feat(escort): 微信支付入口与取消状态展示
- 下单改为提交预约后弹窗选择支付方式,默认微信支付 - 预约详情支持发起微信支付、查单确认与待支付期间切换支付方式 - 预约列表展示支付渠道、待支付/超时状态并提供去支付入口 - 取消状态与 status 解耦,展示状态优先取 cancelStatus - 详情页医院选择回传字段同步移除 manual
This commit is contained in:
+137
-21
@@ -1,7 +1,7 @@
|
||||
const API = require('../../utils/api.js')
|
||||
|
||||
const { parseDate, formatDate, formatDateTime, calcAge } = require('../../utils/date.js')
|
||||
const { STATUS_MAP, PAYMENT_STATUS_MAP } = require('../../utils/order.js')
|
||||
const { STATUS_MAP, PAYMENT_STATUS_MAP, resolveOrderStatus } = require('../../utils/order.js')
|
||||
const { maskIdNumber, maskOrderId } = require('../../utils/privacy.js')
|
||||
|
||||
const SEX_MAP = {
|
||||
@@ -178,18 +178,44 @@ Page({
|
||||
|
||||
formatRecord(item) {
|
||||
const status = item.status
|
||||
const cancelStatus = item.cancelStatus || 'none'
|
||||
// 展示状态:取消状态优先于服务状态(后端 status 不再包含取消值)
|
||||
const displayStatus = resolveOrderStatus(item)
|
||||
const paymentStatus = item.payment?.status || 'unpaid'
|
||||
const statusInfo = STATUS_MAP[status] || STATUS_MAP.pending
|
||||
const statusInfo = STATUS_MAP[displayStatus] || STATUS_MAP.pending
|
||||
const paymentInfo = PAYMENT_STATUS_MAP[paymentStatus] || PAYMENT_STATUS_MAP.unpaid
|
||||
|
||||
// 未支付按渠道与支付窗口区分:线上可去支付、超时仅可改线下或取消、线下等平台收款
|
||||
const payChannel = item.payment?.payChannel || 'offline'
|
||||
const windowEnd = item.paymentWindowEnd ? new Date(item.paymentWindowEnd) : null
|
||||
const paymentExpired = paymentStatus === 'unpaid'
|
||||
&& payChannel === 'online_wechat'
|
||||
&& windowEnd instanceof Date
|
||||
&& !Number.isNaN(windowEnd.getTime())
|
||||
&& Date.now() > windowEnd.getTime()
|
||||
let paymentStatusText = paymentInfo.text
|
||||
if (paymentStatus === 'unpaid') {
|
||||
if (payChannel === 'offline') paymentStatusText = '待收款'
|
||||
else if (paymentExpired) paymentStatusText = '支付已超时'
|
||||
else paymentStatusText = '待支付'
|
||||
} else if (paymentStatus === 'paid' && item.payment?.method === 'online_wechat') {
|
||||
paymentStatusText = '已支付(微信)'
|
||||
}
|
||||
|
||||
// 底栏与「修改」入口的口径在这里算一次,WXML 只读结果,不再重复一串状态判断。
|
||||
// 用户只能取消:未确认且未收款的取消后订单即被删除;已确认/已收款的转为取消申请
|
||||
const canCancel = status === 'pending' || status === 'confirmed'
|
||||
const canRebook = (status === 'completed' || status === 'cancelled') && item.escort?.serviceId > 0
|
||||
const canCancel = cancelStatus === 'none' && (status === 'pending' || status === 'confirmed')
|
||||
const canRebook = (displayStatus === 'completed' || displayStatus === 'cancelled') && item.escort?.serviceId > 0
|
||||
// 终态单据只读:医院预约与陪诊需求不允许回改(就诊人「档案」跳的是档案页,不在此列)
|
||||
// 进行中服务已开始:排期与医院不允许用户单方变更,仅保留就诊人备注(与后端字段白名单一致)
|
||||
const canEditBooking = status === 'pending' || status === 'confirmed'
|
||||
const canEditBooking = cancelStatus === 'none' && (status === 'pending' || status === 'confirmed')
|
||||
const canEditNote = canEditBooking || status === 'in_progress'
|
||||
// 待支付且未超时才能去支付;支付方式仅待支付期间可切换
|
||||
const canPay = paymentStatus === 'unpaid'
|
||||
&& payChannel === 'online_wechat'
|
||||
&& !paymentExpired
|
||||
&& canEditBooking
|
||||
const canSwitchPayChannel = paymentStatus === 'unpaid' && canEditBooking
|
||||
|
||||
// 就诊人字段先落到局部变量:摘要姓名与展开区资料都从同一批值派生,
|
||||
// 口径不在 WXML 与 JS 两处各写一份
|
||||
@@ -242,15 +268,20 @@ Page({
|
||||
paidFee: (item.payment?.paidFee || 0).toFixed(2),
|
||||
showPaidFee: Number(item.payment?.paidFee) > 0,
|
||||
paymentStatus,
|
||||
paymentStatusText: paymentInfo.text,
|
||||
paymentStatusText,
|
||||
paymentStatusColor: paymentInfo.color,
|
||||
paymentStatusBg: paymentInfo.bg,
|
||||
paymentStatusBorder: paymentInfo.border,
|
||||
paymentMethodText: PAYMENT_METHOD_MAP[item.payment?.method] || '',
|
||||
payChannel,
|
||||
payChannelText: payChannel === 'online_wechat' ? '微信支付' : '线下支付',
|
||||
paymentExpired,
|
||||
canPay,
|
||||
canSwitchPayChannel,
|
||||
patientNote: item.notes?.patientNote || '',
|
||||
escortNote: item.notes?.escortNote || '',
|
||||
medicalSummary: item.notes?.medicalSummary || '',
|
||||
status,
|
||||
status: displayStatus,
|
||||
statusText: statusInfo.text,
|
||||
statusColor: statusInfo.color,
|
||||
statusBg: statusInfo.bg,
|
||||
@@ -261,7 +292,7 @@ Page({
|
||||
canEditBooking,
|
||||
canEditNote,
|
||||
// 底栏只在确实有按钮时出现,避免无动作状态空留一条白栏
|
||||
showBottomBar: canCancel || canRebook,
|
||||
showBottomBar: canCancel || canRebook || canPay,
|
||||
createTime: item.meta?.createtime ? formatDateTime(item.meta.createtime) : '',
|
||||
updateTime: item.meta?.updatetime ? formatDateTime(item.meta.updatetime) : ''
|
||||
}
|
||||
@@ -313,6 +344,98 @@ Page({
|
||||
this.setData({ showAllDetails: !this.data.showAllDetails })
|
||||
},
|
||||
|
||||
// ===== 微信支付 =====
|
||||
|
||||
onPayOrder() {
|
||||
if (this.paying) return
|
||||
this.paying = true
|
||||
this.startWechatPay(this.data.recordId)
|
||||
},
|
||||
|
||||
/**
|
||||
* 发起微信支付:payOrder → requestPayment → 查单确认
|
||||
* 前端回调只作提示,最终状态以后端 getPayStatus / 支付回调为准
|
||||
*/
|
||||
async startWechatPay(recordId) {
|
||||
let paid = false
|
||||
try {
|
||||
const res = await API.escort.payOrder(recordId)
|
||||
if (res.code !== 0 || !res.data?.payParams) {
|
||||
wx.showToast({ title: res.msg || '支付发起失败,请稍后重试', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
const payResult = await new Promise((resolve) => {
|
||||
wx.requestPayment({
|
||||
...res.data.payParams,
|
||||
success: () => resolve({ ok: true }),
|
||||
fail: (err) => resolve({ ok: false, err })
|
||||
})
|
||||
})
|
||||
|
||||
if (!payResult.ok && /cancel/i.test(payResult.err?.errMsg || '')) {
|
||||
wx.showToast({ title: '已取消支付', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 支付成功或非取消失败都查单兜底(可能已支付但前端网络中断)
|
||||
const statusRes = await API.escort.getPayStatus(recordId).catch(() => null)
|
||||
paid = statusRes?.code === 0 && statusRes.data?.paymentStatus === 'paid'
|
||||
wx.showToast({
|
||||
title: paid ? '支付成功' : '支付结果确认中',
|
||||
icon: paid ? 'success' : 'none'
|
||||
})
|
||||
} catch (err) {
|
||||
console.log('发起支付失败', err)
|
||||
wx.showToast({ title: '支付发起失败,请稍后重试', icon: 'none' })
|
||||
} finally {
|
||||
this.paying = false
|
||||
setTimeout(() => {
|
||||
if (recordId) this.loadRecord(recordId)
|
||||
}, paid ? 600 : 0)
|
||||
}
|
||||
},
|
||||
|
||||
// ===== 修改支付方式(仅待支付) =====
|
||||
|
||||
onSwitchPayChannel() {
|
||||
if (this.switchingPayChannel) return
|
||||
const current = this.data.record.payChannel
|
||||
wx.showActionSheet({
|
||||
itemList: ['微信支付', '线下支付'],
|
||||
success: (res) => {
|
||||
const channel = res.tapIndex === 0 ? 'online_wechat' : 'offline'
|
||||
if (channel === current) return
|
||||
this.updatePayChannel(channel)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
updatePayChannel(channel) {
|
||||
if (this.switchingPayChannel) return
|
||||
this.switchingPayChannel = true
|
||||
wx.showLoading({ title: '保存中...' })
|
||||
API.escort.updateRecord(this.data.recordId, {
|
||||
'payment.payChannel': channel
|
||||
})
|
||||
.then((res) => {
|
||||
wx.hideLoading()
|
||||
if (res.code === 0) {
|
||||
wx.showToast({ title: '支付方式已更新', icon: 'success' })
|
||||
this.loadRecord(this.data.recordId)
|
||||
} else {
|
||||
wx.showToast({ title: res.msg || '修改失败', icon: 'none' })
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '网络请求失败,请重试', icon: 'none' })
|
||||
})
|
||||
.finally(() => {
|
||||
this.switchingPayChannel = false
|
||||
})
|
||||
},
|
||||
|
||||
// ===== 陪诊需求编辑(底部弹窗) =====
|
||||
|
||||
onEditPatientNote() {
|
||||
@@ -371,9 +494,6 @@ Page({
|
||||
|
||||
const hospitalOptions = getApp().getHospitalsByProvince(province)
|
||||
const name = r.hospitalName || ''
|
||||
const matched = hospitalOptions.find(item => item.name === name)
|
||||
// 历史订单的医院可能已不在库中:自动退回手动输入并保留原值,保证仍能保存
|
||||
const hospitalManual = !hospitalOptions.length || (!!name.trim() && !matched)
|
||||
|
||||
this.setData({
|
||||
showHospitalPopup: true,
|
||||
@@ -388,8 +508,7 @@ Page({
|
||||
medicalRecordNo: r.medicalRecordNo || '',
|
||||
scheduleDate: r.scheduleDate || '',
|
||||
startTime: r.scheduleStartTime || '',
|
||||
sessionIndex,
|
||||
hospitalManual
|
||||
sessionIndex
|
||||
}
|
||||
})
|
||||
},
|
||||
@@ -409,18 +528,14 @@ Page({
|
||||
'editHospital.provinceIndex': index,
|
||||
'editHospital.province': province,
|
||||
'editHospital.name': '',
|
||||
'editHospital.hospitalManual': false,
|
||||
hospitalOptions
|
||||
})
|
||||
},
|
||||
|
||||
// 医院选择组件回传:库内医院同时带出地址,手动输入保持用户填写
|
||||
// 医院选择组件回传:库内医院同时带出地址,手动填写的保持用户填写
|
||||
onHospitalSelectChange(e) {
|
||||
const { name, manual, hospital } = e.detail
|
||||
const patch = {
|
||||
'editHospital.name': name,
|
||||
'editHospital.hospitalManual': manual
|
||||
}
|
||||
const { name, hospital } = e.detail
|
||||
const patch = { 'editHospital.name': name }
|
||||
if (hospital?.address) patch['editHospital.address'] = hospital.address
|
||||
this.setData(patch)
|
||||
},
|
||||
@@ -449,7 +564,8 @@ Page({
|
||||
onSaveHospital() {
|
||||
const form = this.data.editHospital
|
||||
if (!form.name || !form.name.trim()) {
|
||||
wx.showToast({ title: form.hospitalManual ? '请输入就诊医院' : '请选择就诊医院', icon: 'none' })
|
||||
const tip = this.data.hospitalOptions.length ? '请选择就诊医院' : '请填写就诊医院名称'
|
||||
wx.showToast({ title: tip, icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!form.scheduleDate) {
|
||||
|
||||
Reference in New Issue
Block a user