diff --git a/pages/escort/recorddetail.js b/pages/escort/recorddetail.js index f669b34..ed01b89 100644 --- a/pages/escort/recorddetail.js +++ b/pages/escort/recorddetail.js @@ -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(), diff --git a/pages/escort/recorddetail.wxml b/pages/escort/recorddetail.wxml index 8f313dd..5d8b8fe 100644 --- a/pages/escort/recorddetail.wxml +++ b/pages/escort/recorddetail.wxml @@ -63,8 +63,10 @@ - 年龄 - + 出生年月 + + {{editPatient.birth || '请选择出生日期'}} + 体重(kg) diff --git a/pages/mine/mine.js b/pages/mine/mine.js index d74367d..a0a85df 100644 --- a/pages/mine/mine.js +++ b/pages/mine/mine.js @@ -212,7 +212,7 @@ Page({ wx.login({ success: (res) => { if (res.code) { - API.user.wxSignin({ phoneNumber, code: res.code }) + API.user.wxSignin({ phoneNumber, phoneCode, code: res.code }) .then((data) => { if (data.code == 0) { const app = getApp()