diff --git a/apps/miniprogram/src/pages/profile/family-add/index.tsx b/apps/miniprogram/src/pages/profile/family-add/index.tsx
index 02c352d..44ee07c 100644
--- a/apps/miniprogram/src/pages/profile/family-add/index.tsx
+++ b/apps/miniprogram/src/pages/profile/family-add/index.tsx
@@ -1,19 +1,31 @@
-import React, { useState } from 'react';
+import React, { useState, useEffect } from 'react';
import { View, Text, Input, Picker } from '@tarojs/components';
-import Taro from '@tarojs/taro';
-import { createPatient } from '../../../services/patient';
+import Taro, { useRouter } from '@tarojs/taro';
+import { createPatient, updatePatient, Patient } from '../../../services/patient';
import './index.scss';
const RELATION_OPTIONS = ['本人', '配偶', '父母', '子女', '其他'];
const GENDER_OPTIONS = ['男', '女'];
export default function FamilyAdd() {
- const [name, setName] = useState('');
- const [relationIdx, setRelationIdx] = useState(0);
- const [genderIdx, setGenderIdx] = useState(0);
- const [birthDate, setBirthDate] = useState('');
+ const router = useRouter();
+ const editId = router.params.id || '';
+ const editData = Taro.getStorageSync('edit_patient') as Patient | null;
+
+ const [name, setName] = useState(editData?.name || '');
+ const [relationIdx, setRelationIdx] = useState(
+ editData?.relation ? RELATION_OPTIONS.indexOf(editData.relation) : 0
+ );
+ const [genderIdx, setGenderIdx] = useState(
+ editData?.gender === 'female' ? 1 : 0
+ );
+ const [birthDate, setBirthDate] = useState(editData?.birthday || '');
const [submitting, setSubmitting] = useState(false);
+ useEffect(() => {
+ return () => { Taro.removeStorageSync('edit_patient'); };
+ }, []);
+
const handleSubmit = async () => {
if (!name.trim()) {
Taro.showToast({ title: '请输入姓名', icon: 'none' });
@@ -21,17 +33,25 @@ export default function FamilyAdd() {
}
setSubmitting(true);
try {
- await createPatient({
- name: name.trim(),
- gender: GENDER_OPTIONS[genderIdx] === '男' ? 'male' : 'female',
- birthday: birthDate || undefined,
- });
- Taro.showToast({ title: '添加成功', icon: 'success' });
- setTimeout(() => {
- Taro.navigateBack();
- }, 1000);
+ if (editId && editData) {
+ await updatePatient(editId, {
+ name: name.trim(),
+ gender: GENDER_OPTIONS[genderIdx] === '男' ? 'male' : 'female',
+ birthday: birthDate || undefined,
+ relation: RELATION_OPTIONS[relationIdx],
+ }, editData.version);
+ Taro.showToast({ title: '修改成功', icon: 'success' });
+ } else {
+ await createPatient({
+ name: name.trim(),
+ gender: GENDER_OPTIONS[genderIdx] === '男' ? 'male' : 'female',
+ birthday: birthDate || undefined,
+ });
+ Taro.showToast({ title: '添加成功', icon: 'success' });
+ }
+ setTimeout(() => Taro.navigateBack(), 1000);
} catch {
- Taro.showToast({ title: '添加失败', icon: 'none' });
+ Taro.showToast({ title: editId ? '修改失败' : '添加失败', icon: 'none' });
} finally {
setSubmitting(false);
}
@@ -40,7 +60,6 @@ export default function FamilyAdd() {
return (
- {/* 姓名 */}
姓名
- {/* 关系 */}
关系
- {/* 性别 */}
性别
- {/* 出生日期 */}
出生日期
- {submitting ? '提交中...' : '确认添加'}
+ {submitting ? '提交中...' : editId ? '保存修改' : '确认添加'}
);
diff --git a/apps/miniprogram/src/pages/profile/family/index.scss b/apps/miniprogram/src/pages/profile/family/index.scss
index e75a26b..16ad4b0 100644
--- a/apps/miniprogram/src/pages/profile/family/index.scss
+++ b/apps/miniprogram/src/pages/profile/family/index.scss
@@ -68,6 +68,15 @@
font-weight: bold;
}
+.family-edit {
+ font-size: 24px;
+ color: $pri;
+ margin-left: 16px;
+ padding: 6px 16px;
+ border: 1px solid $pri;
+ border-radius: 16px;
+}
+
.empty-state {
display: flex;
justify-content: center;
diff --git a/apps/miniprogram/src/pages/profile/family/index.tsx b/apps/miniprogram/src/pages/profile/family/index.tsx
index 671245e..d49ae09 100644
--- a/apps/miniprogram/src/pages/profile/family/index.tsx
+++ b/apps/miniprogram/src/pages/profile/family/index.tsx
@@ -42,6 +42,11 @@ export default function FamilyList() {
Taro.navigateTo({ url: '/pages/profile/family-add/index' });
};
+ const goToEdit = (patient: Patient) => {
+ Taro.setStorageSync('edit_patient', patient);
+ Taro.navigateTo({ url: `/pages/profile/family-add/index?id=${patient.id}` });
+ };
+
const genderText = (g?: string) => {
if (g === 'male') return '男';
if (g === 'female') return '女';
@@ -67,6 +72,7 @@ export default function FamilyList() {
{isActive && 当前}
+ { e.stopPropagation(); goToEdit(p); }}>编辑
);
})}
diff --git a/apps/miniprogram/src/pages/profile/medication/index.tsx b/apps/miniprogram/src/pages/profile/medication/index.tsx
index 9145049..95948fe 100644
--- a/apps/miniprogram/src/pages/profile/medication/index.tsx
+++ b/apps/miniprogram/src/pages/profile/medication/index.tsx
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react';
-import { View, Text, Input } from '@tarojs/components';
+import { View, Text, Input, Picker } from '@tarojs/components';
import Taro from '@tarojs/taro';
import EmptyState from '../../../components/EmptyState';
import './index.scss';
@@ -132,9 +132,16 @@ export default function MedicationReminder() {
提醒时间
-
- {formTime}
-
+ setFormTime(e.detail.value)}
+ >
+
+ {formTime}
+ 修改
+
+
setShowForm(false)}>