Files
wxapp_escort/pages/home/index.js
T

199 lines
5.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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]
// 计入"待服务订单"的订单状态:待确认 / 已确认 / 进行中
const PENDING_ORDER_STATUS = ['pending', 'confirmed', 'in_progress']
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()
// 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) {
return
}
const records = (res.data && res.data.records) || []
const pendingCount = records.filter((record) => PENDING_ORDER_STATUS.indexOf(record.status) > -1).length
this.setData({
pendingCount
})
})
.catch((err) => {
console.log('获取待服务订单失败', err)
})
},
// 页脚三个 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: '暖橙陪诊',
}
}
});