feat: 添加预约核销功能
This commit is contained in:
+36
-28
@@ -42,16 +42,17 @@ Page({
|
||||
'cancelled': '已取消'
|
||||
}
|
||||
|
||||
// checkStatus 为字符串:'0' 未核销,'1' 已核销
|
||||
const checkStatus = String(result.checkStatus)
|
||||
const checkStatusText = checkStatus === '1' ? '已核销' : '未核销'
|
||||
const checkStatusMap = {
|
||||
'1': '已核销',
|
||||
'0': '未核销'
|
||||
}
|
||||
|
||||
this.setData({
|
||||
record: {
|
||||
...formatRecord(result),
|
||||
statusText: statusMap[result.status] || result.status,
|
||||
checkStatus: checkStatus,
|
||||
checkStatusText: checkStatusText
|
||||
checkStatusText: checkStatusMap[result.checkStatus] || '未核销',
|
||||
isChecked: result.checkStatus === '1'
|
||||
},
|
||||
loading: false
|
||||
})
|
||||
@@ -61,30 +62,37 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
async onVerify() {
|
||||
const { record, verifying } = this.data
|
||||
if (verifying || !record || !record.id) return
|
||||
async handleVerify() {
|
||||
const { record } = this.data
|
||||
if (!record || record.isChecked || this.data.verifying) return
|
||||
|
||||
wx.showModal({
|
||||
title: '确认核销',
|
||||
content: '确定要核销该预约记录吗?',
|
||||
confirmColor: '#1890ff',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
|
||||
this.setData({ verifying: true })
|
||||
try {
|
||||
await appointmentDB.notifyHost(record.id)
|
||||
wx.showToast({ title: '核销成功', icon: 'success' })
|
||||
// 刷新详情页
|
||||
this.loadRecordDetail(record.id)
|
||||
} catch (err) {
|
||||
console.error('核销失败', err)
|
||||
wx.showToast({ title: '核销失败,请重试', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ verifying: false })
|
||||
}
|
||||
}
|
||||
const confirmed = await new Promise((resolve) => {
|
||||
wx.showModal({
|
||||
title: '确认核销',
|
||||
content: '确认通知被访人访客已到达并核销此预约记录?',
|
||||
confirmText: '确认核销',
|
||||
confirmColor: '#1890ff',
|
||||
success: (res) => resolve(res.confirm)
|
||||
})
|
||||
})
|
||||
|
||||
if (!confirmed) return
|
||||
|
||||
try {
|
||||
this.setData({ verifying: true })
|
||||
await appointmentDB.notifyHostArrival(record._id)
|
||||
|
||||
this.setData({
|
||||
'record.isChecked': true,
|
||||
'record.checkStatusText': '已核销',
|
||||
verifying: false
|
||||
})
|
||||
|
||||
wx.showToast({ title: '核销成功,已通知被访人', icon: 'success' })
|
||||
} catch (err) {
|
||||
console.error('核销失败', err)
|
||||
this.setData({ verifying: false })
|
||||
wx.showToast({ title: err.message || '核销失败,请稍后重试', icon: 'none' })
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user