小程序预约详情支持图片预览、编辑预约与完成收款拆分
自动发布开发环境 Nacos 配置 / publish (push) Successful in 34s
环境分支晋级检查 / environment-promotion-source (pull_request_target) Successful in 11s

This commit is contained in:
2026-11-09 15:18:27 +08:00
parent 6f6625bc0d
commit 69ea01eaa4
18 changed files with 801 additions and 61 deletions
@@ -15,6 +15,17 @@ function formatAmount(value) {
return amount ? `¥${amount}` : '未记录'
}
function isPaid(appointment) {
return String((appointment && appointment.paymentStatus) || '').toUpperCase() === 'PAID'
}
const PAY_METHODS = [
{ label: '现金', value: 'CASH' },
{ label: '微信', value: 'WECHAT' },
{ label: '支付宝', value: 'ALIPAY' },
{ label: '线下其他', value: 'OFFLINE' }
]
Page({
data: {
id: '',
@@ -25,10 +36,13 @@ Page({
timeText: '',
isUnassigned: false,
showTransfer: false,
showEdit: false,
showConfirm: false,
showCollect: false,
showComplete: false,
showCancel: false,
updating: false,
paying: false,
dialing: false,
loadError: ''
},
@@ -38,6 +52,13 @@ Page({
this.loadDetail()
},
onShow() {
if (this._needReload && this.data.id) {
this._needReload = false
this.loadDetail()
}
},
async loadDetail() {
try {
const appointment = await planningApi.appointment(this.data.id)
@@ -75,11 +96,16 @@ Page({
amountText: formatAmount(safeAppointment.amount),
statusText: displayValue(safeAppointment.statusText, '状态未知'),
remarkText: displayValue(safeAppointment.remark, '暂无备注'),
cancelReasonText: displayValue(safeAppointment.cancelReason, '')
cancelReasonText: displayValue(safeAppointment.cancelReason, ''),
paymentStatusText: isPaid(safeAppointment)
? `已收款${safeAppointment.paidAmount !== null && safeAppointment.paidAmount !== undefined ? ` ¥${safeAppointment.paidAmount}` : ''}`
: '未收款'
}
const coverImages = Array.isArray(safeAppointment.coverImages)
? safeAppointment.coverImages.filter(item => Boolean(item))
: []
const paid = isPaid(safeAppointment)
const canOperateService = !isUnassigned && (status === 1 || status === 4)
this.setData({
appointment: normalizedAppointment,
coverImages,
@@ -88,8 +114,10 @@ Page({
avatarText: normalizedAppointment.customerNameText.slice(0, 1),
timeText,
showTransfer: Boolean(safeAppointment.canEdit) && !historicalBackfill,
showEdit: Boolean(safeAppointment.canEdit) && !historicalBackfill && (status === 0 || status === 1),
showConfirm: Boolean(safeAppointment.canEdit) && !historicalBackfill && !isUnassigned && status === 0,
showComplete: !isUnassigned && (status === 1 || status === 4),
showCollect: canOperateService && !paid,
showComplete: canOperateService && paid,
showCancel: Boolean(safeAppointment.canCancel),
loadError: ''
})
@@ -99,6 +127,29 @@ Page({
this.setData({ coverIndex: Number(event.detail.current) || 0 })
},
onCoverImageError(event) {
const index = Number(event.currentTarget.dataset.index)
if (!Number.isFinite(index)) return
if (!this._coverFailedIndexes) this._coverFailedIndexes = {}
this._coverFailedIndexes[index] = true
},
previewCoverImage(event) {
const index = Number(event.currentTarget.dataset.index)
const failed = this._coverFailedIndexes || {}
const images = (this.data.coverImages || []).filter((url, itemIndex) => url && !failed[itemIndex])
if (!images.length) {
wx.showToast({ title: '暂无可预览的图片', icon: 'none' })
return
}
const target = (this.data.coverImages || [])[Number.isFinite(index) ? index : 0]
wx.previewImage({
current: target && images.indexOf(target) >= 0 ? target : images[0],
urls: images,
fail: () => wx.showToast({ title: '图片预览失败', icon: 'none' })
})
},
async updateStatus(status) {
if (this.data.updating || !this.data.appointment.orderId) return
if (status !== 3 && this.data.isUnassigned) {
@@ -125,9 +176,84 @@ Page({
complete() {
if (!this.data.showComplete || this.data.updating) return
if (!isPaid(this.data.appointment)) {
wx.showToast({ title: '请先完成收款', icon: 'none' })
return
}
this.updateStatus(2)
},
choosePayMethod() {
return new Promise(resolve => {
wx.showActionSheet({
itemList: PAY_METHODS.map(item => item.label),
success: result => resolve(PAY_METHODS[result.tapIndex] || PAY_METHODS[0]),
fail: () => resolve(null)
})
})
},
async collect() {
if (!this.data.showCollect || this.data.paying || this.data.updating) return
const appointment = this.data.appointment || {}
const orderId = appointment.orderId
if (!orderId) return
const method = await this.choosePayMethod()
if (!method) return
const defaultAmount = appointment.payAmount !== null && appointment.payAmount !== undefined
? appointment.payAmount
: appointment.amount
const input = await showActionModal(this, {
title: '登记收款',
content: `收款方式:${method.label}`,
editable: true,
inputType: 'digit',
inputValue: defaultAmount === null || defaultAmount === undefined ? '' : defaultAmount,
placeholderText: '请输入实收金额',
cancelText: '取消',
confirmText: '确认收款'
})
if (!input.confirm) return
const text = String(input.content || '').trim()
const paidAmount = Number(text)
if (!text || !Number.isFinite(paidAmount) || paidAmount < 0) {
wx.showToast({ title: '请输入正确的收款金额', icon: 'none' })
return
}
this.setData({ paying: true })
try {
await planningApi.registerOfflinePayment(orderId, {
payMethod: method.value,
paidAmount
})
markPlanningRefresh()
const result = await showActionModal(this, {
title: '收款已登记',
content: `实收 ¥${paidAmount},是否同时完成服务?`,
cancelText: '暂不完成',
confirmText: '同时完成服务'
})
if (result.confirm) {
await planningApi.updateStatus(orderId, 2, '')
markPlanningRefresh()
wx.showToast({ title: '已完成服务' })
} else {
wx.showToast({ title: '收款已登记', icon: 'success' })
}
this.loadDetail()
} catch (error) {
showErrorToast(error, '收款登记失败')
} finally {
this.setData({ paying: false })
}
},
goEdit() {
if (!this.data.showEdit) return
this._needReload = true
wx.navigateTo({ url: `/pages/appointment-form/index?mode=edit&id=${this.data.appointment.orderItemId || this.data.id}` })
},
async cancel() {
if (!this.data.showCancel || this.data.updating) return
this._cancelReason = ''
@@ -82,20 +82,58 @@ page.applyAppointment({
assignmentStatus: 'ASSIGNED',
status: 4,
statusText: '服务中',
historicalBackfill: true,
paymentStatus: 'UNPAID',
payAmount: 268,
canEdit: false,
canCancel: true
})
assert.strictEqual(page.data.showTransfer, false)
assert.strictEqual(page.data.showComplete, true)
assert.strictEqual(page.data.showCollect, true)
assert.strictEqual(page.data.showComplete, false)
assert.strictEqual(page.data.showCancel, true)
assert.strictEqual(page.data.appointment.paymentStatusText, '未收款')
page.applyAppointment({
artistId: 9,
assignmentStatus: 'ASSIGNED',
status: 1,
statusText: '待服务',
paymentStatus: 'PAID',
paidAmount: 268,
canEdit: true,
canCancel: true
})
assert.strictEqual(page.data.showCollect, false)
assert.strictEqual(page.data.showComplete, true)
assert.strictEqual(page.data.showEdit, true)
assert.strictEqual(page.data.appointment.paymentStatusText, '已收款 ¥268')
global.wx.previewImage = options => {
global.__preview = options
}
page.data.coverImages = ['https://cdn/a.png', 'https://cdn/b.png', 'https://cdn/c.png']
page._coverFailedIndexes = { 1: true }
page.previewCoverImage({ currentTarget: { dataset: { index: 2 } } })
assert.deepStrictEqual(global.__preview.urls, ['https://cdn/a.png', 'https://cdn/c.png'])
assert.strictEqual(global.__preview.current, 'https://cdn/c.png')
page.data.coverImages = ['', '']
let toastTitle = ''
global.wx.showToast = options => { toastTitle = options.title }
page.previewCoverImage({ currentTarget: { dataset: { index: 0 } } })
assert.strictEqual(toastTitle, '暂无可预览的图片')
const markup = fs.readFileSync(path.join(__dirname, 'index.wxml'), 'utf8')
const styles = fs.readFileSync(path.join(__dirname, 'index.wxss'), 'utf8')
;['订单编号', '服务项目', '美甲师', '时长', '成交金额', '取消原因', 'remarkText', 'customerPhoneText'].forEach(text => assert(markup.includes(text)))
assert.match(markup, /class="primary-btn transfer-action"/)
assert.match(markup, /class="danger-btn"/)
assert.match(markup, /bindtap="previewCoverImage"/)
assert.match(markup, /class="cover-thumb/)
assert.match(markup, /bindtap="collect">完成收款/)
assert.match(markup, /bindtap="goEdit"/)
assert.match(markup, /appointment\.customerPhoneAvailable && appointment\.orderId/)
assert.strictEqual(markup.includes('appointment.customerId && appointment.orderId'), false)
assert.match(styles, /\.transfer-action\s*\{[^}]*box-shadow/)
assert.match(styles, /\.call-btn\s*\{/)
assert.match(styles, /\.cover-thumb\s*\{/)
@@ -22,7 +22,10 @@
</view>
</view>
</view>
<text class="status-tag {{appointment.status === 2 ? 'completed' : appointment.status === 3 ? 'cancelled' : ''}}">{{appointment.historicalBackfill ? '历史补单 · ' : ''}}{{appointment.statusText}}</text>
<view class="head-actions">
<button wx:if="{{showEdit}}" class="edit-btn" size="mini" bindtap="goEdit">编辑</button>
<text class="status-tag {{appointment.status === 2 ? 'completed' : appointment.status === 3 ? 'cancelled' : ''}}">{{appointment.historicalBackfill ? '历史补单 · ' : ''}}{{appointment.statusText}}</text>
</view>
</view>
<view class="detail-grid">
<view class="detail-field">
@@ -49,6 +52,10 @@
<text class="label">成交金额</text>
<text class="value">{{appointment.amountText}}</text>
</view>
<view class="detail-field">
<text class="label">收款状态</text>
<text class="value">{{appointment.paymentStatusText}}</text>
</view>
</view>
<view wx:if="{{appointment.cancelReasonText}}" class="cancel-reason">
<text class="label">取消原因</text>
@@ -64,14 +71,35 @@
<view class="cover-card">
<swiper class="cover-swiper" circular="{{coverImages.length > 1}}" bindchange="onCoverChange">
<swiper-item wx:for="{{coverImages}}" wx:key="*this">
<image class="cover-image" src="{{item}}" mode="aspectFill" />
<image
class="cover-image"
src="{{item}}"
mode="aspectFill"
data-index="{{index}}"
bindtap="previewCoverImage"
binderror="onCoverImageError"
/>
</swiper-item>
</swiper>
<view class="cover-dots">
<view wx:for="{{coverImages}}" wx:key="*this" class="cover-dot {{index === coverIndex ? 'active' : ''}}"></view>
</view>
</view>
<text class="cover-hint">左滑查看更多项目图</text>
<scroll-view class="cover-thumbs" scroll-x>
<view class="cover-thumb-list">
<image
wx:for="{{coverImages}}"
wx:key="*this"
class="cover-thumb {{index === coverIndex ? 'active' : ''}}"
src="{{item}}"
mode="aspectFill"
data-index="{{index}}"
bindtap="previewCoverImage"
binderror="onCoverImageError"
/>
</view>
</scroll-view>
<text class="cover-hint">点击图片可放大查看</text>
</view>
<view wx:if="{{!loadError}}" class="section">
@@ -79,10 +107,11 @@
<view class="card note-card">{{appointment.remarkText}}</view>
</view>
<view wx:if="{{!loadError && (showTransfer || showConfirm || showComplete || showCancel)}}" class="fixed-bottom action-row">
<view wx:if="{{!loadError && (showTransfer || showConfirm || showCollect || showComplete || showCancel)}}" class="fixed-bottom action-row">
<button wx:if="{{showTransfer}}" class="primary-btn transfer-action" loading="{{updating}}" disabled="{{updating}}" bindtap="goTransfer">{{isUnassigned ? '分配美甲师' : '改派美甲师'}}</button>
<button wx:if="{{showConfirm}}" class="secondary-btn" loading="{{updating}}" disabled="{{updating}}" bindtap="confirm">确认预约</button>
<button wx:if="{{showComplete}}" class="secondary-btn" loading="{{updating}}" disabled="{{updating}}" bindtap="complete">{{appointment.historicalBackfill ? '完成补单' : '完成服务'}}</button>
<button wx:if="{{showCollect}}" class="secondary-btn" loading="{{paying}}" disabled="{{paying || updating}}" bindtap="collect">完成收款</button>
<button wx:if="{{showComplete}}" class="secondary-btn" loading="{{updating}}" disabled="{{updating || paying}}" bindtap="complete">{{appointment.historicalBackfill ? '完成补单' : '完成服务'}}</button>
<button wx:if="{{showCancel}}" class="danger-btn" loading="{{updating}}" disabled="{{updating}}" bindtap="cancel">取消预约</button>
</view>
<action-modal id="actionModal" />
@@ -96,6 +96,25 @@
font-weight: 800;
}
.head-actions {
display: flex;
align-items: center;
flex-shrink: 0;
gap: 10rpx;
}
.edit-btn {
margin: 0;
padding: 0 16rpx;
border: 1rpx solid #247b63;
border-radius: 20rpx;
background: #ffffff;
color: #247b63;
font-size: 21rpx;
font-weight: 600;
line-height: 40rpx;
}
.status-tag.completed {
background: #eef2f1;
color: #67766f;
@@ -233,6 +252,31 @@
font-size: 20rpx;
}
.cover-thumbs {
margin-top: 12rpx;
width: 100%;
white-space: nowrap;
}
.cover-thumb-list {
display: flex;
align-items: center;
gap: 12rpx;
}
.cover-thumb {
flex-shrink: 0;
width: 104rpx;
height: 104rpx;
border: 2rpx solid transparent;
border-radius: 12rpx;
background: #e5f4ed;
}
.cover-thumb.active {
border-color: #247b63;
}
.note-card {
padding: 24rpx;
color: #71807a;