Files
JayuCloud/FingertipManager-Program/pages/appointment-detail/index.js
T

85 lines
2.0 KiB
JavaScript
Raw Normal View History

2026-06-04 16:39:06 +08:00
const planningApi = require('../../api/planning')
2026-06-05 16:10:58 +08:00
const config = require('../../utils/config')
2026-06-04 16:39:06 +08:00
const mock = require('../../utils/mock')
Page({
data: {
id: '',
appointment: {},
avatarText: '',
2026-06-05 16:10:58 +08:00
timeText: '',
loadError: false,
errorMessage: ''
2026-06-04 16:39:06 +08:00
},
2026-06-05 16:10:58 +08:00
onLoad(options = {}) {
2026-06-04 16:39:06 +08:00
this.setData({ id: options.id || '' })
this.loadDetail()
},
async loadDetail() {
2026-06-05 16:10:58 +08:00
this.setData({ loadError: false, errorMessage: '' })
2026-06-04 16:39:06 +08:00
try {
const appointment = await planningApi.appointment(this.data.id)
this.applyAppointment(appointment)
} catch (error) {
2026-06-05 16:10:58 +08:00
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 || '预约详情加载失败,请检查服务连接后重试'
})
}
2026-06-04 16:39:06 +08:00
}
},
applyAppointment(appointment) {
this.setData({
appointment,
avatarText: String(appointment.customerName || '客').slice(0, 1),
2026-06-05 16:10:58 +08:00
timeText: `${(appointment.startTime || '').slice(0, 16)} - ${(appointment.endTime || '').slice(11, 16)}`,
loadError: false,
errorMessage: ''
2026-06-04 16:39:06 +08:00
})
},
async updateStatus(status) {
2026-06-05 16:10:58 +08:00
if (!this.data.appointment.orderId) {
wx.showToast({ title: '预约数据未加载', icon: 'none' })
return
}
2026-06-04 16:39:06 +08:00
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()
}
})