| | |
| | | await DevRentApi.devReady(formData.value) |
| | | |
| | | if (autoPrint.value && formData.value.patId && formData.value.checkType) { |
| | | printBill(formData.value.patDetails?.appointmentId) |
| | | const apptId = formData.value.patDetails?.appointmentId |
| | | // 【本次修复】自动打印时若没有预约单号就**静默跳过**: |
| | | // 手动点「打印小票」会给出"无预约单"的提示,但领用完成后的自动打印不该弹警告打断流程。 |
| | | if (apptId != null) { |
| | | printBill(apptId) |
| | | } |
| | | } |
| | | |
| | | // 自动确费 |
| | |
| | | devInfo.value.state = data.devState |
| | | } |
| | | |
| | | /** |
| | | * 【本次修复】等待 hiprint 打印客户端就绪(最多约 800ms)。 |
| | | * |
| | | * 打印客户端是**本机** websocket 服务(默认 http://localhost:17521), |
| | | * `print2()`(静默打印)要求它已连接;首次点击时 socket 可能还在连接中, |
| | | * 这里短暂轮询,避免"本机明明装了客户端,却因为没连上而打不出票"。 |
| | | * |
| | | * @returns true = 客户端可用,可静默打印;false = 不可用,应回退浏览器打印 |
| | | */ |
| | | const waitPrintClientOpened = async (tpl: any, timeoutMs = 800): Promise<boolean> => { |
| | | if (typeof tpl?.clientIsOpened !== 'function') return false |
| | | if (tpl.clientIsOpened()) return true |
| | | const step = 100 |
| | | for (let waited = 0; waited < timeoutMs; waited += step) { |
| | | // eslint-disable-next-line no-await-in-loop |
| | | await new Promise((resolve) => setTimeout(resolve, step)) |
| | | if (tpl.clientIsOpened()) return true |
| | | } |
| | | return false |
| | | } |
| | | |
| | | const printBill = async (appointmentId: number | null | undefined, printMode?: number) => { |
| | | if ( appointmentId == null ) |
| | | // 【本次修复】原来这里直接 return,现场表现是"点「打印小票」完全没反应"。 |
| | | // 小票内容取自**预约单**,没有预约单号就没有可打印的内容 —— 这里明确提示。 |
| | | if (appointmentId == null) { |
| | | message.warning('该患者没有关联的预约单(缺少预约单号),无法打印小票') |
| | | return |
| | | } |
| | | |
| | | const curAppointment: AppointmentVO = await AppointmentApi.getAppointment( appointmentId ) |
| | | |
| | |
| | | // 下列方法都是没有拖拽设计页面的, 相当于代码模式, 使用代码设计页面 |
| | | // 想要实现拖拽设计页面,请往下看 '自定义设计' |
| | | var hiprintTemplate = new hiprint.PrintTemplate(); // 可传参数 |
| | | //var panel = hiprintTemplate.addPrintPanel({ width: 100, height: 130, paperFooter: 340, paperHeader: 10 }); 导致走三页 |
| | | var panel = hiprintTemplate.addPrintPanel({ width: 140, height: 130, paperNumberDisabled:true}); |
| | | //文本 |
| | | |
| | | // ============================================================================ |
| | | // 【本次调整·适配得实 DL-210 + 热敏纸 50×30mm】 |
| | | // |
| | | // 打印机:得实 DL-210(203dpi = 8 dots/mm,可打印宽度 108mm,USB 口) |
| | | // 耗材 :热敏标签纸 50mm(宽) × 30mm(高) |
| | | // |
| | | // 之前模板是 140×130mm(给 A4/大面单用的),比 50mm 纸宽出 90mm ⇒ 驱动按 50mm 缩放, |
| | | // 字与条码会被压得很小/裁切。这里整体改为 50×30mm,并按小纸重排为 **5 行 + 1 条码**: |
| | | // |
| | | // y 0.8mm ── 检查项目(10pt 加粗居中) |
| | | // y 5.6mm ── 姓名 性别 年龄(9pt 加粗居中) |
| | | // y10.0mm ── 病区-床号(左半) | 预约 11-28 08:00(右半) 7.5pt |
| | | // y14.0mm ── 患者编号(左半) | 手机号(右半) 7.5pt |
| | | // y18.4mm ── 条形码(高 10.8mm,宽 46mm;内容 = 就诊流水号 episodeId) |
| | | // |
| | | // ⚠️【单位坑·2026-11-28 实测】hiprint 的 **面板**尺寸 `addPrintPanel({width,height})` 用 **mm**, |
| | | // 但**元素**的 `top/left/width/height` 用 **pt**(源码:`options.displayLeft()` 返回 `left+"pt"`, |
| | | // 元素默认 height=9.75 / width=120 也都是 pt)。第一版把元素坐标也当 mm 传入(0.6/5/8.8…), |
| | | // 结果 27.4"mm" 实际只有 27.4pt≈9.7mm ⇒ 所有文字/条码挤在标签顶部、互相重叠。 |
| | | // 现在统一:**布局仍按 mm 写**,进入 hiprint 前用 mm2pt() 换算(1mm = 72/25.4 pt)。 |
| | | // ============================================================================ |
| | | const PAPER_W = 50 // 标签纸宽 mm(面板单位=mm) |
| | | const PAPER_H = 30 // 标签纸高 mm(面板单位=mm) |
| | | /** 1mm = 2.83465pt */ |
| | | const PT_PER_MM = 72 / 25.4 |
| | | /** mm → pt(元素坐标/尺寸用) */ |
| | | const mm2pt = (v: number) => Math.round(v * PT_PER_MM * 100) / 100 |
| | | // 【打印份数】正式口径 = 2 张(患者 1 张 + 科室留存 1 张)。 |
| | | // 想改份数只改这一个数字:改 1 = 测试省纸;改 3 = 三联。 |
| | | const PRINT_COPIES = 2 |
| | | var panel = hiprintTemplate.addPrintPanel({ width: PAPER_W, height: PAPER_H, paperNumberDisabled:true}); |
| | | |
| | | const FONT = '微软雅黑' |
| | | /** |
| | | * 加一行文本(统一字体/居中)。 |
| | | * 入参单位:**mm**(内部换算成 hiprint 需要的 pt);fontSize 单位是 **pt**。 |
| | | */ |
| | | const addLine = (opts: { |
| | | top: number; left?: number; width?: number; height?: number; |
| | | title: string; fontSize?: number; bold?: boolean; align?: string; |
| | | }) => { |
| | | panel.addPrintText({ |
| | | options: { |
| | | left: mm2pt(opts.left ?? 1), |
| | | top: mm2pt(opts.top), |
| | | width: mm2pt(opts.width ?? PAPER_W - 2), |
| | | height: mm2pt(opts.height ?? 3.6), |
| | | title: opts.title ?? '', |
| | | textAlign: opts.align ?? 'center', |
| | | fontSize: opts.fontSize ?? 8, |
| | | fontFamily: FONT, |
| | | fontWeight: opts.bold === false ? '400' : '700' |
| | | } |
| | | }) |
| | | } |
| | | |
| | | // ① 检查项目(y 0.8~5.4mm) |
| | | const checkTypeName = getCheckTypeName(curAppointment.bookCheckType) |
| | | panel.addPrintText({ options: { width: 140, height: 12, top: 2, left: 20, title: checkTypeName, textAlign: 'center', fontSize: 10, fontFamily: '微软雅黑', fontWeight: '700', } }); |
| | | addLine({ top: 0.8, height: 4.6, title: checkTypeName, fontSize: 10 }) |
| | | // ② 姓名 性别 年龄(y 5.6~9.6mm) |
| | | const patientBaisc = curAppointment.patName + " " + calGender(curAppointment.patGender) + " " + calculateAge(curAppointment.patBirthday) + "岁" |
| | | panel.addPrintText({ options: { width: 140, height: 12, top: 16, left: 20, title: patientBaisc, textAlign: 'center' , fontSize: 10, fontFamily: '微软雅黑', fontWeight: '700', } }); |
| | | const ward_bed = curAppointment.patWardDesc + "-" + curAppointment.patBedNo |
| | | panel.addPrintText({ options: { width: 140, height: 12, top: 30, left: 20, title: ward_bed, textAlign: 'center', fontSize: 10, fontFamily: '微软雅黑', fontWeight: '700', } }); |
| | | const bookTime = formatTimestamp(curAppointment.bookDate) + " " + getBookBeginTime(curAppointment.bookTimeslot) |
| | | panel.addPrintText({ options: { width: 140, height: 12, top: 44, left: 20, title: bookTime, textAlign: 'center', fontSize: 10, fontFamily: '微软雅黑', fontWeight: '700', } }); |
| | | panel.addPrintText({ options: { width: 140, height: 12, top: 58, left: 20, title: curAppointment.patId, textAlign: 'center', fontSize: 10, fontFamily: '微软雅黑', fontWeight: '700', } }); |
| | | panel.addPrintText({ options: { width: 140, height: 12, top: 72, left: 20, title: curAppointment.patMobile, textAlign: 'center', fontSize: 10, fontFamily: '微软雅黑', fontWeight: '700', } }); |
| | | //条形码 |
| | | panel.addPrintText({ options: { width: 140, height: 22, top: 86, left: 20, title: curAppointment.episodeId, textType: 'barcode' } }); |
| | | addLine({ top: 5.6, height: 4.0, title: patientBaisc, fontSize: 9 }) |
| | | // ③ 病区-床号 | 预约时间(y 10.0~13.6mm;"2026-11-28 08:00" 缩成 "11-28 08:00") |
| | | const ward_bed = (curAppointment.patWardDesc || '') + (curAppointment.patBedNo ? "-" + curAppointment.patBedNo : '') |
| | | addLine({ top: 10.0, height: 3.6, left: 1.5, width: 22, title: ward_bed, fontSize: 7.5 }) |
| | | const bookTime = formatTimestamp(curAppointment.bookDate).slice(5) + " " + getBookBeginTime(curAppointment.bookTimeslot) |
| | | addLine({ top: 10.0, height: 3.6, left: 24, width: 25, title: bookTime, fontSize: 7.5 }) |
| | | // ④ 患者编号 | 手机号(y 14.0~17.6mm) |
| | | addLine({ top: 14.0, height: 3.6, left: 1.5, width: 22, title: curAppointment.patId ?? '', fontSize: 7.5 }) |
| | | addLine({ top: 14.0, height: 3.6, left: 24, width: 25, title: curAppointment.patMobile ?? '', fontSize: 7.5 }) |
| | | // ⑤ 条形码(内容 = 就诊流水号;坐标同样 mm→pt) |
| | | // |
| | | // 【"没居中"】① 元素按内容算宽后 `left = (50-w)/2` 精确居中; |
| | | // ② hiprint 的条形 svg 是 `width:100%`,宽度随元素走,所以元素宽度不能随手给。 |
| | | // 【"数值太低"】hiprint 条码元素内部是: |
| | | // <svg class="hibarcode_imgcode" width=100% height=100%> + <div class="hibarcode_displayValue">数值</div> |
| | | // 条形占满元素高度,数值 div 排在元素盒子**之下**,元素一高数值就被推到纸边(甚至会掉到第二页/被裁)。 |
| | | // 因此这里:**关掉它自带的数值(hideTitle)**,改由我们自己紧贴条码画一行居中数值(位置可控)。 |
| | | const barcodeText = curAppointment.episodeId ?? '' |
| | | const isPureDigits = /^\d+$/.test(barcodeText) |
| | | // CODE128 模块数:起始 11 + 数据 + 校验 11 + 终止 13; |
| | | // 纯数字偶数位走 CODE128-C(2 位/符号),否则走 CODE128-B(1 位/符号) |
| | | const barcodeModules = isPureDigits && barcodeText.length % 2 === 0 |
| | | ? 11 + (barcodeText.length / 2) * 11 + 11 + 13 |
| | | : 11 + barcodeText.length * 11 + 11 + 13 |
| | | // JsBarcode 里 1 模块 = 1px ≈ 0.2646mm;+1mm 余量,并限制在 18~40mm(太窄会糊、太宽超出纸面) |
| | | const barcodeWidthMm = Math.min(40, Math.max(18, barcodeModules * 0.2646 + 1)) |
| | | const barcodeLeftMm = (PAPER_W - barcodeWidthMm) / 2 |
| | | const BARCODE_TOP = 17.4 // 条形起始 |
| | | const BARCODE_H = 8.2 // 条形高度(203dpi ≈ 66 点高,扫码足够) |
| | | panel.addPrintText({ |
| | | options: { |
| | | left: mm2pt(barcodeLeftMm), |
| | | top: mm2pt(BARCODE_TOP), |
| | | width: mm2pt(barcodeWidthMm), |
| | | height: mm2pt(BARCODE_H), |
| | | title: barcodeText, |
| | | textType: 'barcode', |
| | | hideTitle: true // 不要 hiprint 自带的数值(它在元素下方,会把内容顶出纸面) |
| | | } |
| | | }); |
| | | // ⑤-2 数值:紧贴条码下方 0.9mm,居中(与条码同宽,超出会被截断) |
| | | addLine({ top: BARCODE_TOP + BARCODE_H + 0.9, height: 3.0, title: barcodeText, fontSize: 7.5 }) |
| | | |
| | | //打印 |
| | | if (printMode == null) |
| | | hiprintTemplate.print2([{},{},{}]); // 预览方式 可以传 [定位参数] http://https://ccsimple.github.io/sv-print-docs/config/template.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E8%AE%BE%E8%AE%A1%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B |
| | | else |
| | | hiprintTemplate.print([{},{},{}]); |
| | | // 【本次修复】优先"静默打印"(需要本机 hiprint 打印客户端); |
| | | // 客户端未连接/未安装时**回退浏览器打印**(弹打印对话框),避免只报「连接客户端失败」而打不出票。 |
| | | // · printMode == null → 期望静默打印(本机有客户端时) |
| | | // · printMode != null → 明确要求浏览器打印(原逻辑保留) |
| | | // |
| | | // 【打印份数】hiprint 的入参数组长度 = 页数(每元素一页)。 |
| | | // 正式口径 = 2 张;份数只在 PRINT_COPIES 一处维护(1=测试省纸,3=三联)。 |
| | | const pages: any[] = Array.from({ length: PRINT_COPIES }, () => ({})) |
| | | if (printMode == null && (await waitPrintClientOpened(hiprintTemplate))) { |
| | | hiprintTemplate.print2(pages); // 静默打印(本机客户端) 可传 [定位参数] http://https://ccsimple.github.io/sv-print-docs/config/template.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E8%AE%BE%E8%AE%A1%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B |
| | | } else { |
| | | console.info('[printBill] 打印客户端未就绪,回退为浏览器打印,份数=' + PRINT_COPIES) |
| | | hiprintTemplate.print(pages); |
| | | } |
| | | } |
| | | /* hiprint 示例 |
| | | // 引入后使用示例 |