修改界面中,临时提交

This commit is contained in:
lik
2026-10-02 10:28:44 +08:00
parent 089e0eb081
commit 55a9c7e3e8
41 changed files with 2458 additions and 451 deletions
+134
View File
@@ -0,0 +1,134 @@
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: '#D4A853',
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'
})
})
}
})
}
})