feat: 添加预约核销功能

This commit is contained in:
ws
2026-04-29 18:24:34 +08:00
parent f1d1c9b460
commit 98f5c7bc49
7 changed files with 125 additions and 77 deletions
+36 -28
View File
@@ -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' })
}
}
})
+12 -7
View File
@@ -66,16 +66,21 @@
</view>
</view>
<!-- 核销状态与操作 -->
<view class="detail-section">
<!-- 核销状态 -->
<view class="check-section">
<view class="detail-row">
<text class="detail-label">核销状态</text>
<text class="detail-value {{record.checkStatus === '1' ? 'text-success' : 'text-warning'}}">{{record.checkStatusText}}</text>
<text class="check-status {{record.isChecked ? 'checked' : 'unchecked'}}">{{record.checkStatusText}}</text>
</view>
<view class="verify-btn-wrap" wx:if="{{record.checkStatus === '0'}}">
<view class="verify-btn {{verifying ? 'verify-btn-disabled' : ''}}" bindtap="onVerify">
{{verifying ? '核销中...' : '确认核销'}}
</view>
<button
wx:if="{{!record.isChecked && record.status === 'approved'}}"
class="verify-btn"
bindtap="handleVerify"
loading="{{verifying}}"
disabled="{{verifying}}"
>核销到访</button>
<view wx:elif="{{record.isChecked}}" class="verified-tip">
<text>该预约记录已核销</text>
</view>
</view>
</view>
+32 -19
View File
@@ -57,7 +57,7 @@
justify-content: space-between;
padding: 30rpx;
border-bottom: 1rpx solid #f0f0f0;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
background: #5b9bd5;
}
.detail-header .title {
@@ -135,34 +135,47 @@
word-break: break-all;
}
/* 核销状态文字 */
.text-warning {
color: #faad14;
font-weight: bold;
/* 核销区块 */
.check-section {
padding: 30rpx;
border-top: 1rpx solid #f0f0f0;
}
.text-success {
.check-status {
font-size: 28rpx;
font-weight: bold;
padding: 6rpx 16rpx;
border-radius: 8rpx;
}
.check-status.checked {
color: #52c41a;
font-weight: bold;
background-color: #f6ffed;
}
/* 核销按钮 */
.verify-btn-wrap {
padding-top: 20rpx;
.check-status.unchecked {
color: #faad14;
background-color: #fffbe6;
}
.verify-btn {
width: 100%;
height: 80rpx;
line-height: 80rpx;
text-align: center;
background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
margin-top: 30rpx;
background: #5b9bd5;
color: #fff;
font-size: 30rpx;
font-weight: bold;
border-radius: 12rpx;
font-size: 30rpx;
height: 88rpx;
line-height: 88rpx;
}
.verify-btn-disabled {
opacity: 0.6;
.verify-btn::after {
border: none;
}
.verified-tip {
margin-top: 24rpx;
text-align: center;
font-size: 24rpx;
color: #999;
padding: 16rpx 0;
}