feat(escort): 下单页增加免责协议勾选与协议弹层

提交预约前须勾选《全程陪诊服务免责协议》,点击协议名弹层查看全文;提交时回传所读版本,服务端判定过期则作废缓存并重新弹层要求重新确认。
This commit is contained in:
lik
2026-11-13 15:48:19 +08:00
parent e4ca0ec2b9
commit e6517e3cae
5 changed files with 322 additions and 3 deletions
+77 -2
View File
@@ -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]