91 lines
2.3 KiB
JavaScript
91 lines
2.3 KiB
JavaScript
const planningApi = require('../../api/planning')
|
|
const { markPlanningRefresh } = require('../../utils/planning-refresh')
|
|
|
|
Page({
|
|
data: {
|
|
id: '',
|
|
appointment: {},
|
|
avatarText: '',
|
|
timeText: '',
|
|
isUnassigned: false,
|
|
loadError: ''
|
|
},
|
|
|
|
onLoad(options) {
|
|
this.setData({ id: options.id || '' })
|
|
this.loadDetail()
|
|
},
|
|
|
|
async loadDetail() {
|
|
try {
|
|
const appointment = await planningApi.appointment(this.data.id)
|
|
this.applyAppointment(appointment)
|
|
} catch (error) {
|
|
this.setData({
|
|
appointment: {},
|
|
avatarText: '',
|
|
timeText: '',
|
|
loadError: error.message || '预约详情加载失败'
|
|
})
|
|
}
|
|
},
|
|
|
|
applyAppointment(appointment) {
|
|
this.setData({
|
|
appointment,
|
|
isUnassigned: appointment.assignmentStatus === 'UNASSIGNED' || !appointment.artistId,
|
|
avatarText: String(appointment.customerName || '客').slice(0, 1),
|
|
timeText: appointment.historicalBackfill && !appointment.startTime ? '时间未记录' : `${(appointment.startTime || '').slice(0, 16)} - ${(appointment.endTime || '').slice(11, 16)}`,
|
|
loadError: ''
|
|
})
|
|
},
|
|
|
|
async updateStatus(status) {
|
|
if (status !== 3 && this.data.isUnassigned) {
|
|
wx.showToast({ title: '请先分配美甲师', icon: 'none' })
|
|
return
|
|
}
|
|
try {
|
|
await planningApi.updateStatus(this.data.appointment.orderId, status, this._cancelReason || '')
|
|
markPlanningRefresh()
|
|
wx.showToast({ title: '已更新' })
|
|
this.loadDetail()
|
|
} catch (error) {
|
|
wx.showToast({ title: error.message || '操作失败', icon: 'none' })
|
|
}
|
|
},
|
|
|
|
confirm() {
|
|
if (this.data.appointment.historicalBackfill) return
|
|
this.updateStatus(1)
|
|
},
|
|
|
|
complete() {
|
|
this.updateStatus(2)
|
|
},
|
|
|
|
cancel() {
|
|
wx.showModal({
|
|
title: '取消预约',
|
|
editable: true,
|
|
placeholderText: '可填写取消原因',
|
|
content: '',
|
|
confirmText: '确认取消',
|
|
success: result => {
|
|
if (!result.confirm) return
|
|
this._cancelReason = result.content || ''
|
|
this.updateStatus(3)
|
|
}
|
|
})
|
|
},
|
|
|
|
goTransfer() {
|
|
if (this.data.appointment.historicalBackfill) return
|
|
wx.navigateTo({ url: `/pages/artist-transfer/index?id=${this.data.id}` })
|
|
},
|
|
|
|
back() {
|
|
wx.navigateBack()
|
|
}
|
|
})
|