Files
wxapp_escort/pages/attendant/attendantlist.js
T
2026-10-07 14:55:06 +08:00

107 lines
3.5 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')
// 陪诊师公示列表:数据来自后端公开接口 /health/attendant
// 该接口已做脱敏(不含手机号 / 身份证号 / 证书编号原文,生日只下发到日),
// 前端不做二次裁剪,只把后端字段整形为展示所需结构(周岁由生日现算)
// 由 YYYY-MM-DD 生日换算周岁。
// 后端只下发到「日」、不含时分秒——公示场景要的是"多大",不是哪一天生的。
// 生日缺失 / 非法 / 算出不合常理(负数或 >120),一律返回 0,模板按 0 隐藏该项
function calcAge(birthday) {
if (!birthday) {
return 0
}
// 把 '-' 换成 '/' 再解析:小程序 iOS 对 'YYYY-MM-DD HH:mm:ss' 这类格式
// 会得到 Invalid Date,'/' 分隔是各端都稳的写法
const birth = new Date(String(birthday).replace(/-/g, '/'))
if (Number.isNaN(birth.getTime())) {
return 0
}
const today = new Date()
let age = today.getFullYear() - birth.getFullYear()
// 今年生日还没到,减一岁
const monthDiff = today.getMonth() - birth.getMonth()
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birth.getDate())) {
age -= 1
}
// 上限 120 是给运营手抖填错年份兜底,否则页面上会出现"年龄 226 岁"
if (!Number.isFinite(age) || age < 0 || age > 120) {
return 0
}
return age
}
Page({
data: {
loading: true,
attendants: []
},
onLoad() {
this.loadAttendants()
},
loadAttendants() {
API.escort.getAttendants()
.then((res) => {
if (res.code !== 0) {
this.setData({ loading: false })
return
}
const list = (res.data && res.data.attendants) || []
this.setData({
loading: false,
attendants: list.map((item) => {
const specialties = item.specialties || []
const serviceAreas = item.serviceAreas || []
const languages = item.languages || []
return {
id: item.id,
name: item.name,
avatar: item.avatar,
// 头像兜底用的首字:姓名已脱敏为「姓 + 陪诊师」,取第一个字即可
initial: (item.name || '').slice(0, 1),
workYears: item.workYears || 0,
// 周岁由本页现算,未登记生日时为 0,模板据 0 隐藏该段
age: calcAge(item.birthday),
orderCount: item.orderCount || 0,
qualificationVerified: !!item.qualificationVerified,
// 擅长场景最多展示 3 个,避免长尾把卡片撑高;完整列表在详情页
specialtyTags: specialties.slice(0, 3),
// 数组在 WXML 里不能直接拼展示,这里先转成文本
areaText: serviceAreas.join(' / '),
langText: languages.join(' / ')
}
})
})
})
.catch((err) => {
console.log('获取陪诊师列表失败', err)
this.setData({ loading: false })
})
},
// 整卡可点进详情。卡片右侧补 chevron 做点击暗示——
// 项目约束不允许"无暗示的整卡可点"
goToDetail(e) {
const id = e.currentTarget.dataset.id
if (!id) {
return
}
wx.navigateTo({
url: `/pages/attendant/attendantdetail?id=${id}`
})
},
onShareAppMessage() {
return {
title: '暖橙陪诊 · 陪诊师团队',
path: '/pages/attendant/attendantlist'
}
}
})