diff --git a/pages/escort/itemdetail.js b/pages/escort/itemdetail.js
index 33165d5..ebfe6c7 100644
--- a/pages/escort/itemdetail.js
+++ b/pages/escort/itemdetail.js
@@ -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)
diff --git a/pages/escort/itemlist.js b/pages/escort/itemlist.js
index 11db7be..8bfa231 100644
--- a/pages/escort/itemlist.js
+++ b/pages/escort/itemlist.js
@@ -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 进详情页,详情页读完服务后会自己把预约单弹出来,
diff --git a/pages/escort/itemlist.wxml b/pages/escort/itemlist.wxml
index 2fc7442..7d5dde7 100644
--- a/pages/escort/itemlist.wxml
+++ b/pages/escort/itemlist.wxml
@@ -20,6 +20,17 @@
目前已开通北京、天津。费用仅含人工服务费,不含就医费用。
+
+
+
+
+ {{loadError}}
+ 重新加载
+
+
+ 暂无可用服务
+
+
+
+
+ 正在加载就诊人信息
+
+
+
+ {{loadError}}
+ 重新加载
+
-
+
姓名
+ {{errors.name}}
@@ -28,34 +39,39 @@
{{form.birth || '请选择出生年月'}}
+ {{errors.birth}}
联系电话
+ {{errors.mobile}}
证件号
+ maxlength="18" data-field="idnumber" bindinput="onFieldInput" />
+ {{errors.idnumber}}
-
+
身高(cm)
+ {{errors.height}}
体重(kg)
+ {{errors.weight}}
-
+
信息仅用于陪诊服务,我们会严格保密
-
\ No newline at end of file
+
diff --git a/pages/health/profileedit.wxss b/pages/health/profileedit.wxss
index 650a55f..d33ac64 100644
--- a/pages/health/profileedit.wxss
+++ b/pages/health/profileedit.wxss
@@ -11,6 +11,32 @@ page {
padding: 40rpx 32rpx calc(180rpx + env(safe-area-inset-bottom));
}
+/* ===== 加载与失败状态 ===== */
+.page-state {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ padding: 120rpx 32rpx;
+}
+
+.page-state-text {
+ margin-top: 20rpx;
+ 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);
+}
+
/* ===== 通栏白块 =====
白面 + 上下各 2rpx 发丝线 + 中性阴影,圆角 0;
负向 margin 抵消容器 32rpx 内距后左右顶到屏幕两侧,
@@ -31,12 +57,22 @@ page {
/* 行高约 87rpx(28rpx×1.4 + 上下 24rpx),贴近 iOS 44pt 触控目标 */
.form-row {
display: flex;
+ flex-wrap: wrap;
align-items: center;
justify-content: space-between;
padding: 24rpx 32rpx;
border-bottom: 2rpx solid var(--line);
}
+.field-error {
+ width: 100%;
+ margin-top: 12rpx;
+ font-size: 24rpx;
+ line-height: 1.5;
+ color: #B4231A;
+ text-align: right;
+}
+
.form-row-last {
border-bottom: none;
}
diff --git a/pages/health/profilelist.js b/pages/health/profilelist.js
index 4d14296..5dffa2a 100644
--- a/pages/health/profilelist.js
+++ b/pages/health/profilelist.js
@@ -1,9 +1,12 @@
const API = require('../../utils/api.js')
+const { formatDate } = require('../../utils/date.js')
+const { maskIdNumber } = require('../../utils/privacy.js')
Page({
data: {
profiles: [],
- loading: false
+ loading: false,
+ loadError: ''
},
// 用 onShow 而不是 onLoad:从新增/编辑页返回后需要刷新列表
@@ -17,41 +20,34 @@ Page({
})
},
- // 拉取当前登录用户的就诊人列表
- loadProfiles() {
- this.setData({
- loading: true
- })
+ // 拉取当前登录用户的就诊人列表;空数组只在请求成功后展示为空态。
+ async loadProfiles() {
+ this.setData({ loading: true, loadError: '' })
- return API.healthProfile.getMyProfiles({
- page: 1,
- pageSize: 50
- })
- .then((res) => {
- if (res.code !== 0) {
- wx.showToast({
- title: res.msg || '加载失败',
- icon: 'none'
- })
- return
- }
- const list = (res.data && res.data.list) || []
- this.setData({
- profiles: list.map((item) => this.formatProfile(item))
- })
- })
- .catch((err) => {
- console.log('获取就诊人失败', err)
- wx.showToast({
- title: '网络请求失败',
- icon: 'none'
- })
- })
- .finally(() => {
- this.setData({
- loading: false
- })
+ try {
+ await getApp().waitForAuth()
+ const res = await API.healthProfile.getMyProfiles({ page: 1, pageSize: 50 })
+ if (res.code !== 0) throw new Error(res.msg || '就诊人加载失败')
+
+ const list = (res.data && res.data.list) || []
+ this.setData({
+ profiles: list.map((item) => this.formatProfile(item))
})
+ } catch (err) {
+ console.log('获取就诊人失败', err)
+ if (this.data.profiles.length === 0) {
+ this.setData({ loadError: err.message || '网络请求失败,请重试' })
+ } else {
+ // 已有成功数据时保留列表,刷新失败不打断查看和编辑。
+ wx.showToast({ title: '刷新失败,请重试', icon: 'none' })
+ }
+ } finally {
+ this.setData({ loading: false })
+ }
+ },
+
+ retryLoad() {
+ this.loadProfiles()
},
// 后端返回的是嵌套结构,这里拍平成卡片展示需要的字段
@@ -63,13 +59,13 @@ Page({
// 顺序:出生年月 → 联系电话 → 证件号(脱敏)
const metaList = []
if (profile.birth) {
- metaList.push(profile.birth)
+ metaList.push(formatDate(profile.birth, profile.birth))
}
if (profile.mobile) {
metaList.push(profile.mobile)
}
if (profile.idnumber) {
- metaList.push(this.maskIdNumber(profile.idnumber))
+ metaList.push(maskIdNumber(profile.idnumber))
}
return {
@@ -83,15 +79,6 @@ Page({
}
},
- // 证件号脱敏:仅保留前 4 位与后 4 位(只在有值时调用)
- maskIdNumber(idnumber) {
- const value = String(idnumber || '')
- if (value.length <= 8) {
- return value
- }
- return `${value.slice(0, 4)}********${value.slice(-4)}`
- },
-
onAdd() {
wx.navigateTo({
url: '/pages/health/profileedit'
diff --git a/pages/health/profilelist.wxml b/pages/health/profilelist.wxml
index 6b2f59c..6c24a9f 100644
--- a/pages/health/profilelist.wxml
+++ b/pages/health/profilelist.wxml
@@ -46,8 +46,14 @@
+
+
+ {{loadError}}
+ 重新加载
+
+
-
+
还没有就诊人,添加后下单即可一键带入
diff --git a/pages/health/profilelist.wxss b/pages/health/profilelist.wxss
index aaa596c..6c372fd 100644
--- a/pages/health/profilelist.wxss
+++ b/pages/health/profilelist.wxss
@@ -183,6 +183,31 @@ page {
white-space: nowrap;
}
+/* ===== 加载失败 ===== */
+.load-error {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ padding: 100rpx 32rpx;
+}
+
+.load-error-text {
+ font-size: 28rpx;
+ line-height: 1.6;
+ color: var(--muted);
+ text-align: center;
+}
+
+.retry-btn {
+ 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);
+}
+
/* ===== 空态 ===== */
.profile-empty {
display: flex;
diff --git a/pages/mine/profileedit.js b/pages/mine/profileedit.js
index f64c394..5a8090d 100644
--- a/pages/mine/profileedit.js
+++ b/pages/mine/profileedit.js
@@ -1,5 +1,7 @@
// pages/mine/profileedit.js
const API = require('../../utils/api.js')
+const { formatDate, toISOString } = require('../../utils/date.js')
+const { setUnsavedGuard } = require('../../utils/form.js')
Page({
data: {
@@ -18,13 +20,28 @@ Page({
},
onLoad() {
- const today = new Date()
- this.setData({
- today: `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}`
- })
+ this.unsavedGuardActive = false
+ this.initialEditSnapshot = ''
+ this.setData({ today: formatDate(new Date()) })
this.initEditData()
},
+ onUnload() {
+ if (this.unsavedGuardActive) setUnsavedGuard(false)
+ },
+
+ captureInitialForm() {
+ this.initialEditSnapshot = JSON.stringify(this.data.editData)
+ this.syncUnsavedGuard()
+ },
+
+ syncUnsavedGuard() {
+ const dirty = JSON.stringify(this.data.editData) !== this.initialEditSnapshot
+ if (dirty === this.unsavedGuardActive) return
+ this.unsavedGuardActive = dirty
+ setUnsavedGuard(dirty)
+ },
+
// 表单初值取自全局用户对象。页面栈上「我的」页的 onShow 读的也是它,
// 所以保存成功后必须回写 app.globalData.user,否则返回时看到的还是旧值
initEditData() {
@@ -33,52 +50,33 @@ Page({
const profile = user.profile || {}
const location = user.location || {}
- let birth = ''
- if (profile.birth) {
- const date = new Date(profile.birth)
- birth = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`
- }
-
this.setData({
editData: {
- // 空字符串表示"无真头像",模板据此渲染浅橙底 + 暖陶土 user 线标的默认头像
+ // 头像修改暂未开放,这里只展示当前头像或默认头像。
avatar: profile.avatar || '',
name: profile.name || '',
phone: profile.mobile || '',
sex: profile.sex || '',
- birth,
+ birth: formatDate(profile.birth),
province: location.province || '',
city: location.city || '',
district: location.district || ''
}
- })
- },
-
- onChooseAvatar() {
- wx.chooseMedia({
- count: 1,
- mediaType: ['image'],
- sourceType: ['album', 'camera'],
- success: (res) => {
- // 微信返回的是本地临时路径,没有文件上传接口可落库,
- // 故只在本次编辑中生效
- this.setData({
- 'editData.avatar': res.tempFiles[0].tempFilePath
- })
- }
- })
+ }, () => this.captureInitialForm())
},
onSelectSex(e) {
this.setData({
'editData.sex': e.currentTarget.dataset.sex
})
+ this.syncUnsavedGuard()
},
onBirthChange(e) {
this.setData({
'editData.birth': e.detail.value
})
+ this.syncUnsavedGuard()
},
onRegionChange(e) {
@@ -88,6 +86,7 @@ Page({
'editData.city': region[1] || '',
'editData.district': region[2] || ''
})
+ this.syncUnsavedGuard()
},
onFieldInput(e) {
@@ -95,6 +94,7 @@ Page({
this.setData({
[`editData.${field}`]: e.detail.value
})
+ this.syncUnsavedGuard()
},
onSave() {
@@ -117,7 +117,7 @@ Page({
profile: {
name: editData.name,
sex: editData.sex,
- birth: editData.birth ? new Date(editData.birth).toISOString() : null,
+ birth: toISOString(editData.birth),
mobile: editData.phone
},
location: {
@@ -135,6 +135,7 @@ Page({
// 整替会把本机 token 抹掉,之后所有接口都变成未登录。security 保留本地那份
const prev = app.globalData.user || {}
app.globalData.user = { ...prev, ...data.data.user, security: prev.security || {} }
+ this.captureInitialForm()
wx.showToast({ title: '保存成功', icon: 'success' })
// 返回上一页(「我的」),由它的 onShow 重新读取全局对象
wx.navigateBack()
diff --git a/pages/mine/profileedit.wxml b/pages/mine/profileedit.wxml
index e37b9bd..a55e162 100644
--- a/pages/mine/profileedit.wxml
+++ b/pages/mine/profileedit.wxml
@@ -7,19 +7,15 @@
行内沿用列表页/弹窗表单的语言:标签左走 --muted,值右走 --ink 加粗,
行间隔用 2rpx --line 发丝线 -->
-
-
+
+
头像
-
diff --git a/utils/date.js b/utils/date.js
new file mode 100644
index 0000000..427e785
--- /dev/null
+++ b/utils/date.js
@@ -0,0 +1,63 @@
+// 小程序各端对 new Date('YYYY-MM-DD') 的解析并不一致,纯日期统一按本地年月日构造。
+function parseDate(value) {
+ if (value instanceof Date) {
+ return Number.isNaN(value.getTime()) ? null : value
+ }
+ if (!value) return null
+
+ const text = String(value)
+ const dateOnly = /^(\d{4})-(\d{2})-(\d{2})$/.exec(text)
+ if (dateOnly) {
+ const year = Number(dateOnly[1])
+ const month = Number(dateOnly[2])
+ const day = Number(dateOnly[3])
+ const date = new Date(year, month - 1, day)
+ if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) {
+ return null
+ }
+ return date
+ }
+
+ const date = new Date(text)
+ return Number.isNaN(date.getTime()) ? null : date
+}
+
+function pad(value) {
+ return String(value).padStart(2, '0')
+}
+
+function formatDate(value, fallback = '') {
+ const date = parseDate(value)
+ if (!date) return fallback
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
+}
+
+function formatDateTime(value, fallback = '') {
+ const date = parseDate(value)
+ if (!date) return fallback
+ return `${formatDate(date)} ${pad(date.getHours())}:${pad(date.getMinutes())}`
+}
+
+function calcAge(value) {
+ const birth = parseDate(value)
+ if (!birth) return 0
+
+ const today = new Date()
+ let age = today.getFullYear() - birth.getFullYear()
+ const monthDelta = today.getMonth() - birth.getMonth()
+ if (monthDelta < 0 || (monthDelta === 0 && today.getDate() < birth.getDate())) age--
+ return age > 0 && age <= 120 ? age : 0
+}
+
+function toISOString(value) {
+ const date = parseDate(value)
+ return date ? date.toISOString() : null
+}
+
+module.exports = {
+ parseDate,
+ formatDate,
+ formatDateTime,
+ calcAge,
+ toISOString
+}
diff --git a/utils/form.js b/utils/form.js
new file mode 100644
index 0000000..68dbcee
--- /dev/null
+++ b/utils/form.js
@@ -0,0 +1,16 @@
+// 使用微信原生返回拦截,导航栏返回和手势返回都不会静默丢失未保存内容。
+function setUnsavedGuard(enabled) {
+ if (enabled && wx.canIUse('enableAlertBeforeUnload')) {
+ wx.enableAlertBeforeUnload({
+ message: '当前修改尚未保存,确定要离开吗?'
+ })
+ return
+ }
+ if (!enabled && wx.canIUse('disableAlertBeforeUnload')) {
+ wx.disableAlertBeforeUnload()
+ }
+}
+
+module.exports = {
+ setUnsavedGuard
+}
diff --git a/utils/order.js b/utils/order.js
new file mode 100644
index 0000000..acbc43f
--- /dev/null
+++ b/utils/order.js
@@ -0,0 +1,21 @@
+// 订单与支付状态的唯一前端映射,列表和详情只按展示需要读取不同扩展字段。
+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: '该订单已取消' }
+}
+
+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' }
+}
+
+module.exports = {
+ STATUS_MAP,
+ PAYMENT_STATUS_MAP
+}
diff --git a/utils/privacy.js b/utils/privacy.js
new file mode 100644
index 0000000..1dcbd34
--- /dev/null
+++ b/utils/privacy.js
@@ -0,0 +1,16 @@
+function maskIdNumber(value) {
+ const text = String(value || '').trim()
+ if (!text) return ''
+ if (text.length <= 8) return '********'
+ return `${text.slice(0, 4)}********${text.slice(-4)}`
+}
+
+function maskOrderId(value) {
+ const text = String(value || '').trim()
+ return text ? `****${text.slice(-8).toUpperCase()}` : '--'
+}
+
+module.exports = {
+ maskIdNumber,
+ maskOrderId
+}