diff --git a/src/components/exam/ExamModal.tsx b/src/components/exam/ExamModal.tsx index dc525d8..c2790d4 100644 --- a/src/components/exam/ExamModal.tsx +++ b/src/components/exam/ExamModal.tsx @@ -7,7 +7,7 @@ import type { CustomerInfo, PhysicalExamProgressItem, } from '../../api'; -import { getCustomerDetail, getPhysicalExamProgressDetail, signInMedicalExamCenter } from '../../api'; +import { getCustomerDetail, getPhysicalExamProgressDetail, signInMedicalExamCenter, getTongyishuPdf } from '../../api'; import { Button, Input } from '../ui'; interface ExamModalProps { @@ -84,7 +84,7 @@ export const ExamModal = ({ client, tab, onTabChange, onClose }: ExamModalProps) onTouchStart={handleTouchStart} >
(
); -const ExamPrintPanel = ({ client }: { client: ExamClient }) => ( -
-
-
-
-
圆和医疗体检中心 · 导检单预览
-
此为预览页面,实际打印效果以院内打印机为准。
-
-
-
体检号:{client.id}
-
日期:2025-11-18
-
-
+const ExamPrintPanel = ({ client }: { client: ExamClient }) => { + const [pdfUrl, setPdfUrl] = useState(null); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + const [pdfReady, setPdfReady] = useState(false); + const [pdfBlobUrl, setPdfBlobUrl] = useState(null); + const printRef = useRef(null); + const iframeRef = useRef(null); -
-
- 姓名:{client.name} -
-
- 性别/年龄: - - {client.gender} / {client.age} - -
-
- 体检套餐:{client.packageName} -
-
- 客户类型:{client.customerType} -
-
+ // 获取 PDF + useEffect(() => { + const physical_exam_id = Number(client.id); + if (!physical_exam_id) { + setError('无效的体检ID'); + setLoading(false); + return; + } -
检查项目列表(预览)
- - - - - - - - - - - {client.checkedItems.map((item, idx) => ( - - - - - - - ))} - {client.pendingItems.map((item, idx) => ( - - - - - - - ))} - -
序号检查项目科室备注
{idx + 1}{item}已预约
{client.checkedItems.length + idx + 1}{item}待检查
+ setPdfReady(false); + getTongyishuPdf({ exam_id: physical_exam_id }) + .then((res) => { + if (res.Status === 200 && res.Data?.list_pdf_url && res.Data.list_pdf_url.length > 0) { + // 取第一个PDF URL + setPdfUrl(res.Data.list_pdf_url[0].pdf_url); + setPdfReady(false); + } else { + setError(res.Message || '未获取到PDF文件'); + } + }) + .catch((err) => { + console.error('获取PDF失败', err); + setError('获取PDF失败,请稍后重试'); + }) + .finally(() => { + setLoading(false); + }); + }, [client.id]); -
-
-
导检提示
-
    -
  • 请按导检单顺序前往相应科室检查。
  • -
  • 如有不适或特殊情况,请及时告知导检护士。
  • -
  • 部分检查项目需空腹或憋尿,请遵从现场指引。
  • -
-
-
-
-
导检护士签名:________________
-
打印时间:2025-11-18 09:30
+ // 将 PDF 拉取为同源 blob,避免跨域打印限制 + useEffect(() => { + if (!pdfUrl) return; + + let objectUrl: string | null = null; + setPdfReady(false); + setLoading(true); + + fetch(pdfUrl) + .then((resp) => { + if (!resp.ok) throw new Error('获取PDF文件失败'); + return resp.blob(); + }) + .then((blob) => { + objectUrl = URL.createObjectURL(blob); + setPdfBlobUrl(objectUrl); + }) + .catch((err) => { + console.error('PDF 拉取失败', err); + setError('PDF 加载失败,请稍后重试'); + }) + .finally(() => { + setLoading(false); + }); + + return () => { + if (objectUrl) { + URL.revokeObjectURL(objectUrl); + } + }; + }, [pdfUrl]); + + const handlePrint = () => { + if (!pdfBlobUrl || !pdfReady) return; + + // 打开新窗口打印(同源 blob),避免跨域和空白页问题 + const printWindow = window.open(pdfBlobUrl, '_blank'); + if (printWindow) { + printWindow.onload = () => { + printWindow.focus(); + printWindow.print(); + }; + } + }; + + return ( +
+
+
+
+
圆和医疗体检中心 · 导检单预览
+
此为预览页面,实际打印效果以院内打印机为准。
-
- 条码 / 二维码 +
+
+
体检号:{client.id}
+
日期:{new Date().toLocaleDateString('zh-CN')}
+
+
+ + {loading ? ( +
+
正在加载PDF...
+
+ ) : error ? ( +
+
{error}
+ +
+ ) : pdfUrl ? ( +
+ {/* PDF预览区域 */} +
+
+