完善导检单显示
This commit is contained in:
@@ -87,10 +87,36 @@ export const ExamPrintPanel = ({ client }: { client: ExamClient }) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 组件加载时检查localStorage,如果有则直接展示
|
||||
// 组件加载时自动获取导检单(未签名版本也可以查看)
|
||||
useEffect(() => {
|
||||
const examId = Number(client.id);
|
||||
if (!examId) return;
|
||||
|
||||
// 自动加载未签名的导检单用于查看
|
||||
const fetchPdf = async () => {
|
||||
setFetchLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const res = await getDaojiandanPdfApi({ exam_id: examId });
|
||||
if (res.Status === 200 && res.Data?.pdf_url) {
|
||||
const pdfUrlValue = res.Data.pdf_url;
|
||||
console.log('获取到导检单PDF URL:', pdfUrlValue);
|
||||
setPdfUrl(pdfUrlValue);
|
||||
setShowPreview(true);
|
||||
} else {
|
||||
console.error('获取导检单失败,响应:', res);
|
||||
setError(res.Message || '获取导检单失败');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取导检单失败', err);
|
||||
setError('获取导检单失败,请稍后重试');
|
||||
} finally {
|
||||
setFetchLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchPdf();
|
||||
}, [client.id]);
|
||||
|
||||
// 获取导检单PDF(优先使用localStorage,没有则调用接口)
|
||||
@@ -389,10 +415,6 @@ export const ExamPrintPanel = ({ client }: { client: ExamClient }) => {
|
||||
<div className='flex items-center justify-center py-12 text-gray-500'>
|
||||
<div>正在加载导检单...</div>
|
||||
</div>
|
||||
) : loading ? (
|
||||
<div className='flex items-center justify-center py-12 text-gray-500'>
|
||||
<div>正在加载PDF...</div>
|
||||
</div>
|
||||
) : error ? (
|
||||
<div className='flex flex-col items-center justify-center py-12 text-gray-500'>
|
||||
<div className='mb-2'>{error}</div>
|
||||
@@ -421,6 +443,10 @@ export const ExamPrintPanel = ({ client }: { client: ExamClient }) => {
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
) : loading ? (
|
||||
<div className='flex items-center justify-center py-12 text-gray-500'>
|
||||
<div>正在加载PDF...</div>
|
||||
</div>
|
||||
) : pdfUrl ? (
|
||||
<div className='w-full'>
|
||||
<div ref={printRef} className='print-content'>
|
||||
@@ -429,6 +455,10 @@ export const ExamPrintPanel = ({ client }: { client: ExamClient }) => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : showPreview ? (
|
||||
<div className='flex items-center justify-center py-12 text-gray-500'>
|
||||
<div>正在准备导检单...</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -3,7 +3,7 @@ import * as pdfjsLib from 'pdfjs-dist';
|
||||
import pdfjsWorker from 'pdfjs-dist/build/pdf.worker.min.mjs?url';
|
||||
|
||||
import type { OutputTongyishuFileInfo, OutputTijianPdfFileInfo } from '../../api';
|
||||
import { signInMedicalExamCenter, submitTongyishuSign, submitDaojiandanSign, editDaojiandanPrintStatus, submitAddItemBillSign, getTijianPdfFile } from '../../api';
|
||||
import { signInMedicalExamCenter, submitTongyishuSign, submitDaojiandanSign, editDaojiandanPrintStatus, submitAddItemBillSign, getTijianPdfFile, getTongyishuPdf, getDaojiandanPdf } from '../../api';
|
||||
import type { SignaturePadHandle } from '../ui';
|
||||
import { Button, SignaturePad } from '../ui';
|
||||
|
||||
@@ -129,7 +129,9 @@ export const ExamSignPanel = ({ examId, onBusyChange }: ExamSignPanelProps) => {
|
||||
setDaojiandanUrl(url);
|
||||
setIsDaojiandanSigned(daojiandan.is_sign === 1);
|
||||
} else {
|
||||
setDaojiandanUrl(null);
|
||||
// 如果 getTijianPdfFile 没有返回导检单,保留之前通过 getDaojiandanPdf 获取的URL(如果存在)
|
||||
// 不设置为 null,这样未签名的导检单也能显示"查看"按钮
|
||||
setDaojiandanUrl((prev) => (prev !== null ? prev : null));
|
||||
setIsDaojiandanSigned(false);
|
||||
}
|
||||
|
||||
@@ -169,7 +171,45 @@ export const ExamSignPanel = ({ examId, onBusyChange }: ExamSignPanelProps) => {
|
||||
setIsDaojiandanSigned(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// 初始化时加载知情同意书和导检单
|
||||
const loadTongyishu = async () => {
|
||||
try {
|
||||
const res = await getTongyishuPdf({ exam_id: examId });
|
||||
if (res.Status === 200 && res.Data?.list_pdf_url) {
|
||||
const list = res.Data.list_pdf_url;
|
||||
const mappedConsent: OutputTongyishuFileInfo[] = list.map((item) => ({
|
||||
pdf_name: item.pdf_name || '',
|
||||
pdf_url: item.pdf_url || '',
|
||||
combination_code: item.combination_code ?? null,
|
||||
}));
|
||||
setConsentList(mappedConsent);
|
||||
if (mappedConsent.length === 0) {
|
||||
setConsentMessage(res.Message || '暂无知情同意书');
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取知情同意书失败', err);
|
||||
}
|
||||
};
|
||||
|
||||
// 初始化时加载导检单(未签名版本也可以查看)
|
||||
const loadDaojiandan = async () => {
|
||||
try {
|
||||
const res = await getDaojiandanPdf({ exam_id: examId });
|
||||
if (res.Status === 200 && res.Data?.pdf_url) {
|
||||
// 如果 refreshTijianPdfs 没有设置导检单URL,则使用这里获取的未签名版本
|
||||
setDaojiandanUrl((prev) => prev || res.Data?.pdf_url || null);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取导检单失败', err);
|
||||
}
|
||||
};
|
||||
|
||||
// 先加载知情同意书和导检单,然后刷新所有PDF状态(包括签名状态)
|
||||
Promise.all([loadTongyishu(), loadDaojiandan()]).then(() => {
|
||||
refreshTijianPdfs(examId);
|
||||
});
|
||||
}, [examId]);
|
||||
|
||||
const handlePickFile = () => {
|
||||
|
||||
Reference in New Issue
Block a user