临时保存知情同意书PDF列表

This commit is contained in:
xianyi
2025-12-24 15:04:54 +08:00
parent e5ea1ab45e
commit e118538557
3 changed files with 124 additions and 7 deletions

View File

@@ -2,7 +2,12 @@ import { useEffect, useRef, useState } from 'react';
import type { OutputTongyishuFileInfo } from '../../api';
import { getTongyishuPdf, signInMedicalExamCenter, submitTongyishuSign } from '../../api';
import { setExamActionRecord } from '../../utils/examActions';
import {
setExamActionRecord,
setTongyishuPdfList,
getTongyishuPdfList,
type TongyishuPdfInfo,
} from '../../utils/examActions';
import type { SignaturePadHandle } from '../ui';
import { Button, SignaturePad } from '../ui';
@@ -170,6 +175,15 @@ export const ExamSignPanel = ({ examId, onBusyChange }: ExamSignPanelProps) => {
if (examId) {
setExamActionRecord(examId, 'consentSign', true);
}
// 存储返回的PDF列表
if (res.Data?.list_pdf_url && Array.isArray(res.Data.list_pdf_url) && examId) {
const pdfList: TongyishuPdfInfo[] = res.Data.list_pdf_url.map((item) => ({
pdf_name: item.pdf_name || '',
pdf_url: item.pdf_url || '',
combination_code: item.combination_code ?? null,
}));
setTongyishuPdfList(examId, pdfList);
}
setSignedCombinationCodes((prev) => {
const code = Number(previewPdf.combination_code);
if (!Number.isFinite(code)) return prev || [];
@@ -207,7 +221,33 @@ export const ExamSignPanel = ({ examId, onBusyChange }: ExamSignPanelProps) => {
getTongyishuPdf({ exam_id: examId })
.then((res) => {
const list = res.Data?.list_pdf_url || [];
setConsentList(list);
// 先拉取接口返回的全部 list_pdf_url再用本地已保存的已签名 PDF 覆盖
let mergedList = list;
const storedList = getTongyishuPdfList(examId);
if (storedList && storedList.length > 0) {
mergedList = list.map((item) => {
if (item.combination_code === undefined || item.combination_code === null) return item;
const code = Number(item.combination_code);
if (!Number.isFinite(code)) return item;
const matched = storedList.find(
(pdf) => pdf.combination_code !== null && Number(pdf.combination_code) === code,
);
if (matched && matched.pdf_url) {
return {
...item,
pdf_url: matched.pdf_url,
pdf_name: matched.pdf_name || item.pdf_name,
};
}
return item;
});
}
setConsentList(mergedList);
if (!list.length) {
setConsentMessage(res.Data?.message || '暂无知情同意书');
}
@@ -286,7 +326,34 @@ export const ExamSignPanel = ({ examId, onBusyChange }: ExamSignPanelProps) => {
/>
)}
</div>
<Button className='py-1.5 px-3' onClick={() => !busy && setPreviewPdf(item)} disabled={busy}>
<Button
className='py-1.5 px-3'
onClick={() => {
if (busy) return;
let target = item;
// 如果本地已保存签名后的PDF列表则优先使用签名后的PDF地址
if (examId) {
const storedList = getTongyishuPdfList(examId);
if (storedList && item.combination_code !== undefined && item.combination_code !== null) {
const code = Number(item.combination_code);
const matched = storedList.find(
(pdf) => pdf.combination_code !== null && Number(pdf.combination_code) === code,
);
if (matched && matched.pdf_url) {
target = {
...item,
pdf_url: matched.pdf_url,
};
}
}
}
setPreviewPdf(target);
}}
disabled={busy}
>
</Button>
</div>