From 7b5599cd3d78bc89df4c7b2af67049af0c2faab4 Mon Sep 17 00:00:00 2001 From: lik Date: Thu, 5 Nov 2026 20:26:40 +0800 Subject: [PATCH] =?UTF-8?q?feat(escort):=20=E6=9C=8D=E5=8A=A1=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E9=A1=B5=E5=A2=9E=E5=8A=A0=E6=94=AF=E4=BB=98=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=BC=B9=E7=AA=97=EF=BC=8C=E5=88=97=E8=A1=A8=E6=8E=A5?= =?UTF-8?q?=E5=85=A5=E3=80=8C=E5=85=B6=E4=BB=96=E9=A1=B9=E7=9B=AE=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 提交预约后先选微信支付或线下支付,微信支付下单即拉起收银台并查单兜底;就医代办组补充 id 9 服务项。 --- pages/escort/itemdetail.js | 124 ++++++++++++++++++++++++++++++----- pages/escort/itemdetail.wxml | 36 ++++++++++ pages/escort/itemdetail.wxss | 95 +++++++++++++++++++++++++++ pages/escort/itemlist.js | 2 +- 4 files changed, 240 insertions(+), 17 deletions(-) diff --git a/pages/escort/itemdetail.js b/pages/escort/itemdetail.js index 0297534..83462a6 100644 --- a/pages/escort/itemdetail.js +++ b/pages/escort/itemdetail.js @@ -35,7 +35,10 @@ Page({ requiresAddress: false, gender: '不限', genderIndex: 0, - genderOptions: ['不限', '男', '女'] + genderOptions: ['不限', '男', '女'], + payChannel: 'online_wechat', + // 点击「提交预约」后弹出支付方式选择,默认微信支付 + showPayPopup: false }, onLoad(options) { @@ -318,6 +321,13 @@ Page({ return '' }, + onPayChannelChange(e) { + const channel = e.currentTarget.dataset.channel + if (!['online_wechat', 'offline'].includes(channel)) return + if (this.data.submitting) return + this.setData({ payChannel: channel }) + }, + submitOrder() { if (this.data.submitting) return const error = this.validateOrder() @@ -325,10 +335,58 @@ Page({ 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 error = this.validateOrder() + if (error) { + wx.showToast({ title: error, icon: 'none' }) + return + } + + 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 || '下单失败') + const record = res.data?.record + this.resetForm() + + 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' }) + } finally { + this.setData({ submitting: false }) + } + }, + + buildOrderData() { const data = this.data const sexMap = { 男: 'male', 女: 'female' } - const orderData = { + return { idempotencyKey: this.idempotencyKey, healthProfileId: data.selectedProfileId, escort: { @@ -344,24 +402,58 @@ Page({ startTime: data.appointmentTime }, shippingAddress: { address: data.shippingAddress.trim() }, - notes: { patientNote: data.remark.trim() } + notes: { patientNote: data.remark.trim() }, + payment: { payChannel: data.payChannel } } + }, - // 同步锁定按钮;网络重试沿用同一幂等键,服务端只创建一笔订单。 - this.setData({ submitting: true }) - API.escort.createRecord(orderData) - .then((res) => { - if (res.code !== 0) throw new Error(res.msg || '下单失败') - wx.showToast({ title: '下单成功', icon: 'success' }) - this.setData({ showOrderPopup: false }) - this.resetForm() - wx.navigateTo({ url: '/pages/escort/recordlist?tab=ongoing' }) + /** + * 发起微信支付: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 }) + }) }) - .catch((err) => { - console.log('下单失败', err) - wx.showToast({ title: err.message || '网络请求失败,请重试', icon: 'none' }) + + 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' }) - .finally(() => this.setData({ submitting: false })) + } 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() { diff --git a/pages/escort/itemdetail.wxml b/pages/escort/itemdetail.wxml index a6b8be3..f6f81cf 100644 --- a/pages/escort/itemdetail.wxml +++ b/pages/escort/itemdetail.wxml @@ -220,6 +220,42 @@ + + + + + 选择支付方式 + + + + + + + + + 微信支付 + 提交后立即拉起收银台 + + + + + + 线下支付 + 平台收款后确认订单 + + + + + 微信支付可立即完成付款;线下支付由平台收款后再确认订单。 + + + 取消 + + {{submitting ? '提交中...' : '确认提交'}} + + + + diff --git a/pages/escort/itemdetail.wxss b/pages/escort/itemdetail.wxss index 46844a9..179ecdd 100644 --- a/pages/escort/itemdetail.wxss +++ b/pages/escort/itemdetail.wxss @@ -732,6 +732,101 @@ page { transform: scale(0.98); } +/* ===== 支付方式选择 ===== */ +/* 两张可选卡片,选中态沿用品牌橙 */ +.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; +} + +/* 支付弹窗底部只放两个等宽按钮,覆盖下单弹窗的「左价格右按钮」布局 */ +.pay-actions { + justify-content: flex-end; + gap: 16rpx; +} + +.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) { .popup-content, .popup-mask { diff --git a/pages/escort/itemlist.js b/pages/escort/itemlist.js index 8bfa231..087aa78 100644 --- a/pages/escort/itemlist.js +++ b/pages/escort/itemlist.js @@ -24,7 +24,7 @@ const SERVICE_GROUPS = [{ // 「开药」已改为「取药」:国标 8.1 只列「领取药物」,开药属开具处方的医疗行为, // 会擦 8.2「提供医疗建议」「代替选择用药方案」;取药是凭已有处方代领,口径与 id 8 一致 note: '代问诊、跑腿取药取报告,本人不必到场。', - ids: [3, 4, 5, 6, 8] // 代问诊 / 检查预约 / 出入院代办 / 跑腿服务 / 取药快递 + ids: [3, 4, 5, 6, 8, 9] // 代问诊 / 检查预约 / 出入院代办 / 跑腿服务 / 取药快递 / 其他项目 } ]