From e6517e3cae35b7a86ef67a02b99ad8407f17abdc Mon Sep 17 00:00:00 2001 From: lik Date: Fri, 13 Nov 2026 15:48:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(escort):=20=E4=B8=8B=E5=8D=95=E9=A1=B5?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=8D=E8=B4=A3=E5=8D=8F=E8=AE=AE=E5=8B=BE?= =?UTF-8?q?=E9=80=89=E4=B8=8E=E5=8D=8F=E8=AE=AE=E5=BC=B9=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 提交预约前须勾选《全程陪诊服务免责协议》,点击协议名弹层查看全文;提交时回传所读版本,服务端判定过期则作废缓存并重新弹层要求重新确认。 --- app.js | 25 ++++++ pages/escort/itemorder.js | 79 +++++++++++++++++- pages/escort/itemorder.wxml | 57 +++++++++++++ pages/escort/itemorder.wxss | 162 +++++++++++++++++++++++++++++++++++- utils/api.js | 2 + 5 files changed, 322 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index a3fb8c9..1fb5438 100644 --- a/app.js +++ b/app.js @@ -222,6 +222,29 @@ App({ return this.globalData.agreementReady }, + // 下单页的免责协议:与「用户协议」分开缓存,正文修订后随接口即时生效 + loadDisclaimer() { + if (this.globalData.disclaimerReady) return this.globalData.disclaimerReady + this.globalData.disclaimerReady = API.resource.getDisclaimer() + .then((res) => { + if (res.code !== 0 || !res.data?.disclaimer) throw new Error(res.msg || '免责协议加载失败') + this.globalData.disclaimer = res.data.disclaimer + return this.globalData.disclaimer + }) + .catch((err) => { + console.error('获取免责协议失败', err) + this.globalData.disclaimerReady = null + return null + }) + return this.globalData.disclaimerReady + }, + + // 服务端判定协议版本不一致后调用:作废缓存,下次 loadDisclaimer 重新拉取最新版 + invalidateDisclaimer() { + this.globalData.disclaimer = null + this.globalData.disclaimerReady = null + }, + // 已经拿到用户(如「我的」页手机号授权登录成功)就直接返回成功。 // 但若此刻有静默登录在飞(token 可能正在轮换),要先等它落定: // 抢跑会让页面拿旧 token 发请求、收到 401 再触发一次重登 + 重试。 @@ -353,6 +376,8 @@ App({ hospitalsReady: null, agreement: null, agreementReady: null, + disclaimer: null, + disclaimerReady: null, authReady: null, } }) \ No newline at end of file diff --git a/pages/escort/itemorder.js b/pages/escort/itemorder.js index 1c1391e..08a2848 100644 --- a/pages/escort/itemorder.js +++ b/pages/escort/itemorder.js @@ -8,6 +8,8 @@ const SERVICE_OPTION_HEIGHT = 108 const SERVICE_PANEL_RESERVED = 200 // 与陪诊师列表 / 详情页共用的选择结果 key const SELECTED_ATTENDANT_KEY = 'escort_selected_attendant' +// 免责协议标题兜底:接口未返回时也能在勾选行展示协议名称 +const DEFAULT_DISCLAIMER_TITLE = '全程陪诊服务免责协议' Page({ data: { @@ -48,7 +50,15 @@ Page({ genderIndex: 0, genderOptions: ['不限', '男', '女'], // 用户指定陪诊师(选填);为空则由平台抢单或管理端指派 - selectedAttendant: null + selectedAttendant: null, + // 下单前必须勾选确认《全程陪诊服务免责协议》 + agreementAgreed: false, + agreementHint: false, + agreementTitle: DEFAULT_DISCLAIMER_TITLE, + showAgreementPopup: false, + disclaimer: null, + disclaimerLoading: false, + disclaimerError: false }, onLoad(options) { @@ -92,9 +102,56 @@ Page({ this.setData({ selectedAttendant: null }) }, + /** + * 免责协议:与表单并行预加载,用户点开弹层或直接提交时都能立即展示 + */ + loadDisclaimer() { + if (this.data.disclaimer || this.data.disclaimerLoading) return + this.setData({ disclaimerLoading: true, disclaimerError: false }) + getApp().loadDisclaimer().then((disclaimer) => { + this.setData({ + disclaimer, + agreementTitle: disclaimer?.title || DEFAULT_DISCLAIMER_TITLE, + disclaimerLoading: false, + disclaimerError: !disclaimer + }) + }) + }, + + onToggleAgreement() { + if (this.data.submitting) return + this.setData({ + agreementAgreed: !this.data.agreementAgreed, + agreementHint: false + }) + }, + + onOpenAgreement() { + this.setData({ showAgreementPopup: true }) + this.loadDisclaimer() + }, + + onCloseAgreementPopup() { + this.setData({ showAgreementPopup: false }) + }, + + onAgreeFromPopup() { + this.setData({ + agreementAgreed: true, + agreementHint: false, + showAgreementPopup: false + }) + }, + + retryLoadDisclaimer() { + this.loadDisclaimer() + }, + async initializePage() { this.pageReady = false this.setData({ pageLoading: true, pageError: '' }) + // 免责协议与表单并行加载,避免用户点开协议时再空等 + this.loadDisclaimer() const services = await getApp().loadServices() if (!services || services.length === 0) { this.setData({ pageLoading: false, pageError: '服务加载失败,请重试' }) @@ -360,6 +417,12 @@ Page({ wx.showToast({ title: error, icon: 'none' }) return } + // 免责协议是下单前置条件:未勾选时直接拉起协议弹层,读完即可勾选 + if (!this.data.agreementAgreed) { + this.setData({ agreementHint: true, showAgreementPopup: true }) + this.loadDisclaimer() + return + } this.setData({ showPayPopup: true, payChannel: 'online_wechat' }) }, @@ -409,6 +472,12 @@ Page({ else wx.navigateTo({ url: '/pages/escort/recordlist?tab=ongoing' }) } catch (err) { console.log('下单失败', err) + // 服务端判定协议版本不一致:作废本地缓存、重新拉取并弹出协议要求重新确认 + if ((err.message || '').includes('协议已更新')) { + getApp().invalidateDisclaimer() + this.setData({ disclaimer: null, agreementAgreed: false, showAgreementPopup: true }) + this.loadDisclaimer() + } wx.showToast({ title: err.message || '网络请求失败,请重试', icon: 'none' }) } finally { this.setData({ submitting: false }) @@ -436,6 +505,8 @@ Page({ shippingAddress: { address: data.shippingAddress.trim() }, notes: { patientNote: data.remark.trim() }, payment: { payChannel: data.payChannel }, + // 协议确认快照:回传用户实际阅读的协议版本,服务端与当前版本比对,不一致则拒绝 + agreement: { accepted: true, version: data.disclaimer?.version || '' }, // 只传 employeeId,姓名 / 电话由服务端按员工档案回填 ...(data.selectedAttendant ? { attendant: { employeeId: data.selectedAttendant.id } } @@ -512,7 +583,11 @@ Page({ genderIndex: 0, remark: '', shippingAddress: '', - selectedAttendant: null + selectedAttendant: null, + // 协议按单次服务确认,重置表单后需重新勾选 + agreementAgreed: false, + agreementHint: false, + showAgreementPopup: false }, () => this.refreshHospitalOptions(provinces[0] || '')) // 重置后仍默认选中第一个就诊人,方便连续预约 const first = this.data.profiles[0] diff --git a/pages/escort/itemorder.wxml b/pages/escort/itemorder.wxml index 74c846b..e320e79 100644 --- a/pages/escort/itemorder.wxml +++ b/pages/escort/itemorder.wxml @@ -155,6 +155,20 @@