接通前端订单与支付链路

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com
This commit is contained in:
lik
2026-10-24 18:18:15 +08:00
committed by trae-solo-agent
co-authored by Claude Sonnet 4.6 noreply@anthropic.com
parent 031227710d
commit d3f399d1ad
19 changed files with 817 additions and 705 deletions
+110 -80
View File
@@ -20,6 +20,7 @@ const PAYMENT_STATUS_MAP = {
unpaid: { text: '未支付', color: '#B8520A', bg: '#FFF4E8', border: '#FFE0C2', hint: '请联系客服完成支付' },
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: '退款处理中,如需了解进度请联系客服' },
refunded: { text: '已退款', color: '#6F655C', bg: 'transparent', border: '#E5DACC' }
}
@@ -40,12 +41,20 @@ Page({
data: {
recordId: '',
record: {},
service: null,
loading: false,
loadError: '',
// 编辑全部收进底部弹窗:页面只读,表单只活在弹窗里,两个弹窗各自一个开关
showNotePopup: false,
editPatientNote: '',
// 医院预约信息编辑弹窗:省份列表与下单页(itemdetail.js)保持同一份口径
// 医院预约规则与下单页一致,均由订单关联的服务目录下发
showHospitalPopup: false,
provinces: ['北京市', '天津市', '河北省', '山西省', '内蒙古自治区', '辽宁省', '吉林省', '黑龙江省', '上海市', '江苏省', '浙江省', '安徽省', '福建省', '江西省', '山东省', '河南省', '湖北省', '湖南省', '广东省', '广西壮族自治区', '海南省', '重庆市', '四川省', '贵州省', '云南省', '西藏自治区', '陕西省', '甘肃省', '青海省', '宁夏回族自治区', '新疆维吾尔自治区', '台湾省', '香港特别行政区', '澳门特别行政区'],
provinces: [],
minAppointmentDate: '',
fixedTime: false,
timeOptions: [],
timeStart: '',
timeEnd: '',
editHospital: {},
showCancelPopup: false,
cancelReason: '',
@@ -83,24 +92,61 @@ Page({
}
},
// 渲染到位判据是 record._id(WXML 用它守内容),本方法只负责取数
loadRecord(id) {
return API.escort.getRecordById(id)
.then((res) => {
if (res.code === 0 && res.data) {
const record = this.formatRecord(res.data.record)
this.setData({ record })
// 订单关联了健康档案时,就诊人信息以档案最新数据为准
if (record.healthProfileId) {
this.loadProfileSnapshot(record.healthProfileId)
}
} else {
wx.showToast({ title: res.msg || '加载失败', icon: 'none' })
}
})
.catch(() => {
wx.showToast({ title: '网络请求失败', icon: 'none' })
})
async loadRecord(id) {
this.setData({ loading: true, loadError: '' })
try {
const app = getApp()
await app.waitForAuth()
if (!app.globalData.user?._id) throw new Error('请先登录后查看订单')
const [res, services] = await Promise.all([
API.escort.getRecordById(id),
app.loadServices()
])
if (res.code !== 0 || !res.data?.record) throw new Error(res.msg || '订单加载失败')
if (!services) throw new Error('服务规则加载失败,请重试')
const item = res.data.record
const service = services.find(entry => entry.id === item.escort?.serviceId) || null
const record = this.formatRecord(item)
// 服务已下架时仍可查看历史订单,但不能再按失效规则修改订单。
if (!service) record.canEditOrder = false
this.setData({ record, service })
if (service) this.applyBookingConfig(service)
if (record.healthProfileId) this.loadProfileSnapshot(record.healthProfileId)
} catch (err) {
this.setData({ record: {}, loadError: err.message || '网络请求失败,请重试' })
} finally {
this.setData({ loading: false })
}
},
retryLoad() {
if (this.data.recordId) this.loadRecord(this.data.recordId)
},
applyBookingConfig(service) {
const booking = service.booking || {}
const sessions = booking.sessions || []
const fixedTime = sessions.length > 0 && sessions.every(item => !item.flexible)
const firstSession = sessions[0] || {}
const minDate = new Date()
minDate.setDate(minDate.getDate() + Number(booking.advanceDays || 0))
const minAppointmentDate = `${minDate.getFullYear()}-${String(minDate.getMonth() + 1).padStart(2, '0')}-${String(minDate.getDate()).padStart(2, '0')}`
let timeEnd = firstSession.end || ''
if (!fixedTime && firstSession.end && booking.durationMinutes) {
const [hour, minute] = firstSession.end.split(':').map(Number)
const latest = hour * 60 + minute - booking.durationMinutes
timeEnd = `${String(Math.floor(latest / 60)).padStart(2, '0')}:${String(latest % 60).padStart(2, '0')}`
}
this.setData({
provinces: service.areas || [],
minAppointmentDate,
fixedTime,
timeOptions: sessions.map(item => `${item.start} - ${item.end}`),
timeStart: firstSession.start || '',
timeEnd
})
},
// 用档案最新信息覆盖订单里的 patient 快照:
@@ -131,7 +177,7 @@ Page({
'record.patientWeight': patient.weight,
'record.patientHeight': patient.height,
'record.patientMobile': patient.mobile,
'record.patientIdnumber': patient.idnumber,
'record.patientIdnumber': this.maskIdNumber(patient.idnumber),
'record.patientInitial': patient.name.charAt(0),
'record.patientMeta': this.buildPatientMeta(patient)
})
@@ -152,8 +198,7 @@ Page({
const canCancel = status === 'pending' || status === 'confirmed'
const canDelete = paymentStatus === 'unpaid'
&& (status === 'pending' || status === 'confirmed' || status === 'cancelled')
const canComplete = status === 'completed'
const canRebook = status === 'completed' || status === 'cancelled'
const canRebook = (status === 'completed' || status === 'cancelled') && item.escort?.serviceId > 0
// 终态单据只读:医院预约与陪诊需求不允许回改(就诊人「修改」改的是档案,不在此列)
const canEditOrder = status !== 'completed' && status !== 'cancelled'
@@ -174,11 +219,13 @@ Page({
return {
_id: item._id,
displayId: item._id ? `****${String(item._id).slice(-8).toUpperCase()}` : '--',
healthProfileId: item.healthProfileId || '',
serviceId: item.escort?.serviceId || 0,
patientName: patient.name,
patientAge: patient.age,
patientMobile: patient.mobile,
patientIdnumber: patient.idnumber,
patientIdnumber: this.maskIdNumber(patient.idnumber),
patientInitial: patient.name.charAt(0),
patientMeta: this.buildPatientMeta(patient),
hospitalProvince: item.hospital?.province || '',
@@ -197,8 +244,11 @@ Page({
scheduleTimeText: scheduleMeta.timeText,
escortServiceName: item.escort?.serviceName || '',
sexRequirementText: SEX_REQUIREMENT_MAP[item.escort?.sexRequirement] || '',
shippingAddress: item.shippingAddress || null,
cancelReason: item.cancelReason || '',
totalFee: (item.payment?.totalFee || 0).toFixed(2),
paidFee: (item.payment?.paidFee || 0).toFixed(2),
showPaidFee: Number(item.payment?.paidFee) > 0,
paymentStatus,
paymentStatusText: paymentInfo.text,
paymentStatusColor: paymentInfo.color,
@@ -216,11 +266,10 @@ Page({
statusDesc: statusInfo.desc,
canCancel,
canDelete,
canComplete,
canRebook,
canEditOrder,
// 底栏只在确实有按钮时出现,避免无动作状态空留一条白栏
showBottomBar: canCancel || canDelete || canComplete || canRebook,
showBottomBar: canCancel || canDelete || canRebook,
createTime: item.meta?.createtime ? this.formatDateTime(item.meta.createtime) : '',
updateTime: item.meta?.updatetime ? this.formatDateTime(item.meta.updatetime) : ''
}
@@ -303,6 +352,21 @@ Page({
return `${year}-${month}-${day} ${hour}:${minute}`
},
maskIdNumber(idNumber) {
const value = String(idNumber || '').trim()
if (!value) return ''
if (value.length <= 8) return '********'
return `${value.slice(0, 4)}********${value.slice(-4)}`
},
onContactSupport() {
const record = this.data.record
if (!record._id) return
wx.navigateTo({
url: `/pages/mine/contact?orderId=${encodeURIComponent(record._id)}`
})
},
onCallPatient() {
const mobile = this.data.record.patientMobile
if (!mobile || mobile === '--') return
@@ -356,10 +420,12 @@ Page({
onEditHospital() {
const r = this.data.record
const provinceIndex = Math.max(0, this.data.provinces.indexOf(r.hospitalProvince))
const sessions = this.data.service?.booking?.sessions || []
const sessionIndex = Math.max(0, sessions.findIndex(item => item.start === r.scheduleStartTime))
this.setData({
showHospitalPopup: true,
editHospital: {
province: r.hospitalProvince || '',
province: r.hospitalProvince || this.data.provinces[0] || '',
provinceIndex,
name: r.hospitalName || '',
address: r.hospitalAddress || '',
@@ -368,7 +434,7 @@ Page({
medicalRecordNo: r.medicalRecordNo || '',
scheduleDate: r.scheduleDate || '',
startTime: r.scheduleStartTime || '',
endTime: r.scheduleEndTime || ''
sessionIndex
}
})
},
@@ -392,22 +458,18 @@ Page({
},
onStartTimeChange(e) {
if (this.data.fixedTime) {
const sessionIndex = Number(e.detail.value)
const session = this.data.service.booking.sessions[sessionIndex]
this.setData({
'editHospital.sessionIndex': sessionIndex,
'editHospital.startTime': session.start
})
return
}
this.setData({ 'editHospital.startTime': e.detail.value })
},
onEndTimeChange(e) {
this.setData({ 'editHospital.endTime': e.detail.value })
},
// 起止时间都在时重算陪诊时长(分钟);结束不晚于开始视为无效,拦在保存前
calcDuration(startTime, endTime) {
if (!startTime || !endTime) return null
const [sh, sm] = startTime.split(':').map(Number)
const [eh, em] = endTime.split(':').map(Number)
const diff = eh * 60 + em - (sh * 60 + sm)
return diff > 0 ? diff : -1
},
onCancelHospitalEdit() {
this.setData({ showHospitalPopup: false })
},
@@ -422,9 +484,8 @@ Page({
wx.showToast({ title: '请选择预约日期', icon: 'none' })
return
}
const duration = this.calcDuration(form.startTime, form.endTime)
if (duration === -1) {
wx.showToast({ title: '结束时间需晚于开始时间', icon: 'none' })
if (!form.startTime) {
wx.showToast({ title: '请选择预约时间', icon: 'none' })
return
}
@@ -435,13 +496,9 @@ Page({
'hospital.department': (form.department || '').trim(),
'hospital.doctor': (form.doctor || '').trim(),
'hospital.medicalRecordNo': (form.medicalRecordNo || '').trim(),
// schedule.date 后端是 Date 类型,mongoose 会把 YYYY-MM-DD 字符串自动转换
// 时长与结束时间由后端按服务目录重新派生,前端只提交业务输入。
'schedule.date': form.scheduleDate,
'schedule.startTime': form.startTime || '',
'schedule.endTime': form.endTime || ''
}
if (duration !== null) {
update['schedule.duration'] = duration
'schedule.startTime': form.startTime
}
wx.showLoading({ title: '保存中...' })
@@ -516,35 +573,6 @@ Page({
})
},
onConfirmComplete() {
wx.showModal({
title: '确认完成',
content: '确认陪诊服务已完成?',
confirmColor: '#B8520A',
success: (res) => {
if (res.confirm) {
wx.showLoading({ title: '处理中...' })
API.escort.updateStatus(this.data.recordId, {
status: 'completed'
})
.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' })
})
}
}
})
},
onDeleteOrder() {
wx.showModal({
title: '删除订单',
@@ -575,8 +603,10 @@ Page({
},
onRebook() {
const serviceId = this.data.record.serviceId
if (!serviceId) return
wx.navigateTo({
url: `/pages/escort/itemlist`
url: `/pages/escort/itemdetail?id=${serviceId}&book=1`
})
},