87 lines
2.0 KiB
JavaScript
87 lines
2.0 KiB
JavaScript
const planningApi = require('../../api/planning')
|
|
const dateUtil = require('../../utils/date')
|
|
const { markPlanningRefresh } = require('../../utils/planning-refresh')
|
|
|
|
Page({
|
|
data: {
|
|
id: '',
|
|
artists: [],
|
|
selectedArtistId: '',
|
|
date: dateUtil.formatDate(new Date()),
|
|
time: '13:00',
|
|
loadError: '',
|
|
loading: false
|
|
},
|
|
|
|
onLoad(options) {
|
|
this.setData({
|
|
id: options.id || ''
|
|
})
|
|
this.loadArtists()
|
|
},
|
|
|
|
async loadArtists() {
|
|
try {
|
|
const calendar = await planningApi.calendar({
|
|
startDate: this.data.date,
|
|
endDate: this.data.date
|
|
})
|
|
const artists = Array.isArray(calendar.artists) ? calendar.artists : []
|
|
this.setData({
|
|
artists: artists.map(item => ({
|
|
...item,
|
|
availableStatus: 'free',
|
|
availableText: '可选择'
|
|
})),
|
|
selectedArtistId: '',
|
|
loadError: ''
|
|
})
|
|
} catch (error) {
|
|
this.setData({
|
|
artists: [],
|
|
selectedArtistId: '',
|
|
loadError: error.message || '美甲师列表加载失败'
|
|
})
|
|
}
|
|
},
|
|
|
|
selectArtist(event) {
|
|
this.setData({ selectedArtistId: event.currentTarget.dataset.id })
|
|
},
|
|
|
|
async onDateChange(event) {
|
|
this.setData({ date: event.detail.value })
|
|
await this.loadArtists()
|
|
},
|
|
|
|
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
|
|
})
|
|
markPlanningRefresh()
|
|
wx.showToast({ title: '已改派' })
|
|
setTimeout(() => wx.navigateBack(), 500)
|
|
} catch (error) {
|
|
wx.showToast({ title: error.message || '改派失败', icon: 'none' })
|
|
} finally {
|
|
this.setData({ loading: false })
|
|
}
|
|
},
|
|
|
|
back() {
|
|
wx.navigateBack()
|
|
}
|
|
})
|