import React, { useState, useCallback } from 'react'; import { View, Text } from '@tarojs/components'; import Taro from '@tarojs/taro'; import { safeNavigateTo } from '@/utils/navigate'; import { usePageData } from '@/hooks/usePageData'; import { listPatients, Patient } from '../../../services/patient'; import { useAuthStore } from '../../../stores/auth'; import EmptyState from '../../../components/EmptyState'; import { useElderClass } from '../../../hooks/useElderClass'; import PageShell from '@/components/ui/PageShell'; import './index.scss'; export default function FamilyList() { const modeClass = useElderClass(); const [patients, setPatients] = useState([]); const [loading, setLoading] = useState(false); const currentPatient = useAuthStore((s) => s.currentPatient); const setCurrentPatient = useAuthStore((s) => s.setCurrentPatient); const fetchPatients = useCallback(async () => { setLoading(true); try { const res = await listPatients(); setPatients(res.data || []); } catch { Taro.showToast({ title: '加载失败', icon: 'none' }); } finally { setLoading(false); } }, []); usePageData(fetchPatients, { throttleMs: 10000 }); const handleSelect = (patient: Patient) => { setCurrentPatient({ id: patient.id, name: patient.name, gender: patient.gender, birth_date: patient.birth_date, relation: patient.relation || '本人', }); Taro.showToast({ title: `已切换为 ${patient.name}`, icon: 'success' }); }; const goToAdd = () => { safeNavigateTo('/pages/pkg-profile/family-add/index'); }; const goToEdit = (patient: Patient) => { Taro.setStorageSync('edit_patient', patient); safeNavigateTo(`/pages/pkg-profile/family-add/index?id=${patient.id}`); }; const genderText = (g?: string) => { if (g === 'male') return '男'; if (g === 'female') return '女'; return '未知'; }; const relationInitial = (relation: string) => { return relation ? relation.charAt(0) : '本'; }; return ( 就诊人管理 {patients.map((p) => { const isActive = currentPatient?.id === p.id; return ( handleSelect(p)} > {relationInitial(p.relation || '本人')} {p.name} {isActive && 当前} {p.relation || '本人'} {genderText(p.gender)} { e.stopPropagation(); goToEdit(p); }} > 编辑 ); })} {patients.length === 0 && !loading && ( )} 添加就诊人 ); }