This commit is contained in:
lik
2026-09-09 17:37:34 +08:00
parent 3bbf4b0449
commit 089e0eb081
3 changed files with 28 additions and 6 deletions
+23 -3
View File
@@ -98,7 +98,8 @@ Page({
_id: item._id,
patientName: item.patient?.name || '',
patientSexText: SEX_MAP[item.patient?.sex] || '',
patientAge: item.patient?.age || 0,
patientBirth: item.patient?.birth || '',
patientAge: this.calcAge(item.patient?.birth),
patientWeight: item.patient?.weight || 0,
patientHeight: item.patient?.height || 0,
patientMobile: item.patient?.mobile || '',
@@ -137,6 +138,18 @@ Page({
}
},
// 根据出生年月(YYYY-MM-DD)计算年龄
calcAge(birth) {
if (!birth) return 0
const d = new Date(birth)
if (isNaN(d.getTime())) return 0
const now = new Date()
let age = now.getFullYear() - d.getFullYear()
const m = now.getMonth() - d.getMonth()
if (m < 0 || (m === 0 && now.getDate() < d.getDate())) age--
return age > 0 ? age : 0
},
formatDate(dateStr) {
const d = new Date(dateStr)
const year = d.getFullYear()
@@ -206,12 +219,15 @@ Page({
onEditPatientInfo() {
const record = this.data.record
const now = new Date()
const today = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`
this.setData({
today,
editingPatient: true,
editPatient: {
name: record.patientName || '',
sex: record.patientSexText === '男' ? 'male' : record.patientSexText === '女' ? 'female' : '',
age: record.patientAge ? String(record.patientAge) : '',
birth: record.patientBirth || '',
weight: record.patientWeight ? String(record.patientWeight) : '',
height: record.patientHeight ? String(record.patientHeight) : '',
mobile: record.patientMobile || '',
@@ -220,6 +236,10 @@ Page({
})
},
onPatientBirthChange(e) {
this.setData({ 'editPatient.birth': e.detail.value })
},
onPatientInfoInput(e) {
const field = e.currentTarget.dataset.field
const value = e.detail.value
@@ -254,7 +274,7 @@ Page({
API.escort.updateRecord(this.data.recordId, {
'patient.name': patient.name.trim(),
'patient.sex': patient.sex,
'patient.age': parseInt(patient.age) || 0,
'patient.birth': patient.birth || '',
'patient.weight': parseFloat(patient.weight) || 0,
'patient.height': parseFloat(patient.height) || 0,
'patient.mobile': patient.mobile.trim(),
+4 -2
View File
@@ -63,8 +63,10 @@
</view>
</view>
<view class="edit-row">
<text class="edit-label">年龄</text>
<input class="edit-input" type="number" value="{{editPatient.age}}" placeholder="请输入年龄" data-field="age" bindinput="onPatientInfoInput" />
<text class="edit-label">出生年月</text>
<picker mode="date" value="{{editPatient.birth}}" end="{{today}}" bindchange="onPatientBirthChange">
<view class="edit-input {{editPatient.birth ? '' : 'placeholder'}}">{{editPatient.birth || '请选择出生日期'}}</view>
</picker>
</view>
<view class="edit-row">
<text class="edit-label">体重(kg)</text>