基本重构完成
This commit is contained in:
+60
-52
@@ -16,9 +16,11 @@ Page({
|
||||
totalPrice: '0.00',
|
||||
showOrderPopup: false,
|
||||
profiles: [], // 已保存的就诊人
|
||||
selectedProfileId: '', // 当前选中的就诊人档案 ID,为空表示手动填写
|
||||
patientName: '',
|
||||
patientPhone: '',
|
||||
selectedProfileId: '', // 必填:订单必须关联就诊人档案
|
||||
patientName: '', // 只读展示,来自所选档案
|
||||
patientPhone: '', // 只读展示,来自所选档案
|
||||
// 选中档案的全部信息,下单时整体写入订单 patient 快照
|
||||
selectedPatient: null,
|
||||
// 默认北京:取值必须与 provinces[0] 完全一致('北京市' 而非 '北京'),
|
||||
// 否则 picker 的 value=0 与显示文案会对不上
|
||||
province: '北京市',
|
||||
@@ -99,11 +101,12 @@ Page({
|
||||
return
|
||||
}
|
||||
|
||||
const user = app.globalData.user
|
||||
// 订单必须关联健康档案,就诊人不再手输:打开弹窗时清空,等用户选择就诊人后带入
|
||||
this.setData({
|
||||
patientName: user.profile?.name || '',
|
||||
patientPhone: user.profile?.mobile || '',
|
||||
patientName: '',
|
||||
patientPhone: '',
|
||||
selectedProfileId: '',
|
||||
selectedPatient: null,
|
||||
showOrderPopup: true
|
||||
})
|
||||
|
||||
@@ -120,11 +123,21 @@ Page({
|
||||
if (res.code !== 0) {
|
||||
return
|
||||
}
|
||||
const list = ((res.data && res.data.list) || []).map((item) => ({
|
||||
_id: item._id,
|
||||
name: item.profile?.name || '',
|
||||
mobile: item.profile?.mobile || ''
|
||||
}))
|
||||
// 档案是 profile + health 两层嵌套,这里拍平成选人后可直接带入的字段
|
||||
const list = ((res.data && res.data.list) || []).map((item) => {
|
||||
const profile = item.profile || {}
|
||||
const health = item.health || {}
|
||||
return {
|
||||
_id: item._id,
|
||||
name: profile.name || '',
|
||||
mobile: profile.mobile || '',
|
||||
sex: profile.sex || '',
|
||||
birth: profile.birth || '',
|
||||
weight: health.weight || 0,
|
||||
height: health.height || 0,
|
||||
idnumber: profile.idnumber || ''
|
||||
}
|
||||
})
|
||||
this.setData({
|
||||
profiles: list
|
||||
})
|
||||
@@ -134,7 +147,7 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
// 选择就诊人:自动带入姓名与联系电话
|
||||
// 选择就诊人:姓名/电话回填展示,其余字段存入 selectedPatient 供下单使用
|
||||
onSelectProfile(e) {
|
||||
const id = e.currentTarget.dataset.id
|
||||
const profile = this.data.profiles.find((item) => item._id === id)
|
||||
@@ -144,8 +157,16 @@ Page({
|
||||
|
||||
this.setData({
|
||||
selectedProfileId: id,
|
||||
// patientName / patientPhone 只用于弹窗内只读展示
|
||||
patientName: profile.name,
|
||||
patientPhone: profile.mobile
|
||||
patientPhone: profile.mobile,
|
||||
// 订单 patient 快照的唯一来源:所选档案的名单字段(体征与证件号不进快照)
|
||||
selectedPatient: {
|
||||
name: profile.name,
|
||||
mobile: profile.mobile,
|
||||
sex: profile.sex,
|
||||
birth: profile.birth
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
@@ -162,21 +183,6 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
// 手动修改姓名/电话后,不再与所选档案对应,清空选择避免存档信息不一致
|
||||
onPatientNameChange(e) {
|
||||
this.setData({
|
||||
patientName: e.detail.value,
|
||||
selectedProfileId: ''
|
||||
})
|
||||
},
|
||||
|
||||
onPatientPhoneChange(e) {
|
||||
this.setData({
|
||||
patientPhone: e.detail.value,
|
||||
selectedProfileId: ''
|
||||
})
|
||||
},
|
||||
|
||||
onProvinceChange(e) {
|
||||
const index = e.detail.value
|
||||
const province = this.data.provinces[index]
|
||||
@@ -228,8 +234,8 @@ Page({
|
||||
submitOrder() {
|
||||
const {
|
||||
service,
|
||||
patientName,
|
||||
patientPhone,
|
||||
selectedProfileId,
|
||||
selectedPatient,
|
||||
province,
|
||||
hospital,
|
||||
department,
|
||||
@@ -239,16 +245,10 @@ Page({
|
||||
remark
|
||||
} = this.data
|
||||
|
||||
if (!patientName.trim()) {
|
||||
// 订单必须关联就诊人:没有档案就没有 patient 快照,不允许下单
|
||||
if (!selectedProfileId || !selectedPatient) {
|
||||
wx.showToast({
|
||||
title: '请输入就诊人姓名',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!patientPhone.trim()) {
|
||||
wx.showToast({
|
||||
title: '请输入联系电话',
|
||||
title: '请选择就诊人',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
@@ -283,9 +283,9 @@ Page({
|
||||
}
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
if (!phoneRegex.test(patientPhone.trim())) {
|
||||
if (!phoneRegex.test(selectedPatient.mobile.trim())) {
|
||||
wx.showToast({
|
||||
title: '请输入正确的手机号',
|
||||
title: '就诊人手机号有误,请到就诊人档案修改',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
@@ -297,12 +297,22 @@ Page({
|
||||
if (gender == '男') sex = 'male'
|
||||
else if (gender == '女') sex = 'female'
|
||||
|
||||
// 就诊人快照只取名单字段(schema 口径:name/mobile/sex/birth);
|
||||
// sex 是 male/female 枚举,空值不写该字段
|
||||
const patient = {
|
||||
name: selectedPatient.name.trim(),
|
||||
mobile: selectedPatient.mobile.trim(),
|
||||
birth: selectedPatient.birth || ''
|
||||
}
|
||||
if (selectedPatient.sex) {
|
||||
patient.sex = selectedPatient.sex
|
||||
}
|
||||
|
||||
const orderData = {
|
||||
userId: user._id,
|
||||
patient: {
|
||||
name: patientName.trim(),
|
||||
mobile: patientPhone.trim(),
|
||||
},
|
||||
// 订单与就诊人档案的关联,必填(patient 只是下单当刻的快照)
|
||||
healthProfileId: selectedProfileId,
|
||||
patient: patient,
|
||||
escort: {
|
||||
serviceId: service.id,
|
||||
serviceName: service.title,
|
||||
@@ -325,11 +335,6 @@ Page({
|
||||
}
|
||||
}
|
||||
|
||||
// 选择了已保存的就诊人时,一并记录档案 ID
|
||||
if (this.data.selectedProfileId) {
|
||||
orderData.healthProfileId = this.data.selectedProfileId
|
||||
}
|
||||
|
||||
wx.showLoading({
|
||||
title: '提交中...'
|
||||
})
|
||||
@@ -346,7 +351,8 @@ Page({
|
||||
showOrderPopup: false
|
||||
})
|
||||
this.resetForm()
|
||||
wx.navigateTo({url: '/pages/escort/recordlist?tab=pending'})
|
||||
// 下单成功回到记录页,直接落到「进行中的」:新单是待确认,属未完成档
|
||||
wx.navigateTo({url: '/pages/escort/recordlist?tab=ongoing'})
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: data.msg || '下单失败',
|
||||
@@ -369,6 +375,7 @@ Page({
|
||||
selectedProfileId: '',
|
||||
patientName: '',
|
||||
patientPhone: '',
|
||||
selectedPatient: null,
|
||||
// 重置后仍回到默认北京,与 data 初值保持一致
|
||||
province: '北京市',
|
||||
provinceIndex: 0,
|
||||
@@ -376,7 +383,8 @@ Page({
|
||||
department: '',
|
||||
appointmentDate: '',
|
||||
appointmentTime: '',
|
||||
gender: '',
|
||||
// 重置后回到默认「不限」,与 data 初值(gender: '不限' / genderIndex: 0)保持一致
|
||||
gender: '不限',
|
||||
genderIndex: 0,
|
||||
remark: ''
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user