Files
wxapp_escort/pages/health/profilelist.js
T
2026-10-18 22:14:49 +08:00

146 lines
3.6 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')
Page({
data: {
profiles: [],
loading: false
},
// 用 onShow 而不是 onLoad:从新增/编辑页返回后需要刷新列表
onShow() {
this.loadProfiles()
},
onPullDownRefresh() {
this.loadProfiles().finally(() => {
wx.stopPullDownRefresh()
})
},
// 拉取当前登录用户的就诊人列表
loadProfiles() {
this.setData({
loading: true
})
return API.healthProfile.getMyProfiles({
page: 1,
pageSize: 50
})
.then((res) => {
if (res.code !== 0) {
wx.showToast({
title: res.msg || '加载失败',
icon: 'none'
})
return
}
const list = (res.data && res.data.list) || []
this.setData({
profiles: list.map((item) => this.formatProfile(item))
})
})
.catch((err) => {
console.log('获取就诊人失败', err)
wx.showToast({
title: '网络请求失败',
icon: 'none'
})
})
.finally(() => {
this.setData({
loading: false
})
})
},
// 后端返回的是嵌套结构,这里拍平成卡片展示需要的字段
formatProfile(item) {
const profile = item.profile || {}
const health = item.health || {}
// 元信息行只收非空项(空值连同分隔线一起消失,不留「未填写」噪音),
// 顺序:出生年月 → 联系电话 → 证件号(脱敏)
const metaList = []
if (profile.birth) {
metaList.push(profile.birth)
}
if (profile.mobile) {
metaList.push(profile.mobile)
}
if (profile.idnumber) {
metaList.push(this.maskIdNumber(profile.idnumber))
}
return {
_id: item._id,
// 首字牌取姓氏首字;无姓名时 wxml 退到 user 图标
initial: (profile.name || '').slice(0, 1),
name: profile.name || '未命名',
sexText: profile.sex === 'male' ? '男' : (profile.sex === 'female' ? '女' : ''),
metaList,
remark: health.remark || ''
}
},
// 证件号脱敏:仅保留前 4 位与后 4 位(只在有值时调用)
maskIdNumber(idnumber) {
const value = String(idnumber || '')
if (value.length <= 8) {
return value
}
return `${value.slice(0, 4)}********${value.slice(-4)}`
},
onAdd() {
wx.navigateTo({
url: '/pages/health/profileedit'
})
},
onEdit(e) {
const id = e.currentTarget.dataset.id
wx.navigateTo({
url: `/pages/health/profileedit?id=${id}`
})
},
onDelete(e) {
const id = e.currentTarget.dataset.id
wx.showModal({
title: '删除确认',
content: '删除后该就诊人信息将无法恢复,确定删除吗?',
// confirmColor 是属性值,读不到 CSS 变量,取值须与令牌同步(DESIGN.md §5.1)
confirmColor: '#B8520A',
success: (res) => {
if (!res.confirm) {
return
}
API.healthProfile.deleteMyProfile(id)
.then((result) => {
if (result.code !== 0) {
wx.showToast({
title: result.msg || '删除失败',
icon: 'none'
})
return
}
wx.showToast({
title: '已删除',
icon: 'success'
})
this.loadProfiles()
})
.catch((err) => {
console.log('删除就诊人失败', err)
wx.showToast({
title: '网络请求失败',
icon: 'none'
})
})
}
})
}
})