82 lines
2.3 KiB
JavaScript
82 lines
2.3 KiB
JavaScript
// pages/healthprofile/index.js
|
|
const API = require('../../utils/api.js')
|
|
const { calcAge } = require('../../utils/format.js')
|
|
|
|
Page({
|
|
data: {
|
|
totalCount: 0,
|
|
profileList: [],
|
|
quickMenus: [
|
|
{ icon: 'view-list', title: '全部档案' },
|
|
{ icon: 'add', title: '新建档案' },
|
|
{ icon: 'search', title: '患者查询' },
|
|
{ icon: 'time', title: '就诊记录' }
|
|
]
|
|
},
|
|
|
|
onLoad() {
|
|
this.loadData()
|
|
},
|
|
|
|
onShow() {
|
|
this.loadData()
|
|
},
|
|
|
|
/**
|
|
* 加载档案总数与最近更新的档案列表(按修改时间排序,最多20条)
|
|
*/
|
|
loadData() {
|
|
API.healthProfile.getProfiles({ page: 1, pageSize: 20, sortBy: 'updatetime' })
|
|
.then(res => {
|
|
if (res.code !== 0) {
|
|
wx.showToast({ title: res.msg || '获取档案失败', icon: 'none' })
|
|
return
|
|
}
|
|
const data = res.data || {}
|
|
const list = (data.list || []).map(item => {
|
|
const age = calcAge(item.profile.birth)
|
|
const loc = item.location || {}
|
|
return {
|
|
id: item._id,
|
|
name: item.profile.name || '',
|
|
mobile: item.profile.mobile || '',
|
|
sexLabel: item.profile.sex === 'male' ? '男' : (item.profile.sex === 'female' ? '女' : ''),
|
|
ageText: age ? `${age}岁` : '',
|
|
locationText: [loc.province, loc.city].filter(Boolean).join(' ')
|
|
}
|
|
})
|
|
this.setData({ totalCount: data.total || 0, profileList: list })
|
|
})
|
|
.catch(err => {
|
|
console.error('获取健康档案失败', err)
|
|
wx.showToast({ title: '网络错误,请重试', icon: 'none' })
|
|
})
|
|
},
|
|
|
|
onMenuTap(e) {
|
|
const { index } = e.currentTarget.dataset
|
|
const item = this.data.quickMenus[index]
|
|
if (item.title === '新建档案') {
|
|
wx.navigateTo({ url: '/pages/healthprofile/profileInfo' })
|
|
return
|
|
}
|
|
if (item.title === '全部档案') {
|
|
// 列表已展示在本页,暂不跳转
|
|
wx.showToast({ title: '档案列表见下方', icon: 'none' })
|
|
return
|
|
}
|
|
wx.showToast({
|
|
title: `${item.title} 开发中`,
|
|
icon: 'none'
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 点击档案 → 编辑/删除
|
|
*/
|
|
onProfileTap(e) {
|
|
const { id } = e.currentTarget.dataset
|
|
wx.navigateTo({ url: `/pages/healthprofile/profileInfo?id=${id}` })
|
|
}
|
|
})
|