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, _id: item._id,
patientName: item.patient?.name || '', patientName: item.patient?.name || '',
patientSexText: SEX_MAP[item.patient?.sex] || '', 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, patientWeight: item.patient?.weight || 0,
patientHeight: item.patient?.height || 0, patientHeight: item.patient?.height || 0,
patientMobile: item.patient?.mobile || '', 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) { formatDate(dateStr) {
const d = new Date(dateStr) const d = new Date(dateStr)
const year = d.getFullYear() const year = d.getFullYear()
@@ -206,12 +219,15 @@ Page({
onEditPatientInfo() { onEditPatientInfo() {
const record = this.data.record 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({ this.setData({
today,
editingPatient: true, editingPatient: true,
editPatient: { editPatient: {
name: record.patientName || '', name: record.patientName || '',
sex: record.patientSexText === '男' ? 'male' : record.patientSexText === '女' ? 'female' : '', sex: record.patientSexText === '男' ? 'male' : record.patientSexText === '女' ? 'female' : '',
age: record.patientAge ? String(record.patientAge) : '', birth: record.patientBirth || '',
weight: record.patientWeight ? String(record.patientWeight) : '', weight: record.patientWeight ? String(record.patientWeight) : '',
height: record.patientHeight ? String(record.patientHeight) : '', height: record.patientHeight ? String(record.patientHeight) : '',
mobile: record.patientMobile || '', mobile: record.patientMobile || '',
@@ -220,6 +236,10 @@ Page({
}) })
}, },
onPatientBirthChange(e) {
this.setData({ 'editPatient.birth': e.detail.value })
},
onPatientInfoInput(e) { onPatientInfoInput(e) {
const field = e.currentTarget.dataset.field const field = e.currentTarget.dataset.field
const value = e.detail.value const value = e.detail.value
@@ -254,7 +274,7 @@ Page({
API.escort.updateRecord(this.data.recordId, { API.escort.updateRecord(this.data.recordId, {
'patient.name': patient.name.trim(), 'patient.name': patient.name.trim(),
'patient.sex': patient.sex, 'patient.sex': patient.sex,
'patient.age': parseInt(patient.age) || 0, 'patient.birth': patient.birth || '',
'patient.weight': parseFloat(patient.weight) || 0, 'patient.weight': parseFloat(patient.weight) || 0,
'patient.height': parseFloat(patient.height) || 0, 'patient.height': parseFloat(patient.height) || 0,
'patient.mobile': patient.mobile.trim(), 'patient.mobile': patient.mobile.trim(),
+4 -2
View File
@@ -63,8 +63,10 @@
</view> </view>
</view> </view>
<view class="edit-row"> <view class="edit-row">
<text class="edit-label">年龄</text> <text class="edit-label">出生年月</text>
<input class="edit-input" type="number" value="{{editPatient.age}}" placeholder="请输入年龄" data-field="age" bindinput="onPatientInfoInput" /> <picker mode="date" value="{{editPatient.birth}}" end="{{today}}" bindchange="onPatientBirthChange">
<view class="edit-input {{editPatient.birth ? '' : 'placeholder'}}">{{editPatient.birth || '请选择出生日期'}}</view>
</picker>
</view> </view>
<view class="edit-row"> <view class="edit-row">
<text class="edit-label">体重(kg)</text> <text class="edit-label">体重(kg)</text>
+1 -1
View File
@@ -212,7 +212,7 @@ Page({
wx.login({ wx.login({
success: (res) => { success: (res) => {
if (res.code) { if (res.code) {
API.user.wxSignin({ phoneNumber, code: res.code }) API.user.wxSignin({ phoneNumber, phoneCode, code: res.code })
.then((data) => { .then((data) => {
if (data.code == 0) { if (data.code == 0) {
const app = getApp() const app = getApp()