import { useEffect, useState } from 'react'; import type { ExamClient } from '../../data/mockData'; import { getReportSendQRcode, getReportSendInfo, saveReportSendAddress } from '../../api'; import { Button, Input } from '../ui'; export const ExamDeliveryPanel = ({ client }: { client: ExamClient }) => { const [viewMode, setViewMode] = useState<'form' | 'image'>('form'); const [qrcodeUrl, setQrcodeUrl] = useState(null); const [qrcodeLoading, setQrcodeLoading] = useState(false); // 表单字段 const [addressContact, setAddressContact] = useState(''); const [addressMobile, setAddressMobile] = useState(''); const [provinceName, setProvinceName] = useState(''); const [cityName, setCityName] = useState(''); const [countryName, setCountryName] = useState(''); const [addressContent, setAddressContent] = useState(''); const [saveLoading, setSaveLoading] = useState(false); const [saveMessage, setSaveMessage] = useState(null); const [infoLoading, setInfoLoading] = useState(false); // 获取报告寄送地址信息并自动填入表单 useEffect(() => { if (!client.id) return; setInfoLoading(true); const appointmentId = Number(client.id); if (!appointmentId) { setInfoLoading(false); return; } getReportSendInfo({ physical_exam_id: appointmentId }) .then((res) => { if (res.Status === 200 && res.Data) { const data = res.Data; if (data.address_contact) { setAddressContact(data.address_contact); } if (data.address_mobile) { setAddressMobile(data.address_mobile); } if (data.address_content) { setAddressContent(data.address_content); } } }) .catch((err) => { console.error('获取报告寄送地址失败', err); }) .finally(() => { setInfoLoading(false); }); }, [client.id]); useEffect(() => { if (viewMode === 'image' && !qrcodeUrl && !qrcodeLoading) { setQrcodeLoading(true); // 使用 client.id 作为 appointment_id,如果接口需要其他格式,可以调整 getReportSendQRcode({ appointment_id: client.id }) .then((res) => { if (res.Status === 200 && res.Data?.qrcode_url) { setQrcodeUrl(res.Data.qrcode_url); } }) .catch((err) => { console.error('获取报告寄送二维码失败', err); }) .finally(() => { setQrcodeLoading(false); }); } }, [viewMode, client.id, qrcodeUrl, qrcodeLoading]); return (
报告寄送
{viewMode === 'form' ? ( <>
收件人姓名 setAddressContact(e.target.value)} />
联系电话 setAddressMobile(e.target.value)} />
省份 setProvinceName(e.target.value)} />
城市 setCityName(e.target.value)} />
区县 setCountryName(e.target.value)} />
详细地址 setAddressContent(e.target.value)} />
备注说明