yxh
9 天以前 be27214928a43cacff975265a7c67e2e2461fd0c
src/views/ecg/doctor/components/DevReadyPanel.vue
@@ -28,7 +28,7 @@
        </el-col>
        <el-col :xs="24" :sm="12" :md="12" :lg="6">
          <el-form-item label="设备编号" prop="devId">
            <el-input v-model="formData.devId" placeholder="请输入设备编号" @input="getDevInfo"/>
            <el-input v-model="formData.devId" :placeholder="requireDevId ? '请输入设备编号' : '可留空'" @input="getDevInfo"/>
          </el-form-item>
        </el-col>
      </el-row>
@@ -81,11 +81,14 @@
  </div>
  <div class="records-host">
    <ContentWrap class="records-wrap">
    <div class="records-scroll">
    <el-table
      v-loading="loading"
      :data="list"
      :stripe="true"
      :show-overflow-tooltip="true"
      highlight-current-row
      @current-change="onCurrentRowChange"
      @row-click="onRowClick"
    >
      <!-- 需求11(修正):「撤销」作为**已完成领用记录列表的第一列**(表头插槽),
@@ -97,7 +100,8 @@
            type="warning"
            :disabled="undoDisabled"
            :loading="undoLoading"
            @click="$emit('event_undo_finish')"
            title="先在下方点选一条完成记录,再点此撤销"
            @click="undoSelected"
          >
            撤销
          </el-button>
@@ -115,6 +119,10 @@
          <span v-else-if="scope.row.jobType === 5">"已领用"</span>
          <span v-if="scope.row.jobType === 30">"已放弃"</span>
        </template>
      </el-table-column>
      <!-- 【2026-11-25 需求】同一患者可能有多个检查项目,已完成列表列出来才能区分/精确撤销 -->
      <el-table-column label="检查项目" align="center" width="150">
        <template #default="scope">{{ getCheckTypeName(scope.row.checkType) }}</template>
      </el-table-column>
<!--      <el-table-column label="作业类型" align="center" prop="jobType" />-->
<!--      <el-table-column label="医生编号" align="center" prop="docId" />-->
@@ -162,6 +170,7 @@
      </el-table-column>
-->
    </el-table>
    </div>
    </ContentWrap>
    <!-- 分页 -->
    <Pagination
@@ -191,6 +200,8 @@
import {calGender, getBookBeginTime} from "@/utils";
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import {tranlateDevState} from "@/utils/statusFormatter";
import { copyText } from '@/utils/copyText'
import { getConfigKey } from '@/api/infra/config'
import {getCheckTypeName, needAutoFeeConfirm, needDevReady} from "../../../../utils/checkTypeFormatter";
import { useRoomStore } from '@/store/modules/room'
// 需求1:患者信息 18 项统一展示块
@@ -249,6 +260,29 @@
  patId: [{ required: true, message: '目前没有患者', trigger: 'blur' }],
  patName: [{ required: true, message: '目前没有患者', trigger: 'blur' }]
})
/**
 * 【系统参数】动态血压和心电设备领用安装登记设备编号
 *   值“是”(默认)→ 设备编号必填;
 *   值“否”       → 允许不填(校验规则同步放开)。
 */
const requireDevId = ref(true)
const loadDevIdRequired = async () => {
  try {
    const value = await getConfigKey('ecg.dev.rent.device.no.required')
    const text = String(value ?? '').trim()
    requireDevId.value = !(
      text === '否' || text === '0' ||
      text.toLowerCase() === 'false' || text.toLowerCase() === 'no'
    )
  } catch (e) {
    console.warn('[DevReadyPanel] 读取“设备编号必填”系统参数失败,按必填处理', e)
    requireDevId.value = true
  }
  formRules.devId = requireDevId.value
    ? [{ required: true, message: '设备编号不能为空', trigger: 'blur' }]
    : []
}
const formRef = ref() // 表单 Ref
const devInfo = ref<Partial<DeviceVO>>({
@@ -314,7 +348,7 @@
      `「${ctName}」不需要设备领用,不能在设备领用模块办理。` +
      `请确认是否应到「叫号检查」页面处理该患者。`
    )
    return
    return false
  }
  // 校验表单
@@ -327,7 +361,12 @@
    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)
      }
    }
    // 自动确费
@@ -341,6 +380,7 @@
    // 发送操作成功的事件
    emit('event_dev_ready')
    message.success(t('操作完成'))
    return true
  } finally {
    formLoading.value = false
  }
@@ -436,7 +476,18 @@
  formData.value.patIdentityId = queueVO?.patIdentityId
  getFreeRentInfo(formData.value)  // 待检查的信息  @ dev_rent 表
}
defineExpose({ setPatient, getList: () => getList() }) // 提供 setPatient 方法,用于设置患者
/**
 * 【叫号自动完成】供父页面点「叫号」时先自动完成当前患者(等同点「领用完成」)。
 */
const completeCurrent = async (): Promise<boolean> => {
  try {
    return (await submitForm()) === true
  } catch (e) {
    console.warn('[DevReadyPanel] 自动「领用完成」失败', e)
    return false
  }
}
defineExpose({ setPatient, getList: () => getList(), completeCurrent }) // 提供 setPatient 方法,用于设置患者
const loading = ref(true) // 列表的加载中
@@ -496,9 +547,29 @@
    const data = await JobRecordApi.getJobRecordDoctorPage(queryParams)
    list.value = data.list
    total.value = data.total
    // 列表刷新后旧的选中行已失效,清掉,避免「撤销」作用到上一屏的记录
    selectedRecord.value = undefined
  } finally {
    loading.value = false
  }
}
/** 【2026-11-25 需求】已完成列表的选中行:撤销前先点选一条,撤销作用在选中记录上 */
const selectedRecord = ref<any>()
const onCurrentRowChange = (row: any) => {
  selectedRecord.value = row || undefined
}
/** 撤销:只撤销当前选中的那条完成记录(未选中时提示,不再默认撤销"最近一条") */
const undoSelected = () => {
  if (!selectedRecord.value) {
    message.warning('请先在「已完成列表」中点选一条记录,再点「撤销」')
    return
  }
  emit('event_undo_finish', {
    ...selectedRecord.value,
    checkTypeName: getCheckTypeName(selectedRecord.value.checkType)
  })
}
const onRowClick = (cur) => {
@@ -517,9 +588,34 @@
  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 )
@@ -531,27 +627,126 @@
// 下列方法都是没有拖拽设计页面的, 相当于代码模式, 使用代码设计页面
// 想要实现拖拽设计页面,请往下看 '自定义设计'
  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 示例
// 引入后使用示例
@@ -592,7 +787,8 @@
*/
const getDevInfo = async () => {
  if (formData.value?.devId == null) {
  // 设备编号允许留空(系统参数=否)时,空值不再去查设备,避免无意义请求/报错
  if (!formData.value?.devId) {
    devInfo.value.brand = undefined
    devInfo.value.model = undefined
    devInfo.value.state = undefined
@@ -677,12 +873,19 @@
const copyBarcode = async () => {
  if (!barcodeContent.value) return
  await navigator.clipboard.writeText(barcodeContent.value)
  // 【兼容 Chrome 85 / http 访问】非安全上下文下 navigator.clipboard 不可用,用兼容实现
  const ok = await copyText(barcodeContent.value)
  if (ok) {
    message.success('已复制')
  } else {
    message.warning('当前浏览器不支持自动复制,请手动选中复制')
  }
}
/** 初始化 **/
onMounted(() => {
  getList()
  loadDevIdRequired()
})
</script>
@@ -705,7 +908,7 @@
  }
  &__text {
    font-size: 14px;
    font-size: 15px;
    font-weight: 600;
    color: var(--el-text-color-primary);
  }
@@ -782,4 +985,22 @@
    margin-left: 0;
  }
}
/* ==========================================================================
   【2026-11-25 需求】已完成列表:只显示 4 行左右,超过就出现纵向滚动条
   (实测行高 40px、表头 63px → 63 + 4×40 + 2 = 225px)。
   ========================================================================== */
.records-scroll {
  max-height: 225px;
  min-height: 120px;
  overflow-y: auto;
  overflow-x: hidden;
  :deep(.el-table__header-wrapper) {
    position: sticky;
    top: 0;
    z-index: 2;
    background-color: var(--el-bg-color);
  }
}
</style>