From 8eb7bc9e7acd5022cf4ff92f30923f959d0f97be Mon Sep 17 00:00:00 2001 From: lik Date: Thu, 5 Nov 2026 18:55:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(escort):=20=E5=BE=AE=E4=BF=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=85=A5=E5=8F=A3=E4=B8=8E=E5=8F=96=E6=B6=88=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 下单改为提交预约后弹窗选择支付方式,默认微信支付 - 预约详情支持发起微信支付、查单确认与待支付期间切换支付方式 - 预约列表展示支付渠道、待支付/超时状态并提供去支付入口 - 取消状态与 status 解耦,展示状态优先取 cancelStatus - 详情页医院选择回传字段同步移除 manual --- pages/escort/itemorder.js | 163 ++++++++++++++++++++++------- pages/escort/itemorder.wxml | 51 ++++++++- pages/escort/itemorder.wxss | 183 +++++++++++++++++++++++++++++++-- pages/escort/recorddetail.js | 158 ++++++++++++++++++++++++---- pages/escort/recorddetail.wxml | 20 +++- pages/escort/recorddetail.wxss | 57 +++++++--- pages/escort/recordlist.js | 45 +++++++- pages/escort/recordlist.wxml | 6 ++ pages/escort/recordlist.wxss | 16 +++ utils/api.js | 3 + utils/order.js | 15 ++- 11 files changed, 627 insertions(+), 90 deletions(-) diff --git a/pages/escort/itemorder.js b/pages/escort/itemorder.js index 7ba8b38..4a5f896 100644 --- a/pages/escort/itemorder.js +++ b/pages/escort/itemorder.js @@ -22,7 +22,7 @@ Page({ provinces: [], hospital: '', hospitalOptions: [], - hospitalManual: false, + hospitalCustom: false, appointmentDate: '', appointmentTime: '', minAppointmentDate: '', @@ -34,6 +34,9 @@ Page({ remark: '', shippingAddress: '', requiresAddress: false, + payChannel: 'online_wechat', + // 点击「提交预约」后弹出支付方式选择,默认微信支付 + showPayPopup: false, gender: '不限', genderIndex: 0, genderOptions: ['不限', '男', '女'] @@ -72,12 +75,9 @@ Page({ const app = getApp() // 启动时 app 已在预取,这里只等它落定后用最新列表刷新下拉; - // 没有可用医院时退回手动输入,避免下拉是空的还阻断下单 + // 列表为空时组件内的「其他医院」入口仍可手填,不会阻断下单 app.loadHospitals().then(() => { this.refreshHospitalOptions() - if (!this.data.hospitalOptions.length && !this.data.hospitalManual) { - this.setData({ hospitalManual: true }) - } }) await app.waitForAuth() if (app.globalData.user?._id) this.loadProfiles() @@ -122,7 +122,7 @@ Page({ province: provinces[0] || '', provinceIndex: 0, hospital: '', - hospitalManual: false, + hospitalCustom: false, appointmentDate: '', appointmentTime: '', shippingAddress: '', @@ -209,7 +209,7 @@ Page({ provinceIndex: index, province, hospital: '', - hospitalManual: false + hospitalCustom: false }, () => this.refreshHospitalOptions(province)) }, @@ -218,7 +218,8 @@ Page({ const hospitalOptions = getApp().getHospitalsByProvince(province) let hospital = '' - if (this.data.hospitalManual) { + if (this.data.hospitalCustom) { + // 「其他医院」手填的名称不在库内,刷新列表时原样保留 hospital = this.data.hospital } else { const selected = hospitalOptions.find((item) => item._id === this.selectedHospitalId) @@ -233,11 +234,11 @@ Page({ this.setData({ hospitalOptions, hospital }) }, - // 医院选择组件回传:name 为最终值,manual 表示是否手动输入,hospital 为库内记录 + // 医院选择组件回传:name 为最终值,manual 表示是否为「其他医院」手填,hospital 为库内记录 onHospitalChange(e) { const { name, manual, hospital } = e.detail this.selectedHospitalId = hospital?._id || '' - this.setData({ hospital: name, hospitalManual: manual }) + this.setData({ hospital: name, hospitalCustom: manual }) }, onDateChange(e) { @@ -263,6 +264,13 @@ Page({ this.setData({ remark: e.detail.value }) }, + onPayChannelChange(e) { + const channel = e.currentTarget.dataset.channel + if (!['online_wechat', 'offline'].includes(channel)) return + if (this.data.submitting) return + this.setData({ payChannel: channel }) + }, + onShippingAddressChange(e) { this.setData({ shippingAddress: e.detail.value }) }, @@ -270,7 +278,9 @@ Page({ validateOrder() { const data = this.data if (!data.selectedProfileId || !data.selectedPatient) return '请选择就诊人' - if (!data.hospital.trim()) return data.hospitalManual ? '请输入就诊医院' : '请选择就诊医院' + if (!data.hospital.trim()) { + return data.hospitalOptions.length ? '请选择就诊医院' : '请填写就诊医院名称' + } if (!data.appointmentDate) return '请选择预约日期' if (!data.appointmentTime) return '请选择预约时间' if (data.requiresAddress && !data.shippingAddress.trim()) return '请填写完整收货地址' @@ -282,7 +292,26 @@ Page({ async submitOrder() { if (this.data.submitting) return - this.setData({ submitting: true }) + // 先做一次表单校验,避免用户选完支付方式才发现信息没填全 + const error = this.validateOrder() + if (error) { + wx.showToast({ title: error, icon: 'none' }) + return + } + this.setData({ showPayPopup: true, payChannel: 'online_wechat' }) + }, + + onClosePayPopup() { + if (this.data.submitting) return + this.setData({ showPayPopup: false }) + }, + + /** + * 确认支付方式后真正提交订单 + */ + async onConfirmPay() { + if (this.data.submitting) return + this.setData({ submitting: true, showPayPopup: false }) try { const loggedIn = await this.ensureLogin() if (loggedIn === null) return @@ -298,33 +327,24 @@ Page({ return } - const data = this.data - const sexMap = { 男: 'male', 女: 'female' } - const orderData = { - idempotencyKey: this.idempotencyKey, - healthProfileId: data.selectedProfileId, - escort: { - serviceId: data.service.id, - sexRequirement: sexMap[data.gender] || 'none' - }, - hospital: { - province: data.province, - name: data.hospital.trim() - }, - schedule: { - date: data.appointmentDate, - startTime: data.appointmentTime - }, - shippingAddress: { address: data.shippingAddress.trim() }, - notes: { patientNote: data.remark.trim() } - } + const payChannel = this.data.payChannel + const orderData = this.buildOrderData() // 网络重试沿用同一幂等键,服务端只创建一笔订单。 const res = await API.escort.createRecord(orderData) if (res.code !== 0) throw new Error(res.msg || '下单失败') - wx.showToast({ title: '下单成功', icon: 'success' }) + const record = res.data?.record this.resetForm() - wx.navigateTo({ url: '/pages/escort/recordlist?tab=ongoing' }) + + if (payChannel === 'offline') { + wx.showToast({ title: '线下支付,请联系平台收款', icon: 'none' }) + wx.navigateTo({ url: '/pages/escort/recordlist?tab=ongoing' }) + return + } + + // 选微信支付:下单成功后立即拉起收银台,支付结果以后端查单为准 + if (record?._id) await this.startWechatPay(record._id) + else wx.navigateTo({ url: '/pages/escort/recordlist?tab=ongoing' }) } catch (err) { console.log('下单失败', err) wx.showToast({ title: err.message || '网络请求失败,请重试', icon: 'none' }) @@ -333,6 +353,79 @@ Page({ } }, + buildOrderData() { + const data = this.data + const sexMap = { 男: 'male', 女: 'female' } + return { + idempotencyKey: this.idempotencyKey, + healthProfileId: data.selectedProfileId, + escort: { + serviceId: data.service.id, + sexRequirement: sexMap[data.gender] || 'none' + }, + hospital: { + province: data.province, + name: data.hospital.trim() + }, + schedule: { + date: data.appointmentDate, + startTime: data.appointmentTime + }, + shippingAddress: { address: data.shippingAddress.trim() }, + notes: { patientNote: data.remark.trim() }, + payment: { payChannel: data.payChannel } + } + }, + + /** + * 发起微信支付:payOrder → requestPayment → 查单确认 + * 支付按钮防抖(this.paying),前端回调只作提示,最终状态以 getPayStatus 为准 + */ + async startWechatPay(recordId) { + if (this.paying) return + this.paying = true + 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) { + const errMsg = payResult.err?.errMsg || '' + if (/cancel/i.test(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(() => { + wx.navigateTo({ url: `/pages/escort/recorddetail?id=${recordId}` }) + }, paid ? 600 : 0) + } + }, + resetForm() { const provinces = this.data.provinces this.selectedHospitalId = '' @@ -344,7 +437,7 @@ Page({ province: provinces[0] || '', provinceIndex: 0, hospital: '', - hospitalManual: false, + hospitalCustom: false, appointmentDate: '', appointmentTime: '', sessionIndex: 0, diff --git a/pages/escort/itemorder.wxml b/pages/escort/itemorder.wxml index b24901d..8f114ef 100644 --- a/pages/escort/itemorder.wxml +++ b/pages/escort/itemorder.wxml @@ -36,10 +36,10 @@ {{item.name}} - {{item.mobile}} - - + 添加就诊人 + + + 增加 @@ -70,7 +70,6 @@ {{pageError}} + + + + + + 选择支付方式 + + + + + + + + + 微信支付 + 提交后立即拉起收银台 + + + + + + 线下支付 + 平台收款后确认订单 + + + + + 微信支付可立即完成付款;线下支付由平台收款后再确认订单。 + + + 取消 + + {{submitting ? '提交中...' : '确认提交'}} + + + \ No newline at end of file diff --git a/pages/escort/itemorder.wxss b/pages/escort/itemorder.wxss index 327f100..e4a8cf6 100644 --- a/pages/escort/itemorder.wxss +++ b/pages/escort/itemorder.wxss @@ -212,8 +212,11 @@ page { .patient-chip { display: inline-flex; flex-direction: column; + align-items: center; + justify-content: center; box-sizing: border-box; - min-width: 180rpx; + /* 140rpx:只显示姓名,胶囊按名字长度收紧,不再为手机号预留宽度 */ + min-width: 140rpx; padding: 16rpx 24rpx; border: 2rpx solid var(--line); border-radius: 16rpx; @@ -242,14 +245,15 @@ page { color: var(--brand-ink); } -.patient-chip-phone { - margin-top: 6rpx; - color: var(--ink-2); - font-size: var(--fs-28); -} - .patient-chip-add { + flex-direction: row; + align-items: center; justify-content: center; + gap: 4rpx; + /* 虚线描边 + 白底:与「已选就诊人」的实心浅橙底区分开, + 一眼看出这是动作入口而不是某个就诊人 */ + background: var(--white); + border: 2rpx dashed var(--brand-line); } .add-profile-tip { @@ -375,6 +379,171 @@ page { line-height: 1.5; } +/* 支付方式:两张可选卡片,选中态沿用品牌橙 */ +.pay-channel-options { + display: flex; + flex-direction: column; + gap: 16rpx; + margin-top: 16rpx; +} + +.pay-channel-option { + display: flex; + align-items: center; + justify-content: space-between; + padding: 20rpx 24rpx; + border: 2rpx solid var(--line); + border-radius: 18rpx; + background: var(--paper); +} + +.pay-channel-option.active { + border-color: var(--brand-line); + background: var(--brand-soft); +} + +.pay-channel-text { + display: flex; + flex-direction: column; + gap: 6rpx; +} + +.pay-channel-title { + color: var(--ink); + font-size: var(--fs-30); + font-weight: 600; +} + +.pay-channel-desc { + color: var(--muted); + font-size: var(--fs-24); +} + +.pay-channel-radio { + flex-shrink: 0; + width: 32rpx; + height: 32rpx; + border: 2rpx solid var(--line); + border-radius: 50%; + background: var(--white); +} + +.pay-channel-radio.checked { + border-color: var(--brand-strong); + background: var(--brand-strong); +} + +.pay-popup-tip { + display: block; + margin-top: 20rpx; + color: var(--muted); + font-size: var(--fs-24); + line-height: 1.6; +} + +/* ===== 支付方式底部弹窗 ===== */ +.popup-mask { + position: fixed; + left: 0; + right: 0; + top: 0; + bottom: 0; + z-index: 200; + background: rgba(43, 37, 33, 0.45); + opacity: 0; + visibility: hidden; + transition: opacity 0.3s ease, visibility 0.3s ease; +} + +.popup-mask.show { + opacity: 1; + visibility: visible; +} + +.popup-content { + position: fixed; + left: 0; + right: 0; + bottom: 0; + z-index: 201; + display: flex; + flex-direction: column; + max-height: 70vh; + background: var(--white); + border-radius: 32rpx 32rpx 0 0; + transform: translateY(100%); + transition: transform 0.3s ease-out; +} + +.popup-content.show { + transform: translateY(0); +} + +.popup-header { + display: flex; + align-items: center; + justify-content: space-between; + flex-shrink: 0; + padding: 28rpx 32rpx; + border-bottom: 2rpx solid var(--line); +} + +.popup-title { + color: var(--ink); + font-size: var(--fs-32); + font-weight: 700; +} + +.popup-close { + padding: 8rpx; + margin: -8rpx; +} + +.popup-close:active { + opacity: 0.5; +} + +.popup-body { + flex: 1; + overflow-y: auto; + padding: 20rpx 32rpx 28rpx; +} + +.popup-footer { + display: flex; + gap: 16rpx; + flex-shrink: 0; + padding: 20rpx 32rpx; + padding-bottom: calc(20rpx + env(safe-area-inset-bottom)); + border-top: 2rpx solid var(--line); +} + +.popup-btn { + flex: 1; + display: flex; + align-items: center; + justify-content: center; + padding: 22rpx 0; + border-radius: 999rpx; + font-size: var(--fs-30); + line-height: 1.4; +} + +.popup-btn:active { + opacity: 0.7; +} + +.popup-btn-ghost { + border: 3rpx solid var(--sep); + color: var(--muted); +} + +.popup-btn-primary { + background: var(--brand-strong); + color: var(--white); + font-weight: 700; +} + @media (prefers-reduced-motion: reduce) { .patient-chip, .add-profile-tip, diff --git a/pages/escort/recorddetail.js b/pages/escort/recorddetail.js index 6f86f59..c57beb7 100644 --- a/pages/escort/recorddetail.js +++ b/pages/escort/recorddetail.js @@ -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) { diff --git a/pages/escort/recorddetail.wxml b/pages/escort/recorddetail.wxml index 7662d72..1275272 100644 --- a/pages/escort/recorddetail.wxml +++ b/pages/escort/recorddetail.wxml @@ -119,6 +119,20 @@ 不再在卡内挂一行「请联系客服…」:那句话只对未支付状态成立, 却长期占着卡内一条常驻行位 --> + + + 支付方式 + {{record.payChannelText}} + 切换 + + + 取消原因 {{record.cancelReason}} @@ -248,6 +262,11 @@ > + 去支付 windowEnd.getTime() + let paymentStatusText = paymentStatusInfo.text + if (paymentStatus === 'unpaid') { + if (payChannel === 'offline') paymentStatusText = '线下支付' + else if (paymentExpired) paymentStatusText = '支付已超时' + else paymentStatusText = '待支付' + } + const canPay = paymentStatus === 'unpaid' + && payChannel === 'online_wechat' + && !paymentExpired + && ['pending', 'confirmed'].includes(displayStatus) + return { _id: item._id, patientName: item.patient?.name || '--', @@ -120,7 +146,11 @@ Page({ statusBorder: statusInfo.border, appointmentTime, fee: fee.toFixed(2), - paymentStatusText: paymentStatusInfo.text, + payChannel, + payChannelText: payChannel === 'online_wechat' ? '微信支付' : '线下支付', + paymentExpired, + canPay, + paymentStatusText, paymentStatusColor: paymentStatusInfo.color, paymentStatusBg: paymentStatusInfo.bg, paymentStatusBorder: paymentStatusInfo.border @@ -190,6 +220,13 @@ Page({ wx.navigateTo({ url: `/pages/escort/recorddetail?id=${id}` }) }, + // 列表「去支付」只作为入口:真正发起支付在详情页,避免列表与详情两套支付逻辑 + onPayRecord(e) { + const id = e.currentTarget.dataset.id + if (!id) return + wx.navigateTo({ url: `/pages/escort/recorddetail?id=${id}` }) + }, + // 回首页:首页是 tabBar 页,必须走 switchTab,navigateTo 跳不过去 onGoHome() { wx.switchTab({ url: '/pages/home/index' }) diff --git a/pages/escort/recordlist.wxml b/pages/escort/recordlist.wxml index 4bcd226..d8ab3dc 100644 --- a/pages/escort/recordlist.wxml +++ b/pages/escort/recordlist.wxml @@ -83,6 +83,12 @@ class="pay-chip" style="background: {{item.paymentStatusBg}}; color: {{item.paymentStatusColor}}; border-color: {{item.paymentStatusBorder}};" >{{item.paymentStatusText}} + 去支付 diff --git a/pages/escort/recordlist.wxss b/pages/escort/recordlist.wxss index 7f23a6f..6fccc67 100644 --- a/pages/escort/recordlist.wxss +++ b/pages/escort/recordlist.wxss @@ -322,6 +322,22 @@ page { box-shadow: var(--shadow-card); } +/* 列表「去支付」:只在待支付且未超时时出现,点击进入详情完成支付 */ +.pay-entry { + margin-right: 12rpx; + padding: 8rpx 22rpx; + border-radius: 999rpx; + background: var(--brand-soft); + color: var(--brand-strong); + font-size: var(--fs-24); + font-weight: 600; + line-height: 1.4; +} + +.pay-entry:active { + opacity: 0.7; +} + .home-fab:active { opacity: 0.7; } diff --git a/utils/api.js b/utils/api.js index 8569acf..5fc9a19 100644 --- a/utils/api.js +++ b/utils/api.js @@ -25,6 +25,9 @@ const API = { updateRecord: (id, data) => request.put(`/health/escort-record/${id}`, data), updateStatus: (id, data) => request.patch(`/health/escort-record/${id}/status`, data), deleteRecord: (id) => request.delete(`/health/escort-record/${id}`), + // 微信支付:发起支付返回调起收银台参数;支付结果以后端查单为准 + payOrder: (id) => request.post(`/health/escort-record/${id}/pay`), + getPayStatus: (id) => request.get(`/health/escort-record/${id}/pay/status`), // 陪诊师公示列表(公开接口,后端已做脱敏) getAttendants: (params) => request.get('/health/attendant', params), // 单个陪诊师详情,同一份白名单数据 diff --git a/utils/order.js b/utils/order.js index 1e7e91f..b3f0327 100644 --- a/utils/order.js +++ b/utils/order.js @@ -8,8 +8,18 @@ const STATUS_MAP = { cancelled: { text: '已取消', color: '#B4231A', bg: '#FCF0EE', border: '#F2D6D1', desc: '该订单已取消' } } +// 取消与 status 解耦:展示层优先按 cancelStatus 映射为「待取消/已取消」, +// 其余情况仍按服务状态展示,status 本身不再写入取消值。 +function resolveOrderStatus(item) { + const cancelStatus = item?.cancelStatus || 'none' + if (cancelStatus === 'cancelled') return 'cancelled' + if (cancelStatus === 'requested') return 'cancel_requested' + return item?.status || 'pending' +} + const PAYMENT_STATUS_MAP = { - unpaid: { text: '未支付', color: '#B8520A', bg: '#FFF4E8', border: '#FFE0C2', hint: '请联系客服完成支付' }, + // 未支付的展示文案由页面按 payChannel / 支付窗口派生,这里不再固定「联系客服」 + unpaid: { text: '未支付', color: '#B8520A', bg: '#FFF4E8', border: '#FFE0C2' }, partial: { text: '部分支付', color: '#B8520A', bg: '#FFF4E8', border: '#FFE0C2', hint: '请联系客服补齐剩余费用' }, paid: { text: '已支付', color: '#1F7A4D', bg: '#EAF6EE', border: '#CDE9D7' }, refunding: { text: '退款中', color: '#B8520A', bg: '#FFF4E8', border: '#FFE0C2', hint: '退款处理中,如需了解进度请联系客服' }, @@ -18,5 +28,6 @@ const PAYMENT_STATUS_MAP = { module.exports = { STATUS_MAP, - PAYMENT_STATUS_MAP + PAYMENT_STATUS_MAP, + resolveOrderStatus }