const planningApi = require('../../api/planning') const config = require('../../utils/config') const mock = require('../../utils/mock') Page({ data: { id: '', appointment: {}, avatarText: '', timeText: '', loadError: false, errorMessage: '' }, onLoad(options = {}) { this.setData({ id: options.id || '' }) this.loadDetail() }, async loadDetail() { this.setData({ loadError: false, errorMessage: '' }) try { const appointment = await planningApi.appointment(this.data.id) this.applyAppointment(appointment) } catch (error) { if (config.USE_DEV_MOCK_DATA) { const demo = mock.buildCalendar(new Date()).appointments[0] this.applyAppointment(demo) } else { this.setData({ appointment: {}, avatarText: '', timeText: '', loadError: true, errorMessage: error.message || '预约详情加载失败,请检查服务连接后重试' }) } } }, applyAppointment(appointment) { this.setData({ appointment, avatarText: String(appointment.customerName || '客').slice(0, 1), timeText: `${(appointment.startTime || '').slice(0, 16)} - ${(appointment.endTime || '').slice(11, 16)}`, loadError: false, errorMessage: '' }) }, async updateStatus(status) { if (!this.data.appointment.orderId) { wx.showToast({ title: '预约数据未加载', icon: 'none' }) return } try { await planningApi.updateStatus(this.data.appointment.orderId, status) wx.showToast({ title: '已更新' }) this.loadDetail() } catch (error) { wx.showToast({ title: error.message || '操作失败', icon: 'none' }) } }, confirm() { this.updateStatus(1) }, complete() { this.updateStatus(2) }, cancel() { this.updateStatus(3) }, goTransfer() { wx.navigateTo({ url: `/pages/artist-transfer/index?id=${this.data.id}` }) }, back() { wx.navigateBack() } })