Files
wxapp_escort/pages/health/profilelist.js
T
2026-10-06 21:19:20 +08:00

136 lines
3.2 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 || {}
return {
_id: item._id,
name: profile.name || '未命名',
sexText: profile.sex === 'male' ? '男' : (profile.sex === 'female' ? '女' : ''),
birth: profile.birth || '',
mobile: profile.mobile || '',
idnumberText: this.maskIdNumber(profile.idnumber),
remark: health.remark || ''
}
},
// 证件号脱敏:仅保留前 4 位与后 4 位
maskIdNumber(idnumber) {
const value = String(idnumber || '')
if (!value) {
return '未填写'
}
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'
})
})
}
})
}
})