2026-09-17 22:21:31 +08:00
|
|
|
/**
|
|
|
|
|
* U51 服务预约
|
|
|
|
|
*
|
|
|
|
|
* Phase 19:此前提交只弹本地 Modal(后端收不到任何记录),属"假成功"。
|
|
|
|
|
* 现接入 POST /service-appointments:来源由服务端强制为 user_self,
|
|
|
|
|
* 前端**不传** requestSource / createdByOperatorId / userId(防伪造运营代登记身份)。
|
|
|
|
|
*
|
|
|
|
|
* 站点上下文:从 U50 服务站页跳转时携带 `?serviceLocationId=`,本页解析后
|
|
|
|
|
* 原样回传,保证预约真正落在该站点;站点名仅作展示,解析失败不阻断提交。
|
|
|
|
|
*/
|
|
|
|
|
const { serviceAppointmentService } = require('../../services');
|
|
|
|
|
|
|
|
|
|
const SERVICE_OPTIONS = [
|
|
|
|
|
{ label: '到站资料协助', type: 'station_visit' },
|
|
|
|
|
{ label: '公益红娘咨询', type: 'matchmaker' },
|
|
|
|
|
{ label: '活动报名指导', type: 'station_visit' },
|
|
|
|
|
{ label: '婚恋咨询预约', type: 'counselor_consultation' },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
data: {
|
|
|
|
|
services: SERVICE_OPTIONS.map((option) => option.label),
|
|
|
|
|
service: '请选择服务项目',
|
|
|
|
|
date: '',
|
|
|
|
|
note: '',
|
|
|
|
|
serviceLocationId: '',
|
|
|
|
|
serviceLocationName: '',
|
|
|
|
|
submitting: false,
|
|
|
|
|
},
|
|
|
|
|
selectedIndex: -1,
|
|
|
|
|
onLoad(options) {
|
|
|
|
|
const raw = options && options.serviceLocationId;
|
|
|
|
|
const serviceLocationId = raw ? decodeURIComponent(raw).trim() : '';
|
|
|
|
|
if (!serviceLocationId) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.setData({ serviceLocationId });
|
|
|
|
|
this.resolveStationName(serviceLocationId);
|
|
|
|
|
},
|
|
|
|
|
async resolveStationName(serviceLocationId) {
|
|
|
|
|
const location = await serviceAppointmentService.getCurrentServiceLocation();
|
|
|
|
|
if (location && location.id === serviceLocationId) {
|
|
|
|
|
this.setData({ serviceLocationName: location.name });
|
|
|
|
|
} else {
|
|
|
|
|
// 站点信息不可得时仍保留归属 ID,仅以占位文案展示,避免误导为空
|
|
|
|
|
this.setData({ serviceLocationName: '已选服务站点' });
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
chooseService(event) {
|
|
|
|
|
const index = Number(event.detail.value);
|
|
|
|
|
this.selectedIndex = index;
|
|
|
|
|
this.setData({ service: SERVICE_OPTIONS[index].label });
|
|
|
|
|
},
|
|
|
|
|
chooseDate(event) {
|
|
|
|
|
this.setData({ date: event.detail.value });
|
|
|
|
|
},
|
|
|
|
|
onNoteInput(event) {
|
|
|
|
|
this.setData({ note: event.detail.value });
|
|
|
|
|
},
|
|
|
|
|
async submit() {
|
|
|
|
|
if (this.selectedIndex < 0) {
|
|
|
|
|
wx.showToast({ title: '请选择服务项目', icon: 'none' });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!this.data.date) {
|
|
|
|
|
wx.showToast({ title: '请选择预约日期', icon: 'none' });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (this.data.submitting) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.setData({ submitting: true });
|
|
|
|
|
try {
|
|
|
|
|
await serviceAppointmentService.createAppointment({
|
|
|
|
|
serviceLocationId: this.data.serviceLocationId || undefined,
|
|
|
|
|
serviceType: SERVICE_OPTIONS[this.selectedIndex].type,
|
|
|
|
|
preferredDate: this.data.date,
|
|
|
|
|
userNote: this.data.note,
|
|
|
|
|
});
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '预约已提交',
|
|
|
|
|
content: '工作人员确认后会通过平台通知你。',
|
|
|
|
|
showCancel: false,
|
|
|
|
|
success: () => wx.navigateTo({ url: '/pages/my-appointments/my-appointments' }),
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
wx.showToast({ title: '提交失败,请稍后重试', icon: 'none' });
|
|
|
|
|
} finally {
|
|
|
|
|
this.setData({ submitting: false });
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|