63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
const planningApi = require('../../api/planning')
|
|
const mock = require('../../utils/mock')
|
|
const dateUtil = require('../../utils/date')
|
|
|
|
Page({
|
|
data: {
|
|
id: '',
|
|
artists: [],
|
|
selectedArtistId: '',
|
|
date: dateUtil.formatDate(new Date()),
|
|
time: '13:00',
|
|
loading: false
|
|
},
|
|
|
|
onLoad(options) {
|
|
this.setData({
|
|
id: options.id || '',
|
|
artists: mock.artists.map((item, index) => ({
|
|
...item,
|
|
availableStatus: index === 1 ? 'busy' : index === 2 ? 'full' : 'free',
|
|
availableText: index === 1 ? '有冲突' : index === 2 ? '已满' : '可接'
|
|
}))
|
|
})
|
|
},
|
|
|
|
selectArtist(event) {
|
|
this.setData({ selectedArtistId: event.currentTarget.dataset.id })
|
|
},
|
|
|
|
onDateChange(event) {
|
|
this.setData({ date: event.detail.value })
|
|
},
|
|
|
|
onTimeChange(event) {
|
|
this.setData({ time: event.detail.value })
|
|
},
|
|
|
|
async submit() {
|
|
if (!this.data.selectedArtistId) {
|
|
wx.showToast({ title: '请选择美甲师', icon: 'none' })
|
|
return
|
|
}
|
|
this.setData({ loading: true })
|
|
try {
|
|
await planningApi.moveAppointment(this.data.id, {
|
|
artistId: Number(this.data.selectedArtistId),
|
|
appointmentDate: this.data.date,
|
|
appointmentTime: this.data.time
|
|
})
|
|
wx.showToast({ title: '已改派' })
|
|
setTimeout(() => wx.navigateBack(), 500)
|
|
} catch (error) {
|
|
wx.showToast({ title: error.message || '改派失败', icon: 'none' })
|
|
} finally {
|
|
this.setData({ loading: false })
|
|
}
|
|
},
|
|
|
|
back() {
|
|
wx.navigateBack()
|
|
}
|
|
})
|