export {} const app = getApp<{ globalData: { apiBase: string; token: string } }>(); Page({ data: { serviceType: '', serviceTypeLabel: '', modes: ['线上视频', '线下面谈', '电话沟通'], pModeIndex: 0, preferredTime: '', summary: '', submitting: false }, onLoad(options: any) { if (options.type) { const typeMap: Record = { relationship_guidance: '恋爱困惑指导', emotional_support: '情感支持', premarital_guidance: '婚前辅导', anti_fraud_guidance: '婚恋反诈指导' }; this.setData({ serviceType: options.type, serviceTypeLabel: typeMap[options.type] || options.type }); } }, onModeChange(e: any) { this.setData({ pModeIndex: e.detail.value }); }, onTimeInput(e: any) { this.setData({ preferredTime: e.detail.value }); }, onSummaryInput(e: any) { this.setData({ summary: e.detail.value }); }, async onSubmit() { const { serviceType, pModeIndex, preferredTime, summary } = this.data; if (!serviceType) return wx.showToast({ title: '请选择服务类型', icon: 'none' }); this.setData({ submitting: true }); try { await wx.request({ url: `${app.globalData.apiBase}/counseling/services`, method: 'POST', header: { 'Authorization': `Bearer ${app.globalData.token}`, 'Content-Type': 'application/json' }, data: { serviceType, preferredServiceMode: this.data.modes[pModeIndex], preferredTime, userRequestSummary: summary } }); wx.showToast({ title: '申请已提交', icon: 'success' }); setTimeout(() => wx.redirectTo({ url: '/pages/my-counseling/my-counseling' }), 1500); } catch (e) { wx.showToast({ title: '提交失败,请重试', icon: 'none' }); } finally { this.setData({ submitting: false }); } } });