Files
wxapp_escort/pages/home/index.js
T
2026-10-02 10:28:44 +08:00

191 lines
5.0 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 项)
const SERVICE_ORDER = [1, 2, 3, 4, 5, 6, 7, 8]
// 计入"待服务订单"的订单状态:待确认 / 已确认 / 进行中
const PENDING_ORDER_STATUS = ['pending', 'confirmed', 'in_progress']
// 人工客服电话
const SERVICE_PHONE = '18618162956'
Page({
data: {
escortServices: [], // 陪诊服务(来自后端,最多 8 项)
pendingCount: 0, // 待服务订单数,大于 0 时首页顶部展示状态条
quickEntries: [{
id: 'records',
name: '预约记录',
desc: '查看预约进度与历史',
// 日历:与「健康档案」的人形图标形成明显形态差异(原先两个都是"文档+勾",缩小后难分辨)
icon: 'calendar-1',
url: '/pages/escort/recordlist'
},
{
id: 'health',
name: '健康档案',
desc: '管理家人就诊信息',
icon: 'user-checked',
url: '/pages/health/profilelist'
}
]
},
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
})
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)
})
},
goToAiChat() {
wx.switchTab({
url: '/pages/ai/aichat'
});
},
// 页脚 B 端合作入口仍直接转服务电话
goToContact() {
wx.makePhoneCall({
phoneNumber: SERVICE_PHONE
});
},
// 「联系我们」卡片:进入独立联系页,页内再提供拨号/复制/工作时间
goToContactPage() {
wx.navigateTo({
url: '/pages/mine/contact'
});
},
// Hero 主按钮:先引导新用户了解服务,服务列表入口在指南页底部
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: '暖橙陪诊',
}
}
});