77 lines
2.2 KiB
JavaScript
77 lines
2.2 KiB
JavaScript
const orderApi = require('../../api/order')
|
|
const auth = require('../../utils/auth')
|
|
const navigation = require('../../utils/navigation')
|
|
const theme = require('../../utils/theme')
|
|
const { formatDateTime, formatPrice } = require('../../utils/format')
|
|
const { runWithLoading } = require('../../utils/loading')
|
|
|
|
function safeList(value) {
|
|
return Array.isArray(value) ? value : []
|
|
}
|
|
|
|
function formatClock(value) {
|
|
return value ? String(value).replace('T', ' ').slice(11, 16) : '--'
|
|
}
|
|
|
|
function formatAppointment(item) {
|
|
return {
|
|
...item,
|
|
dayText: String(item.appointmentStartTime || '').slice(5, 10),
|
|
timeText: `${formatClock(item.appointmentStartTime)}-${formatClock(item.appointmentEndTime)}`,
|
|
amountText: `¥${formatPrice(item.actualAmount || item.totalAmount)}`,
|
|
dateTimeText: formatDateTime(item.appointmentStartTime)
|
|
}
|
|
}
|
|
|
|
Page({
|
|
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
|
|
loading: false,
|
|
isLoggedIn: false,
|
|
appointments: []
|
|
}),
|
|
|
|
onShow() {
|
|
this.loadAppointments()
|
|
},
|
|
|
|
handleBack() {
|
|
navigation.goBack('/pages/artist-orders/index')
|
|
},
|
|
|
|
async loadAppointments() {
|
|
const isLoggedIn = auth.isLoggedIn()
|
|
this.setData({ isLoggedIn })
|
|
if (!isLoggedIn) {
|
|
navigation.openAuth(navigation.getCurrentPageUrl())
|
|
return
|
|
}
|
|
this.setData({ loading: true })
|
|
try {
|
|
const list = safeList(await orderApi.getArtistCalendarRecent(7))
|
|
this.setData({
|
|
appointments: list.map(formatAppointment)
|
|
})
|
|
} catch (error) {
|
|
wx.showToast({ title: error.message || '预约日历加载失败', icon: 'none' })
|
|
} finally {
|
|
this.setData({ loading: false })
|
|
}
|
|
},
|
|
|
|
openArtistOrders() {
|
|
navigation.navigate('/pages/artist-orders/index')
|
|
},
|
|
|
|
async completeOrder(event) {
|
|
const orderId = event.currentTarget.dataset.orderId
|
|
if (!orderId) return
|
|
try {
|
|
await runWithLoading(() => orderApi.completeArtistOrder(orderId))
|
|
wx.showToast({ title: '服务已完成', icon: 'none' })
|
|
await this.loadAppointments()
|
|
} catch (error) {
|
|
wx.showToast({ title: error.message || '完成服务失败', icon: 'none' })
|
|
}
|
|
}
|
|
})
|