2026-09-10 16:06:11 +08:00
|
|
|
export {}
|
2026-09-17 01:25:12 +08:00
|
|
|
import { request } from '../../utils/requestPromise'
|
2026-09-09 22:05:00 +08:00
|
|
|
const app = getApp<{ globalData: { apiBase: string; token: string } }>();
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
data: {
|
|
|
|
|
serviceType: '',
|
|
|
|
|
serviceTypeLabel: '',
|
2026-09-17 01:25:12 +08:00
|
|
|
modes: ['online', 'offline', 'phone'],
|
|
|
|
|
modeLabels: ['线上视频', '线下面谈', '电话沟通'],
|
2026-09-09 22:05:00 +08:00
|
|
|
pModeIndex: 0,
|
|
|
|
|
preferredTime: '',
|
|
|
|
|
summary: '',
|
2026-09-17 01:25:12 +08:00
|
|
|
submitting: false,
|
|
|
|
|
errorMsg: ''
|
2026-09-09 22:05:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onLoad(options: any) {
|
|
|
|
|
if (options.type) {
|
|
|
|
|
const typeMap: Record<string, string> = {
|
|
|
|
|
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;
|
2026-09-17 01:25:12 +08:00
|
|
|
if (!serviceType) {
|
|
|
|
|
wx.showToast({ title: '请选择服务类型', icon: 'none' });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!summary || !summary.trim()) {
|
|
|
|
|
wx.showToast({ title: '请简要描述您的困扰', icon: 'none' });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.setData({ submitting: true, errorMsg: '' });
|
2026-09-09 22:05:00 +08:00
|
|
|
try {
|
2026-09-17 01:25:12 +08:00
|
|
|
const res = await request<any>({
|
2026-09-09 22:05:00 +08:00
|
|
|
url: `${app.globalData.apiBase}/counseling/services`,
|
|
|
|
|
method: 'POST',
|
|
|
|
|
header: { 'Authorization': `Bearer ${app.globalData.token}`, 'Content-Type': 'application/json' },
|
2026-09-17 01:25:12 +08:00
|
|
|
data: {
|
|
|
|
|
serviceType,
|
|
|
|
|
// 字段名与后端 ApplyRequest 对齐(此前用 preferredServiceMode / userRequestSummary 导致整条链路拿不到值)
|
|
|
|
|
preferredMode: this.data.modes[pModeIndex],
|
|
|
|
|
preferredTime,
|
|
|
|
|
summary,
|
|
|
|
|
requestSource: 'user_self',
|
|
|
|
|
// 幂等键:同一次填写重复提交不会产生两条申请
|
|
|
|
|
idempotencyKey: `counseling-${serviceType}-${Date.now()}`
|
|
|
|
|
}
|
2026-09-09 22:05:00 +08:00
|
|
|
});
|
2026-09-17 01:25:12 +08:00
|
|
|
if (res.statusCode === 200 && res.data && res.data.success) {
|
|
|
|
|
wx.showToast({ title: '申请已提交', icon: 'success' });
|
|
|
|
|
setTimeout(() => wx.redirectTo({ url: '/pages/my-counseling/my-counseling' }), 1500);
|
|
|
|
|
} else {
|
|
|
|
|
this.setData({ errorMsg: (res.data && res.data.message) || '提交失败,请重试' });
|
|
|
|
|
wx.showToast({ title: (res.data && res.data.message) || '提交失败', icon: 'none' });
|
|
|
|
|
}
|
2026-09-09 22:05:00 +08:00
|
|
|
} catch (e) {
|
2026-09-17 01:25:12 +08:00
|
|
|
this.setData({ errorMsg: '网络异常,请稍后重试' });
|
|
|
|
|
wx.showToast({ title: '网络异常,请稍后重试', icon: 'none' });
|
2026-09-09 22:05:00 +08:00
|
|
|
} finally {
|
|
|
|
|
this.setData({ submitting: false });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-09-17 01:25:12 +08:00
|
|
|
|