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: {
|
2026-09-17 01:25:12 +08:00
|
|
|
|
name: '', phone: '', hasCompanion: false, companionName: '', companionUserId: '',
|
|
|
|
|
|
preferredTime: '', summary: '', submitting: false, errorMsg: ''
|
2026-09-09 22:05:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
onNameInput(e: any) { this.setData({ name: e.detail.value }); },
|
|
|
|
|
|
onPhoneInput(e: any) { this.setData({ phone: e.detail.value }); },
|
|
|
|
|
|
onCompanionChange(e: any) { this.setData({ hasCompanion: e.detail.value }); },
|
|
|
|
|
|
onCompanionNameInput(e: any) { this.setData({ companionName: e.detail.value }); },
|
2026-09-17 01:25:12 +08:00
|
|
|
|
onCompanionIdInput(e: any) { this.setData({ companionUserId: e.detail.value }); },
|
2026-09-09 22:05:00 +08:00
|
|
|
|
onTimeInput(e: any) { this.setData({ preferredTime: e.detail.value }); },
|
|
|
|
|
|
onSummaryInput(e: any) { this.setData({ summary: e.detail.value }); },
|
|
|
|
|
|
|
|
|
|
|
|
async onSubmit() {
|
2026-09-17 01:25:12 +08:00
|
|
|
|
const { name, phone, hasCompanion, companionName, companionUserId, preferredTime, summary } = this.data;
|
|
|
|
|
|
if (!name || !phone) {
|
|
|
|
|
|
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' },
|
|
|
|
|
|
data: {
|
|
|
|
|
|
serviceType: 'premarital_guidance',
|
|
|
|
|
|
preferredTime,
|
2026-09-17 01:25:12 +08:00
|
|
|
|
// 字段名与后端 ApplyRequest 对齐(此前用 userRequestSummary 导致后端拿到 null)
|
|
|
|
|
|
summary: summary || `申请人:${name},电话:${phone}${hasCompanion ? `,伴侣:${companionName}` : ''}`,
|
|
|
|
|
|
requestSource: 'user_self',
|
|
|
|
|
|
// INV-005:伴侣须**本人**确认。此处只登记受邀伴侣 ID,确认动作由伴侣本人另行完成。
|
|
|
|
|
|
companionUserId: hasCompanion ? (companionUserId || null) : null,
|
|
|
|
|
|
idempotencyKey: `premarital-${name}-${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: hasCompanion ? '已提交,伴侣需本人确认' : '申请已提交', icon: 'success' });
|
|
|
|
|
|
setTimeout(() => wx.redirectTo({ url: '/pages/my-counseling/my-counseling' }), 1800);
|
|
|
|
|
|
} 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
|
|
|
|
|