diff --git a/app.js b/app.js
index 0eed6d7..aa3597a 100644
--- a/app.js
+++ b/app.js
@@ -15,34 +15,54 @@ App({
}
this.globalData.appId = appId
- this.globalData.servicesReady = new Promise((resolve) => {
- API.resource.getServices().then((data) => {
- this.globalData.services = data.data.services
- resolve(data.data.services)
- }).catch((err) => {
- console.error('获取服务列表失败', err)
- resolve([])
- })
- })
-
- this.globalData.agreementReady = new Promise((resolve) => {
- API.resource.getAgreement().then((data) => {
- this.globalData.agreement = data.data.agreement
- resolve(data.data.agreement)
- }).catch((err) => {
- console.error('获取服务协议失败', err)
- resolve(null)
- })
- })
+ this.loadServices()
+ this.loadAgreement()
this.checkUpdate();
},
onShow() {
- this.silentSignin()
+ this.globalData.authReady = this.silentSignin()
this.initChatSocket()
},
+ // 启动期资源统一走 Promise;失败后清空 Promise,页面重试可重新发起请求。
+ loadServices() {
+ if (this.globalData.servicesReady) return this.globalData.servicesReady
+ this.globalData.servicesReady = API.resource.getServices()
+ .then((res) => {
+ if (res.code !== 0 || !Array.isArray(res.data?.services)) throw new Error(res.msg || '服务列表加载失败')
+ this.globalData.services = res.data.services
+ return this.globalData.services
+ })
+ .catch((err) => {
+ console.error('获取服务列表失败', err)
+ this.globalData.servicesReady = null
+ return null
+ })
+ return this.globalData.servicesReady
+ },
+
+ loadAgreement() {
+ if (this.globalData.agreementReady) return this.globalData.agreementReady
+ this.globalData.agreementReady = API.resource.getAgreement()
+ .then((res) => {
+ if (res.code !== 0 || !res.data?.agreement) throw new Error(res.msg || '服务协议加载失败')
+ this.globalData.agreement = res.data.agreement
+ return this.globalData.agreement
+ })
+ .catch((err) => {
+ console.error('获取服务协议失败', err)
+ this.globalData.agreementReady = null
+ return null
+ })
+ return this.globalData.agreementReady
+ },
+
+ waitForAuth() {
+ return this.globalData.authReady || this.silentSignin()
+ },
+
// 静默重登:app.onShow 与 request 层的 401 兜底共用这一个入口
// (wxsignin 只凭 code 换到 openid 就能签发 token,见 api/user/handler/users.js)。
//
@@ -174,6 +194,9 @@ App({
user: null,
chatSocket: null,
services: [],
+ servicesReady: null,
agreement: null,
+ agreementReady: null,
+ authReady: null,
}
})
\ No newline at end of file
diff --git a/pages/escort/agreement.js b/pages/escort/agreement.js
index db83ede..596d393 100644
--- a/pages/escort/agreement.js
+++ b/pages/escort/agreement.js
@@ -1,5 +1,3 @@
-const app = getApp()
-
Page({
/**
@@ -7,64 +5,30 @@ Page({
*/
data: {
agreement: null,
- loading: true
+ loading: true,
+ error: false
},
/**
* 生命周期函数--监听页面加载
*/
- onLoad(options) {
- const agreement = app.globalData.agreement
- if (agreement) {
+ onLoad() {
+ this.loadAgreement()
+ },
+
+ loadAgreement() {
+ this.setData({ loading: true, error: false })
+ getApp().loadAgreement().then((agreement) => {
this.setData({
- agreement: agreement,
- loading: false
+ agreement: agreement || null,
+ loading: false,
+ error: !agreement
})
- } else {
- this.setData({ loading: false })
- }
+ })
},
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
-
+ retry() {
+ this.loadAgreement()
},
/**
diff --git a/pages/escort/agreement.wxml b/pages/escort/agreement.wxml
index 24db2bf..552d93b 100644
--- a/pages/escort/agreement.wxml
+++ b/pages/escort/agreement.wxml
@@ -1,7 +1,13 @@
- 加载中...
-
+
+ 加载中...
+
+
+ 协议加载失败,请重试
+
+
+
-
- {{record.paymentHint}}
+
+
+ {{record.paymentHint}}
+
+
-
+
+
+
+
+ 收货信息
+
+
+ {{record.shippingAddress.recipientName}} {{record.shippingAddress.mobile}}
+ {{record.shippingAddress.address}}
+
+
+
+
订单信息
- 订单编号 {{record._id || '--'}}
+ 订单编号 {{record.displayId}}
创建于 {{record.createTime || '--'}}
更新于 {{record.updateTime || '--'}}
+
@@ -187,9 +205,15 @@
-
+
+
+
+
+ {{loadError}}
+
+
+
+
删除订单
- 确认完成
{{editHospital.scheduleDate || '请选择日期'}}
- 开始时间
+ 预约时间
+ {{timeOptions[editHospital.sessionIndex] || '请选择服务班次'}}
+
+
{{editHospital.startTime || '请选择时间'}}
-
- 结束时间
-
- {{editHospital.endTime || '请选择时间'}}
-
-
-
+
-
-
+
+
+
+ {{loadError}}
+
+
+
+
+
{{statusFilter ? '暂无进行中的预约' : '暂无陪诊记录'}}
{{statusFilter ? '已结束的预约可在「全部预约」里查看' : '您还没有预约陪诊服务'}}
diff --git a/pages/escort/recordlist.wxss b/pages/escort/recordlist.wxss
index 52eb53c..67a4322 100644
--- a/pages/escort/recordlist.wxss
+++ b/pages/escort/recordlist.wxss
@@ -217,6 +217,10 @@ page {
align-items: center;
}
+.record-chevron {
+ margin-left: 12rpx;
+}
+
/* 支付状态胶囊:比订单状态轻一档(无底色的中性档只留字与描边) */
.pay-chip {
padding: 4rpx 14rpx;
@@ -228,7 +232,38 @@ page {
white-space: nowrap;
}
-/* ===== 空 / 加载 / 到底 ===== */
+/* ===== 空 / 错误 / 加载 / 到底 ===== */
+.error-state {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ padding: 140rpx 32rpx 0;
+}
+
+.error-text {
+ margin-top: 24rpx;
+ font-size: 28rpx;
+ color: var(--muted);
+ line-height: 1.6;
+ text-align: center;
+}
+
+.retry-btn {
+ margin: 28rpx 0 0;
+ padding: 12rpx 36rpx;
+ border: 2rpx solid var(--brand-strong);
+ border-radius: 999rpx;
+ background: transparent;
+ color: var(--brand-strong);
+ font-size: 28rpx;
+ font-weight: 500;
+ line-height: 1.5;
+}
+
+.retry-btn::after {
+ border: none;
+}
+
.empty-state {
display: flex;
flex-direction: column;
diff --git a/pages/home/index.js b/pages/home/index.js
index 461ad1f..0058c69 100644
--- a/pages/home/index.js
+++ b/pages/home/index.js
@@ -19,9 +19,6 @@ const SERVICE_UI = {
// 全天 / 半天是核心营收项,靠排在前两位形成隐性推荐位
const SERVICE_ORDER = [1, 2, 7, 3, 4, 5, 8, 6]
-// 计入"待服务订单"的订单状态:待确认 / 已确认 / 进行中
-const PENDING_ORDER_STATUS = ['pending', 'confirmed', 'in_progress']
-
Page({
data: {
escortServices: [], // 陪诊服务(来自后端,按 SERVICE_ORDER 展示)
@@ -72,67 +69,81 @@ Page({
// 读取后端服务列表,拼装成首页宫格所需的展示数据
loadServices() {
const app = getApp()
- // servicesReady 由 app.onLaunch 创建,兜底避免极端情况下取不到
- const ready = app.globalData.servicesReady || Promise.resolve(app.globalData.services || [])
-
- ready.then((services) => {
- const serviceMap = {}
- ;(services || []).forEach((service) => {
- serviceMap[service.id] = service
- })
-
- // 按展示顺序拼装。首页宫格不取 price / subtitle——
- // 定价与服务介绍分别留到指南页、详情页展示
- const escortServices = SERVICE_ORDER
- .filter((id) => serviceMap[id])
- .map((id) => {
- const service = serviceMap[id]
- const ui = SERVICE_UI[id] || {}
- return {
- id,
- name: ui.name || service.title,
- // 图标类名:与 index.wxss 中 .assist-icon-{id} 对应
- iconClass: 'assist-icon-' + id
- }
- })
-
- this.setData({
- escortServices
- })
- })
- },
-
- // 统计待服务订单:仅在登录信息就绪后请求,未就绪时稍后重试一次
- refreshPendingCount(retry) {
- const app = getApp()
- const user = app.globalData.user
-
- if (!user || !user._id) {
- // 首次进入时 App 的登录请求可能还没返回,延迟重试一次即可
- if (!retry) {
- setTimeout(() => this.refreshPendingCount(1), 1500)
- }
- return
- }
-
- API.escort.getMyRecords({
- userId: user._id,
- page: 1,
- pageSize: 50
- })
- .then((res) => {
- if (res.code !== 0) {
+ app.loadServices()
+ .then((services) => {
+ if (!services) {
+ this.setData({ escortServices: [] })
+ console.error('首页服务列表加载失败')
return
}
- const records = (res.data && res.data.records) || []
- const pendingCount = records.filter((record) => PENDING_ORDER_STATUS.indexOf(record.status) > -1).length
- this.setData({
- pendingCount
+
+ const serviceMap = {}
+ services.forEach((service) => {
+ serviceMap[service.id] = service
})
+
+ // 按展示顺序拼装。首页宫格不取 price / subtitle——
+ // 定价与服务介绍分别留到指南页、详情页展示
+ const escortServices = SERVICE_ORDER
+ .filter((id) => serviceMap[id])
+ .map((id) => {
+ const service = serviceMap[id]
+ const ui = SERVICE_UI[id] || {}
+ return {
+ id,
+ name: ui.name || service.title,
+ // 图标类名:与 index.wxss 中 .assist-icon-{id} 对应
+ iconClass: 'assist-icon-' + id
+ }
+ })
+
+ this.setData({
+ escortServices
+ })
+ })
+ .catch((err) => {
+ this.setData({ escortServices: [] })
+ console.error('首页服务列表加载失败', err)
+ })
+ },
+
+ // 统计待服务订单:等待鉴权完成,登录后由后端按状态汇总
+ refreshPendingCount() {
+ if (this.pendingRequest) return this.pendingRequest
+
+ const app = getApp()
+ this.pendingRequest = app.waitForAuth()
+ .then(() => {
+ const user = app.globalData.user
+ if (!user || !user._id) {
+ this.setData({ pendingCount: 0 })
+ return null
+ }
+
+ return API.escort.getMyRecords({
+ page: 1,
+ pageSize: 1,
+ status: 'pending,confirmed,in_progress'
+ })
+ })
+ .then((res) => {
+ if (!res || res.code !== 0) return
+
+ const data = res.data || {}
+ const counts = data.counts || {}
+ const pendingCount = counts.ongoing === undefined || counts.ongoing === null
+ ? (data.total || 0)
+ : counts.ongoing
+ this.setData({ pendingCount })
})
.catch((err) => {
console.log('获取待服务订单失败', err)
})
+ .finally(() => {
+ this.pendingRequest = null
+ })
+
+ return this.pendingRequest
},
// 页脚三个 B 端入口:都进「合作与入驻」页,用 section 定位到各自的卡片
diff --git a/pages/mine/contact.js b/pages/mine/contact.js
index 8af68f3..fd1c21c 100644
--- a/pages/mine/contact.js
+++ b/pages/mine/contact.js
@@ -1,6 +1,7 @@
// pages/mine/contact.js
Page({
data: {
+ orderContext: '',
// 联系方式配置:action 决定点击行为,call=拨号 / copy=复制 / 空=不可点
contactItems: [{
label: '客服热线',
@@ -29,6 +30,17 @@ Page({
]
},
+ onLoad(options = {}) {
+ const orderNo = String(options.orderNo || '').trim()
+ const orderId = String(options.orderId || '').trim()
+ const displayNo = (orderNo || orderId.slice(-8)).toUpperCase()
+ if (!displayNo) return
+
+ this.setData({
+ orderContext: `咨询订单尾号 ${displayNo},联系客服时请提供该编号`
+ })
+ },
+
onItemTap(e) {
const {
action,
diff --git a/pages/mine/contact.wxml b/pages/mine/contact.wxml
index ff9ee9f..e61b95e 100644
--- a/pages/mine/contact.wxml
+++ b/pages/mine/contact.wxml
@@ -9,6 +9,10 @@
+
+ {{orderContext}}
+
+
this.loadUserInfo())
// 同步自定义 tabBar 选中态(我的为第 2 项)
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({
@@ -96,12 +84,7 @@ Page({
'userInfo.phone': profile.mobile || '',
// 身份行副行(微信那行是微信号):本应用没有账号体系,
// 等价标识是手机号,脱敏成 138****1234 后再上屏
- 'userInfo.account': this.maskMobile(profile.mobile || ''),
- 'userInfo.sex': profile.sex || '',
- 'userInfo.birth': profile.birth ? this.formatDate(profile.birth) : '',
- 'userInfo.email': profile.email || '',
- 'userInfo.idnumber': profile.idnumber || '',
- 'userInfo.ssn': profile.ssn || ''
+ 'userInfo.account': this.maskMobile(profile.mobile || '')
})
} else {
// 未登录(含刚退出登录):身份行收敛回默认态。
@@ -124,17 +107,8 @@ Page({
return `${digits.slice(0, 3)}****${digits.slice(7)}`
},
- formatDate(date) {
- if (!date) return ''
- const d = new Date(date)
- 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}`
- },
-
// 顶部身份行整行可点,但未登录时不该跳进"填完才被拦"的资料页
- // (个人信息与邮寄地址改真页面后系统返回键归页面栈管,
+ // (个人信息改真页面后系统返回键归页面栈管,
// 不再像原来的浮层那样被系统返回键直接退出小程序)
onTapProfile() {
if (!this.data.userInfo.isLoggedIn) return
@@ -143,12 +117,6 @@ Page({
})
},
- onTapAddress() {
- wx.navigateTo({
- url: '/pages/mine/addressedit'
- })
- },
-
onTapHealth() {
wx.navigateTo({
url: '/pages/health/profilelist'