基本重构完成
This commit is contained in:
@@ -1,5 +1,34 @@
|
||||
const API = require('../../utils/api.js')
|
||||
|
||||
// 由 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
|
||||
}
|
||||
|
||||
// 陪诊师详情:数据来自后端公开接口 /health/attendant/:id
|
||||
// 与列表页是同一份白名单数据(不含手机号 / 身份证号 / 证书编号原文),
|
||||
// 差别在于详情页按 GB/T 47801—2026 4.2.1.5 把公示项补全:
|
||||
@@ -55,6 +84,8 @@ Page({
|
||||
initial: name.slice(0, 1),
|
||||
// 后端 sex 为空串表示未登记,模板据此隐藏该行
|
||||
sexText: item.sex === 'male' ? '男' : item.sex === 'female' ? '女' : '',
|
||||
// 周岁由本页现算,未登记生日时为 0,模板据 0 隐藏该行
|
||||
age: calcAge(item.birthday),
|
||||
workYears: item.workYears || 0,
|
||||
orderCount: item.orderCount || 0,
|
||||
qualificationVerified: !!item.qualificationVerified,
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
</view>
|
||||
|
||||
<!-- 服务信息:有哪项展示哪项,整行不留空标签 -->
|
||||
<view class="section" wx:if="{{ attendant.sexText || areaText || langText }}">
|
||||
<view class="section" wx:if="{{ attendant.sexText || attendant.age > 0 || areaText || langText }}">
|
||||
<view class="section-head">
|
||||
<view class="section-bar"></view>
|
||||
<text class="section-title">服务信息</text>
|
||||
@@ -68,6 +68,10 @@
|
||||
<text class="info-label">性别</text>
|
||||
<text class="info-value">{{ attendant.sexText }}</text>
|
||||
</view>
|
||||
<view class="info-row" wx:if="{{ attendant.age > 0 }}">
|
||||
<text class="info-label">年龄</text>
|
||||
<text class="info-value">{{ attendant.age }} 岁</text>
|
||||
</view>
|
||||
<view class="info-row" wx:if="{{ areaText }}">
|
||||
<text class="info-label">服务区域</text>
|
||||
<text class="info-value">{{ areaText }}</text>
|
||||
|
||||
@@ -1,8 +1,38 @@
|
||||
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,
|
||||
@@ -36,6 +66,8 @@ Page({
|
||||
// 头像兜底用的首字:姓名已脱敏为「姓 + 陪诊师」,取第一个字即可
|
||||
initial: (item.name || '').slice(0, 1),
|
||||
workYears: item.workYears || 0,
|
||||
// 周岁由本页现算,未登记生日时为 0,模板据 0 隐藏该段
|
||||
age: calcAge(item.birthday),
|
||||
orderCount: item.orderCount || 0,
|
||||
qualificationVerified: !!item.qualificationVerified,
|
||||
// 擅长场景最多展示 3 个,避免长尾把卡片撑高;完整列表在详情页
|
||||
|
||||
@@ -48,6 +48,11 @@
|
||||
</view>
|
||||
<view class="staff-meta">
|
||||
<text class="staff-meta-text">从业 {{ item.workYears }} 年</text>
|
||||
<!-- 年龄未登记时(后端给 0)整段连同分隔线一起隐藏,不留孤立竖线 -->
|
||||
<block wx:if="{{ item.age > 0 }}">
|
||||
<view class="meta-sep"></view>
|
||||
<text class="staff-meta-text">{{ item.age }} 岁</text>
|
||||
</block>
|
||||
<view class="meta-sep"></view>
|
||||
<text class="staff-meta-text">已服务 {{ item.orderCount }} 次</text>
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user