diff --git a/src/api/his.ts b/src/api/his.ts index b448410..7b70e09 100644 --- a/src/api/his.ts +++ b/src/api/his.ts @@ -18,6 +18,8 @@ import type { TongyishuGetResponse, InputTongyishuSignSubmit, TongyishuSignSubmitResponse, + InputCustomerDetailEdit, + CustomerDetailEditResponse, } from './types'; /** @@ -156,3 +158,15 @@ export const submitTongyishuSign = ( ).then(res => res.data); }; +/** + * 客户信息编辑 + */ +export const editCustomerDetail = ( + data: InputCustomerDetailEdit +): Promise => { + return request.post( + `${MEDICAL_EXAM_BASE_PATH}/customer-detail-edit`, + data + ).then(res => res.data); +}; + diff --git a/src/api/types.ts b/src/api/types.ts index e4bb2cb..b98ba9a 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -336,3 +336,25 @@ export interface OutputTongyishuSignInfo { */ export type TongyishuSignSubmitResponse = CommonActionResult; +/** + * 客户信息编辑入参 + */ +export interface InputCustomerDetailEdit { + /** 婚姻状况(10-未婚 20-已婚) */ + marital_status: number; + /** 联系电话 */ + phone: string; +} + +/** + * 客户信息编辑出参 + */ +export interface OutputCustomerDetailEdit { + // 空对象,无属性 +} + +/** + * 客户信息编辑响应 + */ +export type CustomerDetailEditResponse = CommonActionResult; + diff --git a/src/components/exam/ExamModal.tsx b/src/components/exam/ExamModal.tsx index 12c6a04..9e7a373 100644 --- a/src/components/exam/ExamModal.tsx +++ b/src/components/exam/ExamModal.tsx @@ -8,7 +8,7 @@ import type { OutputTongyishuFileInfo, PhysicalExamProgressItem, } from '../../api'; -import { getCustomerDetail, getPhysicalExamProgressDetail, signInMedicalExamCenter, getTongyishuPdf, submitTongyishuSign } from '../../api'; +import { getCustomerDetail, getPhysicalExamProgressDetail, signInMedicalExamCenter, getTongyishuPdf, submitTongyishuSign, editCustomerDetail } from '../../api'; import type { SignaturePadHandle } from '../ui'; import { Button, Input, SignaturePad } from '../ui'; @@ -788,14 +788,28 @@ const ExamDetailInfo = ({ loading: boolean; }) => { const basePhone = customerInfo?.phone || (client['mobile' as keyof ExamClient] as string | undefined) || ''; - const baseMarital = + const baseMaritalText = customerInfo?.patient_marital_status_name || (client['maritalStatus' as keyof ExamClient] as string | undefined) || '—'; + // 将文本转换为数字:10-未婚,20-已婚 + const getMaritalCodeFromText = (text: string): number => { + if (text.includes('未婚') || text === '未婚') return 10; + if (text.includes('已婚') || text === '已婚') return 20; + return 20; // 默认已婚 + }; + const baseMaritalCode = baseMaritalText === '—' ? 20 : getMaritalCodeFromText(baseMaritalText); + const [phone, setPhone] = useState(basePhone || '—'); - const [marital, setMarital] = useState(baseMarital); + const [maritalCode, setMaritalCode] = useState(baseMaritalCode); const [phoneEditing, setPhoneEditing] = useState(false); const [maritalEditing, setMaritalEditing] = useState(false); + const [editLoading, setEditLoading] = useState(false); + const [editMessage, setEditMessage] = useState(null); + + const getMaritalText = (code: number): string => { + return code === 10 ? '未婚' : '已婚'; + }; const customerChannel = client.customerType === '团客' ? '团体客户' : '散客客户'; const familyDoctor = customerInfo?.family_doctor_name || (client['familyDoctor' as keyof ExamClient] as string | undefined) || '—'; @@ -807,6 +821,70 @@ const ExamDetailInfo = ({ ? addItemInfoList.map((i) => `${i.dept_name ?? ''} ${i.combination_name ?? ''}`.trim()).join('、') : client['addonSummary' as keyof ExamClient] || '—'; + const handleSavePhone = async () => { + if (!phone || phone.trim() === '' || phone === '—') { + setEditMessage('请输入联系电话'); + return; + } + + setEditLoading(true); + setEditMessage(null); + + try { + const res = await editCustomerDetail({ + marital_status: maritalCode, + phone: phone.trim(), + }); + + if (res.Status === 200) { + setEditMessage('保存成功'); + setPhoneEditing(false); + // 2秒后清除消息 + setTimeout(() => setEditMessage(null), 2000); + } else { + setEditMessage(res.Message || '保存失败'); + } + } catch (err) { + console.error('保存客户信息失败', err); + setEditMessage('保存失败,请稍后重试'); + } finally { + setEditLoading(false); + } + }; + + const handleSaveMarital = async () => { + const phoneValue = phone === '—' ? '' : phone.trim(); + + if (!phoneValue) { + setEditMessage('联系电话不能为空'); + return; + } + + setEditLoading(true); + setEditMessage(null); + + try { + const res = await editCustomerDetail({ + marital_status: maritalCode, + phone: phoneValue, + }); + + if (res.Status === 200) { + setEditMessage('保存成功'); + setMaritalEditing(false); + // 2秒后清除消息 + setTimeout(() => setEditMessage(null), 2000); + } else { + setEditMessage(res.Message || '保存失败'); + } + } catch (err) { + console.error('保存客户信息失败', err); + setEditMessage('保存失败,请稍后重试'); + } finally { + setEditLoading(false); + } + }; + const progressGroups = useMemo(() => { const checked: string[] = []; const abandoned: string[] = []; @@ -843,7 +921,12 @@ const ExamDetailInfo = ({ {loading ? '加载中…' : '基础信息:头像、姓名、证件号、手机号等(点击图标可进行编辑)'} - + {editMessage && ( +
+ {editMessage} +
+ )}
基础信息
@@ -868,9 +951,25 @@ const ExamDetailInfo = ({ className='w-28 rounded-xl border px-2 py-0.5 text-[11px] outline-none' value={phone} onChange={(e) => setPhone(e.target.value)} + disabled={editLoading} /> - + )} @@ -891,20 +990,54 @@ const ExamDetailInfo = ({ 婚姻状况: {!maritalEditing ? ( - {marital} + {getMaritalText(maritalCode)} ) : ( - - setMarital(e.target.value)} - /> - + )}