Files
wxapp_escort/pages/health/profilelist.js
T
liktrae-solo-agentKimi-K3.1-Pro noreply@moonshot.cn
df96cb3b07 清理无效页面与前端发布风险
Co-Authored-By: Kimi-K3.1-Pro noreply@moonshot.cn
2026-10-24 19:07:02 +08:00

133 lines
3.7 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')
const { formatDate } = require('../../utils/date.js')
const { maskIdNumber } = require('../../utils/privacy.js')
Page({
data: {
profiles: [],
loading: false,
loadError: ''
},
// 用 onShow 而不是 onLoad:从新增/编辑页返回后需要刷新列表
onShow() {
this.loadProfiles()
},
onPullDownRefresh() {
this.loadProfiles().finally(() => {
wx.stopPullDownRefresh()
})
},
// 拉取当前登录用户的就诊人列表;空数组只在请求成功后展示为空态。
async loadProfiles() {
this.setData({ loading: true, loadError: '' })
try {
await getApp().waitForAuth()
const res = await API.healthProfile.getMyProfiles({ page: 1, pageSize: 50 })
if (res.code !== 0) throw new Error(res.msg || '就诊人加载失败')
const list = (res.data && res.data.list) || []
this.setData({
profiles: list.map((item) => this.formatProfile(item))
})
} catch (err) {
console.log('获取就诊人失败', err)
if (this.data.profiles.length === 0) {
this.setData({ loadError: err.message || '网络请求失败,请重试' })
} else {
// 已有成功数据时保留列表,刷新失败不打断查看和编辑。
wx.showToast({ title: '刷新失败,请重试', icon: 'none' })
}
} finally {
this.setData({ loading: false })
}
},
retryLoad() {
this.loadProfiles()
},
// 后端返回的是嵌套结构,这里拍平成卡片展示需要的字段
formatProfile(item) {
const profile = item.profile || {}
const health = item.health || {}
// 元信息行只收非空项(空值连同分隔线一起消失,不留「未填写」噪音),
// 顺序:出生年月 → 联系电话 → 证件号(脱敏)
const metaList = []
if (profile.birth) {
metaList.push({ id: 'birth', text: formatDate(profile.birth, profile.birth) })
}
if (profile.mobile) {
metaList.push({ id: 'mobile', text: profile.mobile })
}
if (profile.idnumber) {
metaList.push({ id: 'idnumber', text: 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 || ''
}
},
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'
})
})
}
})
}
})