210 lines
5.9 KiB
JavaScript
210 lines
5.9 KiB
JavaScript
const API = require('../../utils/api.js')
|
||
|
||
// 陪诊服务的展示配置:价格等以后端返回为准,这里只覆盖展示名。
|
||
// 图标不走数据,而是按 id 映射到 index.wxss 里内嵌的细线 SVG(.assist-icon-1 ~ .assist-icon-8)
|
||
// key 为后端 services 的 id,顺序即首页宫格的展示顺序
|
||
const SERVICE_UI = {
|
||
1: { name: '全天陪诊' },
|
||
2: { name: '半天陪诊' },
|
||
3: { name: '代问诊' },
|
||
4: { name: '检查预约' },
|
||
5: { name: '出入院代办' },
|
||
6: { name: '跑腿服务' },
|
||
7: { name: '夜间陪诊' },
|
||
8: { name: '取药快递' }
|
||
}
|
||
|
||
// 陪诊服务的展示顺序(共 8 项,4 列 × 2 行正好排满)。
|
||
// 陪同就医三项(全天 / 半天 / 夜间)连排在前,与列表页的分组顺序一致;
|
||
// 全天 / 半天是核心营收项,靠排在前两位形成隐性推荐位
|
||
const SERVICE_ORDER = [1, 2, 7, 3, 4, 5, 8, 6]
|
||
|
||
Page({
|
||
data: {
|
||
escortServices: [], // 陪诊服务(来自后端,按 SERVICE_ORDER 展示)
|
||
pendingCount: 0, // 待服务订单数,大于 0 时首页顶部展示状态条
|
||
quickEntries: [{
|
||
id: 'records',
|
||
name: '预约记录',
|
||
// 横排布局后文字区变窄,右侧又补了 chevron(文字区约 179rpx),desc 控制在 7 字内避免折行
|
||
desc: '查看进度与历史',
|
||
// 日历:与「就诊人」的人形图标形成明显形态差异(原先两个都是"文档+勾",缩小后难分辨)
|
||
icon: 'calendar-1',
|
||
url: '/pages/escort/recordlist'
|
||
},
|
||
{
|
||
id: 'health',
|
||
name: '就诊人',
|
||
// 原「管理家人就诊信息」8 字 + 右侧箭头会折行,收到 6 字
|
||
desc: '管理家人信息',
|
||
icon: 'user-checked',
|
||
url: '/pages/health/profilelist'
|
||
},
|
||
{
|
||
id: 'contact',
|
||
name: '联系我们',
|
||
desc: '人工客服',
|
||
icon: 'call',
|
||
url: '/pages/mine/contact',
|
||
// 第三张卡通栏排布(两列网格的 2+1),避免右下角孤零零半张卡
|
||
full: true
|
||
}
|
||
]
|
||
},
|
||
|
||
onLoad() {
|
||
this.loadServices()
|
||
},
|
||
|
||
onShow() {
|
||
this.refreshPendingCount()
|
||
// 同步自定义 tabBar 选中态(首页为第 0 项)
|
||
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
|
||
this.getTabBar().setData({
|
||
selected: 0
|
||
})
|
||
}
|
||
},
|
||
|
||
// 读取后端服务列表,拼装成首页宫格所需的展示数据
|
||
loadServices() {
|
||
const app = getApp()
|
||
app.loadServices()
|
||
.then((services) => {
|
||
if (!services) {
|
||
this.setData({ escortServices: [] })
|
||
console.error('首页服务列表加载失败')
|
||
return
|
||
}
|
||
|
||
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 定位到各自的卡片
|
||
goToBusiness(e) {
|
||
const section = e.currentTarget.dataset.section || ''
|
||
wx.navigateTo({
|
||
url: `/pages/mine/business?section=${section}`
|
||
});
|
||
},
|
||
|
||
// Hero 主按钮:直达服务列表,缩短「了解 → 下单」路径。
|
||
// 陪诊指南的入口由服务区块的介绍卡承担
|
||
goToBooking() {
|
||
wx.navigateTo({
|
||
url: '/pages/escort/itemlist'
|
||
});
|
||
},
|
||
|
||
// 次级文字链:新用户想先了解流程时看指南
|
||
goToGuide() {
|
||
wx.navigateTo({
|
||
url: '/pages/escort/guide'
|
||
});
|
||
},
|
||
|
||
// 点击陪诊服务,直达服务详情下单
|
||
goToServiceDetail(e) {
|
||
const id = e.currentTarget.dataset.id
|
||
wx.navigateTo({
|
||
url: `/pages/escort/itemdetail?id=${id}`
|
||
})
|
||
},
|
||
|
||
// 常用功能:预约记录、就诊人
|
||
onQuickEntryTap(e) {
|
||
const entry = e.currentTarget.dataset.item
|
||
if (!entry || !entry.url) {
|
||
return
|
||
}
|
||
wx.navigateTo({
|
||
url: entry.url
|
||
})
|
||
},
|
||
|
||
goToRecords() {
|
||
wx.navigateTo({
|
||
url: '/pages/escort/recordlist'
|
||
})
|
||
},
|
||
|
||
onShareAppMessage() {
|
||
return {
|
||
title: '暖橙陪诊', // 转发标题
|
||
path: '/pages/home/index',
|
||
}
|
||
},
|
||
|
||
onShareTimeline: function () {
|
||
return {
|
||
title: '暖橙陪诊',
|
||
}
|
||
}
|
||
});
|