2026-09-17 22:21:31 +08:00
|
|
|
/**
|
|
|
|
|
* U52 我的预约
|
|
|
|
|
*
|
|
|
|
|
* Phase 19:此前是硬编码假预约(取消只弹 Modal,不改数据)。
|
|
|
|
|
* 现接入 GET /service-appointments(服务端按登录主体过滤)+ POST /{id}/cancel。
|
|
|
|
|
*/
|
|
|
|
|
const { serviceAppointmentService } = require('../../services');
|
|
|
|
|
|
|
|
|
|
const STATUS_LABEL = {
|
|
|
|
|
submitted: '待确认',
|
|
|
|
|
pending_confirmation: '待确认',
|
|
|
|
|
confirmed: '已确认',
|
|
|
|
|
completed: '已完成',
|
|
|
|
|
cancelled: '已取消',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
data: {
|
|
|
|
|
loading: true,
|
|
|
|
|
error: '',
|
|
|
|
|
appointments: [],
|
|
|
|
|
},
|
|
|
|
|
onShow() {
|
|
|
|
|
this.load();
|
|
|
|
|
},
|
|
|
|
|
async load() {
|
|
|
|
|
this.setData({ loading: true, error: '' });
|
|
|
|
|
try {
|
|
|
|
|
const list = await serviceAppointmentService.getMyAppointments();
|
|
|
|
|
const appointments = (list || []).map((item) => ({
|
|
|
|
|
id: item.id,
|
|
|
|
|
title: item.serviceLocationName || '善缘丹阳公益服务站',
|
|
|
|
|
status: STATUS_LABEL[item.status] || item.status || '',
|
|
|
|
|
date: [item.preferredDate, item.preferredTimeSlot].filter(Boolean).join(' ') || '时间待确认',
|
|
|
|
|
station: item.serviceLocationName || '',
|
|
|
|
|
cancellable: item.status !== 'completed' && item.status !== 'cancelled',
|
|
|
|
|
}));
|
|
|
|
|
this.setData({ appointments, loading: false });
|
|
|
|
|
} catch (error) {
|
|
|
|
|
this.setData({ loading: false, error: '加载失败,请稍后重试' });
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
cancel(event) {
|
|
|
|
|
const id = event.currentTarget.dataset.id;
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '取消预约',
|
|
|
|
|
content: '确定取消本次服务预约吗?',
|
|
|
|
|
confirmText: '确认取消',
|
|
|
|
|
confirmColor: '#D94A4A',
|
|
|
|
|
success: async (res) => {
|
|
|
|
|
if (!res.confirm) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
await serviceAppointmentService.cancelAppointment(id, '用户取消');
|
|
|
|
|
wx.showToast({ title: '已取消', icon: 'success' });
|
|
|
|
|
this.load();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
wx.showToast({ title: '取消失败,请稍后重试', icon: 'none' });
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|