完善表单校验与公共数据逻辑

Co-Authored-By: Kimi-K3.1-Pro <noreply@moonshot.ai>
This commit is contained in:
lik
2026-10-24 18:49:02 +08:00
committed by trae-solo-agent
co-authored by Kimi-K3.1-Pro
parent d731fc1da3
commit a45a3d7a86
18 changed files with 496 additions and 336 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
const API = require('../../utils/api.js')
const { formatDate } = require('../../utils/date.js')
Page({
data: {
@@ -88,7 +89,7 @@ Page({
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')}`
const minAppointmentDate = formatDate(minDate)
let timeEnd = firstSession.end || ''
if (!fixedTime && firstSession.end && booking.durationMinutes) {
const [hour, minute] = firstSession.end.split(':').map(Number)
+23 -13
View File
@@ -44,7 +44,9 @@ function formatPrice(value) {
Page({
data: {
groups: []
groups: [],
loading: true,
loadError: ''
},
onShareAppMessage() {
@@ -61,23 +63,23 @@ Page({
},
onLoad() {
const app = getApp()
// 与首页同样走 servicesReady,避免直接从详情页返回时 globalData 尚未就绪
const ready = app.globalData.servicesReady || Promise.resolve(app.globalData.services || [])
this.loadServices()
},
async loadServices() {
this.setData({ loading: true, loadError: '' })
try {
const services = await getApp().loadServices()
if (!services) throw new Error('服务加载失败,请重试')
ready.then((services) => {
const list = services || []
const serviceMap = {}
list.forEach((service) => {
services.forEach((service) => {
serviceMap[service.id] = service
})
// 取到服务后再加工成列表页要用的字段:unit 补规格签,price 去掉 .00。
// 说明句不再加工,直接用 subtitle 原文——原先按「第一个逗号」剥时长前缀,
// 副标题一旦写成「八小时服务/次(早8点-中午12点,下午1点-晚上5点),…」,
// 括号里的逗号会先被匹配上,行内只剩「下午1点-晚上5点),专业陪诊师全程陪同」,
// 开头半个括号、括号不配对。行内允许折行,不靠截文案来压行数。
// 最后空组不展示,免得留下一个没有服务、只有标题的分组
// 说明句直接使用 subtitle 原文,允许折行,不靠截断来压缩行数。
const groups = SERVICE_GROUPS
.map((group) => ({
key: group.key,
@@ -95,7 +97,15 @@ Page({
.filter((group) => group.items.length > 0)
this.setData({ groups })
})
} catch (err) {
this.setData({ groups: [], loadError: err.message || '网络请求失败,请重试' })
} finally {
this.setData({ loading: false })
}
},
retryLoad() {
this.loadServices()
},
// 预约:带 book=1 进详情页,详情页读完服务后会自己把预约单弹出来,
+11
View File
@@ -20,6 +20,17 @@
<text class="notice-text">目前已开通北京、天津。费用仅含人工服务费,不含就医费用。</text>
</view>
<view class="page-state" wx:if="{{loading}}">
<t-loading theme="circular" size="40rpx" text="加载中..." />
</view>
<view class="page-state" wx:elif="{{loadError}}">
<text class="page-state-text">{{loadError}}</text>
<view class="page-retry" bindtap="retryLoad">重新加载</view>
</view>
<view class="page-state" wx:elif="{{groups.length === 0}}">
<text class="page-state-text">暂无可用服务</text>
</view>
<!-- 服务按"要办的事"分两组,每组是"组头 + 每项一张白卡":
组头(竖条 + 36rpx 标题 + 暖橙底副题)落在纸面上,下面直接堆叠服务白卡。
分组本轮由"通栏白底章节带"改为"组头在纸面上、卡片逐张堆叠"(原理详见 itemlist.wxss 的 .group)。
+25
View File
@@ -146,6 +146,31 @@ page {
line-height: 1.7;
}
/* ===== 加载、失败与真实空态 ===== */
.page-state {
display: flex;
flex-direction: column;
align-items: center;
padding: 80rpx 32rpx;
}
.page-state-text {
font-size: 28rpx;
line-height: 1.6;
color: var(--muted);
text-align: center;
}
.page-retry {
margin-top: 24rpx;
padding: 12rpx 28rpx;
border: 2rpx solid var(--brand-strong);
border-radius: 28rpx;
font-size: 26rpx;
font-weight: 500;
color: var(--brand-strong);
}
/* ===== 页尾文档行 =====
服务指南 / 用户协议两枚链接,从页首披露卡下移到这里。
不做卡:清单已由末张服务卡收口,页尾只补一行"文档级"元信息,重量压到最低。
+14 -71
View File
@@ -1,28 +1,8 @@
const API = require('../../utils/api.js')
// 状态配色遵循 doc/DESIGN.md §三:四档状态色 + 状态说明文字,
// 颜色只做强化,文字才是信息。待确认与已确认同属「等待」阶段,共用待服务档
const STATUS_MAP = {
// 待确认是唯一「等用户自己决定」的阶段(底栏此时一定有「取消订单」),
// 说明文字因此带上可执行动作,靠文字而不是靠再叠一层色块来提请注意
pending: { text: '待确认', color: '#0F766E', bg: '#ECF7F4', border: '#C7E5DF', desc: '订单已提交,等待陪诊师确认;确认前可取消' },
confirmed: { text: '已确认', color: '#0F766E', bg: '#ECF7F4', border: '#C7E5DF', desc: '订单已确认,陪诊师将准时为您服务' },
in_progress: { text: '进行中', color: '#B8520A', bg: '#FFF4E8', border: '#FFE0C2', desc: '陪诊服务正在进行中' },
completed: { text: '已完成', color: '#1F7A4D', bg: '#EAF6EE', border: '#CDE9D7', desc: '陪诊服务已完成,感谢您的使用' },
cancelled: { text: '已取消', color: '#B4231A', bg: '#FCF0EE', border: '#F2D6D1', desc: '该订单已取消' }
}
// 支付状态胶囊:未支付 / 部分支付复用主色浅档提示待处理;已退款走中性档(--muted 字 + --sep 描边 + 透明底);
// 已支付不显示胶囊(支付完成是常态,不需要状态强调),paid 档仅为映射兜底保留。
// hint 是未付清时的出口指引:全站没有线上支付入口,只能引导走客服;
// 部分支付要说清是「补齐」而不是「完成支付」,否则用户会以为要再付一次全款
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' }
}
const { parseDate, formatDate, formatDateTime, calcAge } = require('../../utils/date.js')
const { STATUS_MAP, PAYMENT_STATUS_MAP } = require('../../utils/order.js')
const { maskIdNumber, maskOrderId } = require('../../utils/privacy.js')
const SEX_MAP = {
male: '男',
@@ -132,7 +112,7 @@ Page({
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')}`
const minAppointmentDate = formatDate(minDate)
let timeEnd = firstSession.end || ''
if (!fixedTime && firstSession.end && booking.durationMinutes) {
const [hour, minute] = firstSession.end.split(':').map(Number)
@@ -165,7 +145,7 @@ Page({
const patient = {
name: profile.name || '',
sexText: SEX_MAP[profile.sex] || '',
age: this.calcAge(profile.birth),
age: calcAge(profile.birth),
weight: health.weight || 0,
height: health.height || 0,
mobile: profile.mobile || '',
@@ -177,7 +157,7 @@ Page({
'record.patientWeight': patient.weight,
'record.patientHeight': patient.height,
'record.patientMobile': patient.mobile,
'record.patientIdnumber': this.maskIdNumber(patient.idnumber),
'record.patientIdnumber': maskIdNumber(patient.idnumber),
'record.patientInitial': patient.name.charAt(0),
'record.patientMeta': this.buildPatientMeta(patient)
})
@@ -207,7 +187,7 @@ Page({
const patient = {
name: item.patient?.name || '',
sexText: SEX_MAP[item.patient?.sex] || '',
age: this.calcAge(item.patient?.birth),
age: calcAge(item.patient?.birth),
weight: item.patient?.weight || 0,
height: item.patient?.height || 0,
mobile: item.patient?.mobile || '',
@@ -219,13 +199,13 @@ Page({
return {
_id: item._id,
displayId: item._id ? `****${String(item._id).slice(-8).toUpperCase()}` : '--',
displayId: maskOrderId(item._id),
healthProfileId: item.healthProfileId || '',
serviceId: item.escort?.serviceId || 0,
patientName: patient.name,
patientAge: patient.age,
patientMobile: patient.mobile,
patientIdnumber: this.maskIdNumber(patient.idnumber),
patientIdnumber: maskIdNumber(patient.idnumber),
patientInitial: patient.name.charAt(0),
patientMeta: this.buildPatientMeta(patient),
hospitalProvince: item.hospital?.province || '',
@@ -237,7 +217,7 @@ Page({
hospitalDoctor: item.hospital?.doctor || '',
medicalRecordNo: item.hospital?.medicalRecordNo || '',
// scheduleDate 保留 YYYY-MM-DD 原格式:编辑弹窗的 date picker 直接喂它
scheduleDate: item.schedule?.date ? this.formatDate(item.schedule.date) : '',
scheduleDate: item.schedule?.date ? formatDate(item.schedule.date) : '',
scheduleStartTime: item.schedule?.startTime || '',
scheduleEndTime: item.schedule?.endTime || '',
scheduleDateText: scheduleMeta.dateText,
@@ -270,8 +250,8 @@ Page({
canEditOrder,
// 底栏只在确实有按钮时出现,避免无动作状态空留一条白栏
showBottomBar: canCancel || canDelete || canRebook,
createTime: item.meta?.createtime ? this.formatDateTime(item.meta.createtime) : '',
updateTime: item.meta?.updatetime ? this.formatDateTime(item.meta.updatetime) : ''
createTime: item.meta?.createtime ? formatDateTime(item.meta.createtime) : '',
updateTime: item.meta?.updatetime ? formatDateTime(item.meta.updatetime) : ''
}
},
@@ -301,8 +281,8 @@ Page({
buildScheduleMeta(schedule) {
const result = { dateText: '', timeText: '' }
if (schedule.date) {
const d = new Date(schedule.date)
if (!isNaN(d.getTime())) {
const d = parseDate(schedule.date)
if (d) {
result.dateText = `${d.getFullYear()}年${d.getMonth() + 1}月${d.getDate()}日 ${WEEKDAYS[d.getDay()]}`
}
}
@@ -322,43 +302,6 @@ Page({
return result
},
// 根据出生年月(YYYY-MM-DD)计算年龄
calcAge(birth) {
if (!birth) return 0
const d = new Date(birth)
if (isNaN(d.getTime())) return 0
const now = new Date()
let age = now.getFullYear() - d.getFullYear()
const m = now.getMonth() - d.getMonth()
if (m < 0 || (m === 0 && now.getDate() < d.getDate())) age--
return age > 0 ? age : 0
},
formatDate(dateStr) {
const d = new Date(dateStr)
const year = d.getFullYear()
const month = String(d.getMonth() + 1).padStart(2, '0')
const day = String(d.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
},
formatDateTime(dateStr) {
const d = new Date(dateStr)
const year = d.getFullYear()
const month = String(d.getMonth() + 1).padStart(2, '0')
const day = String(d.getDate()).padStart(2, '0')
const hour = String(d.getHours()).padStart(2, '0')
const minute = String(d.getMinutes()).padStart(2, '0')
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
+3 -27
View File
@@ -1,21 +1,6 @@
const API = require('../../utils/api.js')
// 状态配色遵循 doc/DESIGN.md §三,颜色只作强化,文字才是信息。
const STATUS_MAP = {
pending: { text: '待确认', color: '#0F766E', bg: '#ECF7F4', border: '#C7E5DF' },
confirmed: { text: '已确认', color: '#0F766E', bg: '#ECF7F4', border: '#C7E5DF' },
in_progress: { text: '进行中', color: '#B8520A', bg: '#FFF4E8', border: '#FFE0C2' },
completed: { text: '已完成', color: '#1F7A4D', bg: '#EAF6EE', border: '#CDE9D7' },
cancelled: { text: '已取消', color: '#B4231A', bg: '#FCF0EE', border: '#F2D6D1' }
}
const PAYMENT_STATUS_MAP = {
unpaid: { text: '未支付', color: '#B8520A', bg: '#FFF4E8', border: '#FFE0C2' },
partial: { text: '部分支付', color: '#B8520A', bg: '#FFF4E8', border: '#FFE0C2' },
paid: { text: '已支付', color: '#1F7A4D', bg: '#EAF6EE', border: '#CDE9D7' },
refunding: { text: '退款中', color: '#B8520A', bg: '#FFF4E8', border: '#FFE0C2' },
refunded: { text: '已退款', color: '#6F655C', bg: 'transparent', border: '#E5DACC' }
}
const { formatDate } = require('../../utils/date.js')
const { STATUS_MAP, PAYMENT_STATUS_MAP } = require('../../utils/order.js')
// 左右滑动切换状态页的手势参数(单位 px)
const SWIPE_THRESHOLD = 50
@@ -120,7 +105,7 @@ Page({
const paymentStatusInfo = PAYMENT_STATUS_MAP[item.payment?.status] || PAYMENT_STATUS_MAP.unpaid
const fee = Number(item.payment?.totalFee) || 0
const appointmentTime = item.schedule?.date
? `${this.formatDate(item.schedule.date)} ${item.schedule.startTime || ''}`.trim()
? `${formatDate(item.schedule.date, '--')} ${item.schedule.startTime || ''}`.trim()
: '--'
return {
@@ -142,15 +127,6 @@ Page({
}
},
formatDate(dateStr) {
const d = new Date(dateStr)
if (isNaN(d.getTime())) return '--'
const year = d.getFullYear()
const month = String(d.getMonth() + 1).padStart(2, '0')
const day = String(d.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
},
onTabChange(e) {
this.switchStatusTab(Number(e.currentTarget.dataset.index))
},