yxh
yxh
10 天以前 09dc74e264b6262cbe41c9c8476e24705871d4a6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
<!--设备领用界面-->
<template>
 
<!--  当前患者: {{patient?.patId}} {{isStringEmpty(patient?.patName)?'无':patient.patName}}-->
 
    <el-form
      class="patient-compact-form"
      ref="formRef"
      :model="formData"
      :rules="formRules"
      label-width="100px"
      v-loading="formLoading"
   
    >
      <!-- ===== 编辑区(需要录入的字段)===== -->
      <el-row :gutter="20">
        <el-col :xs="24" :sm="12" :md="12" :lg="6">
          <el-form-item label="检查项目" prop="">
            {{getCheckTypeName(formData.checkType)}}
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="12" :lg="12">
          <el-form-item label="患者编号" prop="patId">
            <el-input v-model="formData.patId" placeholder="请输入患者编号" @input="getRentInfoByPatId" />
            <Barcode v-if="showBarCode" :value="barcodeContent" :width=100 />
            <el-button v-if="showCopyButton" :disabled="!barcodeContent" @click="copyBarcode()">复制</el-button>
          </el-form-item>
        </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-form-item>
        </el-col>
      </el-row>
 
      <!-- ===== 患者信息(需求1:18 项统一展示,一行四列)=====
           后端 DevRentRespVO 已从预约单平铺回填,setPatient 已赋值到 formData -->
      <PatientInfoBlock :data="formData" check-type-field="checkType" :span="6" />
 
      <!-- ===== 设备信息(一行四列)=====
           设备编号在上方编辑区已录入,此处只读展示其余设备字段 -->
      <DeviceInfoBlock :data="formData" :device="devInfo" time-label-mode="ready" :span="6">
        <template #rentTime>
          <el-date-picker
            v-model="formData.rentTime"
            type="date"
            value-format="x"
            placeholder="选择领用时间"
          />
        </template>
      </DeviceInfoBlock>
 
      <el-form-item label="备注" prop="remark">
        <el-input v-model="formData.remark" placeholder="请输入备注" />
      </el-form-item>
<!--
      <el-form-item label="缴费确认" prop="paid">
        <el-radio-group v-model="formData.paid">
          <el-radio key="1" :label="1"> 已缴费 </el-radio>
          <el-radio key="0" :label="0"> 未缴费 </el-radio>
        </el-radio-group>
      </el-form-item>
-->
        
    </el-form>
    <div class="patient-actions">
    <el-button size="small" @click="submitForm" type="primary" :disabled="formLoading">领用完成</el-button>
    <el-checkbox style="margin-left:10px" label="自动&nbsp;" v-model="autoPrint" />
    <el-button size="small" @click="printBill(formData.patDetails?.appointmentId)">打印小票</el-button>
    <el-button size="small" @click="cancelReady"  :disabled="formLoading">放弃领用</el-button>
    <el-button size="small" @click="resetForm()">重 置</el-button>
    <el-button size="small" v-if="needAutoFeeConfirm(formData.checkType)" @click="feeConfirm"  :disabled="formLoading">确费</el-button>
    <el-button size="small" v-if="needAutoFeeConfirm(formData.checkType)" @click="feeCancel"  :disabled="formLoading">取消确费</el-button>
    </div>
 
  <!-- 医生装机列表 -->
  <!-- 【本次需求】操作功能区与已完成记录之间的标题栏 -->
  <div class="records-title">
    <span class="records-title__bar"></span>
    <span class="records-title__text">已完成列表</span>
  </div>
  <div class="records-host">
    <ContentWrap class="records-wrap">
    <el-table
      v-loading="loading"
      :data="list"
      :stripe="true"
      :show-overflow-tooltip="true"
      @row-click="onRowClick"
    >
      <!-- 需求11(修正):「撤销」作为**已完成领用记录列表的第一列**(表头插槽),
           只出现一次,作用于最近一位已完成患者,语义与后端 lastFinishedPatient 一致。 -->
      <el-table-column label="撤销" align="center" width="90px" fixed="left">
        <template #header>
          <el-button
            link
            type="warning"
            :disabled="undoDisabled"
            :loading="undoLoading"
            @click="$emit('event_undo_finish')"
          >
            撤销
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="确费" align="center" prop="paid">
        <template #default="scope">
          {{scope.row.paid == 1 ? "已确费" : ""}}
        </template>
      </el-table-column>
      <el-table-column label="领用情况" align="center" prop="cancelled" >
        <template #default="scope">
          <!-- 【本需求】完成被撤销过:该条记录显示「已撤销」;再次完成时后端 undone 自动变回 false -->
          <el-tag v-if="scope.row.undone" type="danger" size="small">已撤销</el-tag>
          <span v-else-if="scope.row.jobType === 5">"已领用"</span>
          <span v-if="scope.row.jobType === 30">"已放弃"</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="作业类型" align="center" prop="jobType" />-->
<!--      <el-table-column label="医生编号" align="center" prop="docId" />-->
      <el-table-column label="医生名称" align="center" width="auto" prop="docName" />
      <el-table-column label="设备编号" align="center" prop="devId" />
<!--      <el-table-column label="患者编号" align="center" prop="patId" />-->
      <el-table-column label="患者名称" align="center" prop="patName" />
      <el-table-column
          label="作业时间"
          align="center"
          prop="jobTime"
          :formatter="dateFormatter"
          width="180px"
      />
<!--      <el-table-column label="作业概要" align="center" prop="summary" />-->
      <el-table-column label="备注" align="center" prop="remark" />
<!--
      <el-table-column
          label="创建时间"
          align="center"
          prop="createTime"
          :formatter="dateFormatter"
      />
-->
<!--
      <el-table-column label="操作" align="center" min-width="120px">
        <template #default="scope">
          <el-button
              link
              type="primary"
              @click="openForm('update', scope.row.id)"
              v-hasPermi="['ecg:job-record:update']"
          >
            编辑
          </el-button>
          <el-button
              link
              type="danger"
              @click="handleDelete(scope.row.id)"
              v-hasPermi="['ecg:job-record:delete']"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
-->
    </el-table>
    </ContentWrap>
    <!-- 分页 -->
    <Pagination
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />
  </div>
 
</template>
 
<script setup lang="ts">
import {defineComponent, PropType} from "vue";
import {Barcode} from "@/components/Barcode";
import { DevRentApi, DevRentVO } from '@/api/ecg/devrent'
import {QueueVO} from "@/api/ecg/queue";
import {isStringEmpty} from "@/utils/stringUtil";
import {dateFormatter} from "@/utils/formatTime";
import {JobRecordApi, JobRecordVO} from "@/api/ecg/jobrecord";
import {DeviceApi, DeviceVO} from "@/api/ecg/devmanage";
import {calculateAge, curDayEnd, curDayStart, formatTimestamp} from "@/utils/dateUtil";
import {RoomBedVO} from "@/api/ecg/doctor";
import {hiprint} from "vue-plugin-hiprint";
import {AppointmentApi, AppointmentVO} from "@/api/ecg/appointment";
import {useCheckTypeStore} from '@/store/modules/checkType'
import {calGender, getBookBeginTime} from "@/utils";
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import {tranlateDevState} from "@/utils/statusFormatter";
import {getCheckTypeName, needAutoFeeConfirm, needDevReady} from "../../../../utils/checkTypeFormatter";
import { useRoomStore } from '@/store/modules/room'
// 需求1:患者信息 18 项统一展示块
import PatientInfoBlock from "@/views/ecg/doctor/components/PatientInfoBlock.vue";
import DeviceInfoBlock from "@/views/ecg/doctor/components/DeviceInfoBlock.vue";
 
/** 设备领用 表单 */
defineComponent({ name: 'DevReadyPanel' })
 
const  props = defineProps({
  room: {
    type: Object as PropType<RoomBedVO>,
    required: true
  },
  /** 需求11:记录列表第一列「撤销」按钮的禁用态(由父页面控制) */
  undoDisabled: {
    type: Boolean,
    required: false,
    default: false
  },
  /** 需求11:记录列表第一列「撤销」按钮的 loading(由父页面控制) */
  undoLoading: {
    type: Boolean,
    required: false,
    default: false
  }
})
 
const emit = defineEmits(['event_dev_ready', 'event_undo_finish'])
 
const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
 
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
 
const autoPrint = ref<boolean>(true);
 
const checkTypeStore = useCheckTypeStore()
 
const formData = ref<DevRentVO>({
  id: undefined,
  devId: undefined,
  patId: undefined,
  patName: undefined,
  patDetails: undefined,
  checkType: undefined,
  rentTime: new Date().getTime(),
  returnTime: undefined,
  remark: undefined,
  paid: undefined,
})
 
const formRules = reactive({
  devId: [{ required: true, message: '设备编号不能为空', trigger: 'blur' }],
  rentTime: [{ required: true, message: '请选择装机日期', trigger: 'blur' }],
  patId: [{ required: true, message: '目前没有患者', trigger: 'blur' }],
  patName: [{ required: true, message: '目前没有患者', trigger: 'blur' }]
})
const formRef = ref() // 表单 Ref
 
const devInfo = ref<Partial<DeviceVO>>({
  category: undefined,
  brand: undefined,
  model: undefined,
  state: undefined,
})
 
 
const getRentInfoByPatId = () => {
  const tempPatId = formData.value.patId;
  resetForm()
  if (isStringEmpty(tempPatId))
    return
 
  formData.value.patId = tempPatId;
  getFreeRentInfo(formData.value)
}
 
// 根据患者或设备, 获取 Free的租赁
const getFreeRentInfo = async (devRentVO) => {
  if ((devRentVO.devId == null || devRentVO.devId === '') && (devRentVO.patId == null || devRentVO.patId === '') )
    return
 
  const data = await DevRentApi.getFreeRent(devRentVO)
  if (null === data)
    return
 
  // formDate 对应  DevRent
  // ⚠️ 原实现是整体替换 formData,会把患者信息冲成 null:
  //   实测 GET /ecg/dev-rent/get 的响应里,除 patName 外的患者字段全是 null
  //   (dev_rent 表不存这些列,且该路径未从 appointment 回填)。
  //   故改为「只覆盖非空字段」,保留已回填的患者信息(PatientInfoBlock 依赖)。
  const _merged = { ...formData.value } as Record<string, any>
  Object.keys(data as Record<string, any>).forEach((k) => {
    const v = (data as Record<string, any>)[k]
    if (v !== null && v !== undefined && v !== '') _merged[k] = v
  })
  formData.value = _merged as typeof formData.value
 
  // 领用时间  采用当前时间
  formData.value.rentTime = new Date().getTime()
}
 
/** 提交表单 */
const submitForm = async () => {
  // ==========================================================================
  // 【守卫】「设备领用」只受理**需要设备领用**的检查项目。
  //
  // 背景:`check_type.need_dev_ready`(是否需要设备领用)在后端**从未被校验**,
  // 医生可在本页手动输入患者编号,把**常规心电图(ct=100) / 常规心电向量图(ct=1100)**
  // 这类 needDevReady=0 的患者拉进来并点「领用完成」,
  // 表现为"常规心电图、心电向量图患者出现在设备领用模块"的混乱。
  //
  // 实测(真实接口):119/D1 等设备准备工位的 get-to-be-installed-list 返回空,
  // 说明**自动分流是按工位 checkTypes 过滤的、没有问题**;
  // 混乱来自"人工把不属于本流程的患者拉进来"。
  // ==========================================================================
  if (formData.value.checkType != null && !needDevReady(formData.value.checkType)) {
    const ctName = getCheckTypeName(formData.value.checkType) || String(formData.value.checkType)
    message.warning(
      `「${ctName}」不需要设备领用,不能在设备领用模块办理。` +
      `请确认是否应到「叫号检查」页面处理该患者。`
    )
    return
  }
 
  // 校验表单
  await formRef.value.validate()
  // 提交请求
  formLoading.value = true
  try {
    formData.value.roomId = props.room.roomId
    formData.value.bedNo = props.room.bedNo
    await DevRentApi.devReady(formData.value)
 
    if (autoPrint.value && formData.value.patId && formData.value.checkType) {
      printBill(formData.value.patDetails?.appointmentId)
    }
 
    // 自动确费
    if (needAutoFeeConfirm(formData.value.checkType)) {
      feeConfirm()
    }
 
    resetForm()
    getList()
 
    // 发送操作成功的事件
    emit('event_dev_ready')
    message.success(t('操作完成'))
  } finally {
    formLoading.value = false
  }
}
 
// 放弃领用
const cancelReady = async () => {
  formData.value.roomId = props.room.roomId
  formData.value.bedNo = props.room.bedNo
  const data = formData.value as unknown as DevRentVO
 
  await DevRentApi.devReadyCancel(data)
  message.success(t('操作成功'))
 
  // 发送操作成功的事件
  emit('event_dev_ready')
  resetForm()
  getList()
}
 
/** 重置表单 */
const resetForm = () => {
  formData.value = {
    devId: undefined,
    patId: undefined,
    patName: undefined,
    checkType: undefined,
    rentTime: new Date().getTime(),
    returnTime: undefined,
    tolerance: undefined,
    remark: undefined,
    patDetails: undefined,
    paid: undefined,
    // 需求1:PatientInfoBlock 依赖的平铺字段,先初始化为 undefined,
    // 随后由 setPatient 从 QueueVO 赋值(不初始化会读不到属性)
    applyNo: undefined,
    episodeId: undefined,
    patGender: undefined,
    patBirthday: undefined,
    registerDate: undefined,
    doctor: undefined,
    doctorTime: undefined,
    patSrc: undefined,
    patMobile: undefined,
    patPhone: undefined,
    patWardDesc: undefined,
    patBedNo: undefined,
    medicalCard: undefined,
    doctorAdviceNo: undefined,
    outpatientNo: undefined,
    patIdentityId: undefined,
    status: undefined,
    seqNum: undefined,
  }
  formRef.value?.resetFields()
 
  devInfo.value = {
    category: undefined,
    brand: undefined,
    model: undefined,
    state: undefined,
  }
}
 
const setPatient = (queueVO: QueueVO | undefined) => {
  resetForm()
  formData.value.applyNo = queueVO?.applyNo
  formData.value.episodeId = queueVO?.episodeId
  formData.value.patId = queueVO?.patId
  formData.value.patName = queueVO?.patName
  formData.value.checkType = queueVO?.bookCheckType
  formData.value.tolerance = queueVO?.tolerance // 多耐药,后端从预约单补齐
  // 需求1:以下平铺字段由后端从预约单回填到 QueueRespVO,
  // 必须显式赋值给 formData,否则模板里读不到(原先只赋值了上面 6 个)。
  formData.value.patGender = queueVO?.patGender
  formData.value.patBirthday = queueVO?.patBirthday
  formData.value.registerDate = queueVO?.registerDate
  formData.value.doctor = queueVO?.doctor
  formData.value.doctorTime = queueVO?.doctorTime
  formData.value.patSrc = queueVO?.patSrc
  // 【本次修复】条码/打印小票依赖 patDetails(含 source/appointmentId),
  // 队列行本就带着它;原先只在 getFreeRentInfo() 查到"待检查单"时才赋值,
  // 导致绝大多数情况下 patDetails 为 undefined → 条码不显示。
  formData.value.patDetails = queueVO?.patDetails
  formData.value.patMobile = queueVO?.patMobile
  formData.value.patPhone = queueVO?.patPhone
  formData.value.patWardDesc = queueVO?.patWardDesc
  formData.value.patBedNo = queueVO?.patBedNo
  formData.value.medicalCard = queueVO?.medicalCard
  formData.value.outpatientNo = queueVO?.outpatientNo
    // 需求1:医嘱号(此前 3 个面板都遗漏了该字段的赋值,导致 PatientInfoBlock 恒显示 '-')
    formData.value.doctorAdviceNo = queueVO?.doctorAdviceNo
  formData.value.patIdentityId = queueVO?.patIdentityId
  getFreeRentInfo(formData.value)  // 待检查的信息  @ dev_rent 表
}
defineExpose({ setPatient, getList: () => getList() }) // 提供 setPatient 方法,用于设置患者
 
 
const loading = ref(true) // 列表的加载中
const list = ref<JobRecordVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
// 当前诊室信息(用于取诊室开展的检查项目做兜底,见 syncRoomCheckTypes)
const roomStore = useRoomStore()
 
 
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  jobType: [5, 30],
  docId: undefined,
  docName: undefined,
  devId: undefined,
  patId: undefined,
  patName: undefined,
  jobTime: [curDayStart(), curDayEnd()],
  summary: undefined,
  remark: undefined,
  createTime: [],
  // ========================================================================
  // 按**当前诊室开展的检查项目**隔离已完成记录。
  //
  // 背景:`job_record` 表只有 doc_id + check_type,**没有 room_id**;
  // 而 /ecg/job-record/doctor-page 是强制按登录医生查"自己的记录"。
  // 于是同一医生在多个诊室坐诊时(如 1号门诊 ct=[100,1100]、6号门诊 ct=[400] 平板运动心电),
  // 叫号检查页会把**多个诊室的记录混在一起**显示 —— 正是用户反馈的现象。
  //
  // 由各页面(Routine.vue / index.vue / DevInstall.vue)在 onMounted 时
  // 用当前诊室的 checkTypes 赋值,并在每次查询前同步,确保切诊室后立即生效。
  // ========================================================================
  checkTypes: undefined as number[] | undefined
})
 
/**
 * 把「当前诊室开展的检查项目」同步到查询条件,实现已完成记录按诊室隔离。
 * 见 queryParams.checkTypes 的说明。
 */
const syncRoomCheckTypes = () => {
  // 优先用页面传入的诊室信息;为空时回退到 store(更可靠,见 TitlePanel 同处说明)
  const fromProp = props.room?.checkTypes
  const types = (Array.isArray(fromProp) && fromProp.length > 0)
    ? fromProp
    : roomStore.room?.checkTypes
  queryParams.checkTypes = (Array.isArray(types) && types.length > 0) ? [...types] : undefined
}
 
 
/** 查询列表 */
const getList = async () => {
  // 查询前同步当前诊室开展的检查项目,保证只显示本诊室的记录
  syncRoomCheckTypes()
  loading.value = true
  try {
    const data = await JobRecordApi.getJobRecordDoctorPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}
 
const onRowClick = (cur) => {
  if (cur !== null)
    getSelectedRent( cur.rentId )
}
 
const getSelectedRent = async (rentId) => {
  const data = await DevRentApi.getDevRent(rentId)
 
  formData.value = data
 
  devInfo.value.category = data.category
  devInfo.value.brand = data.brand
  devInfo.value.model = data.model
  devInfo.value.state = data.devState
}
 
const printBill = async (appointmentId: number | null | undefined, printMode?: number) => {
  if ( appointmentId == null )
    return
 
  const curAppointment: AppointmentVO = await AppointmentApi.getAppointment( appointmentId )
 
// 引入后使用示例
  hiprint.init({
    //    host: 'http://192.168.2.100:17521',
    token: '111111'
  });
// 下列方法都是没有拖拽设计页面的, 相当于代码模式, 使用代码设计页面
// 想要实现拖拽设计页面,请往下看 '自定义设计'
  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});
//文本
  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', } });
  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' } });
 
//打印
  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 示例
// 引入后使用示例
  hiprint.init({
    //    host: 'http://192.168.2.100:17521',
    token: '111111'
  });
// 下列方法都是没有拖拽设计页面的, 相当于代码模式, 使用代码设计页面
// 想要实现拖拽设计页面,请往下看 '自定义设计'
  var hiprintTemplate = new hiprint.PrintTemplate();  // 可传参数
  var panel = hiprintTemplate.addPrintPanel({ width: 100, height: 130, paperFooter: 340, paperHeader: 10 });
//文本
  panel.addPrintText({ options: { width: 140, height: 15, top: 20, left: 20, title: 'hiprint插件手动添加text', textAlign: 'center' } });
//条形码
  panel.addPrintText({ options: { width: 140, height: 35, top: 40, left: 20, title: '123456', textType: 'barcode' } });
//二维码
  panel.addPrintText({ options: { width: 35, height: 35, top: 40, left: 165, title: '123456', textType: 'qrcode' } });
//长文本
  panel.addPrintLongText({ options: { width: 180, height: 35, top: 90, left: 20, title: '长文本:hiprint是一个很好的webjs打印,浏览器在的地方他都可以运行' } });
//打印 直接打印
  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
*/
/* 分页打印
HiPrint.print({
  pages: [
    {
      text: 'Hello World!'
    },
    {
      html: '<div><h1>Hello World!</h1></div>',
      pageBreak: true
    },
    {
      image: 'image.png'
    }
  ]
});
*/
 
const getDevInfo = async () => {
  if (formData.value?.devId == null) {
    devInfo.value.brand = undefined
    devInfo.value.model = undefined
    devInfo.value.state = undefined
    return
  }
 
  const data = await DeviceApi.getDeviceByDevId(formData.value.devId!)
  if ( null !== data)
    devInfo.value = data
}
 
const feeConfirm = async () => {
  if (formData.value.id == null) {
    message.error('请先领用')
    return
  }
 
 try {
    const result = await DevRentApi.feeConfirm(formData.value.id)
    if (0 === result) {
      //message.success('确费操作成功')
    }
  } catch (err) {
    // 框架 会给出 后台的 错误信息
  }
}
 
const feeCancel = async () => {
  if (formData.value.id == null) {
    message.error('请先领用')
    return
  }
 
  try {
    const result = await DevRentApi.feeCancel(formData.value.id)
    if (0 === result) {
      //message.success('确费取消成功')
    }
  } catch (err) {
    // 框架 会给出 后台的 错误信息
  }
}
 
/**
 * 获取条形码,显示与否  同一个值
 */
/**
 * 【本需求】患者条码口径(门诊/急诊/体检 = 就诊流水号;住院不出条码,只留「复制」)
 *
 *  · 门诊(1) / 急诊(2) / 体检(4) → 条码内容 = **就诊流水号**(episodeId)
 *  · 住院(3)                    → **不显示条码**,只保留「复制」按钮(复制内容同样是就诊流水号)
 *  · 「复制」按钮与条码一致:同受「检查类型 → 患者条码显示」配置控制
 *    (该检查类型未勾选这个患者来源时,条码和复制按钮都不显示)
 */
const patSourceValue = computed<number | null>(() => {
  const source = formData.value.patDetails?.source ?? formData.value.patSrc
  return source === null || source === undefined || source === '' ? null : Number(source)
})
 
/** 是否通过了「患者条码显示」配置(勾选了当前患者来源) */
const barcodeEnabled = computed<boolean>(() => {
  if (formData.value.checkType == null) return false
  const displayBarcode: number[] | undefined = checkTypeStore.getCheckTypeDispBarCode(formData.value.checkType)
  if (displayBarcode == null || displayBarcode.length === 0) return false
  const patSource = patSourceValue.value
  if (patSource == null) return false
  return displayBarcode.map(Number).includes(patSource)
})
 
/** 条码 / 复制的内容:统一取「就诊流水号」 */
const barcodeContent = computed<string>(() =>
  barcodeEnabled.value ? (formData.value.episodeId ?? '') : ''
)
 
/** 是否显示条码:住院(来源 3)不显示;内容为空时也不显示 */
const showBarCode = computed<boolean>(
  () => barcodeEnabled.value && patSourceValue.value !== 3 && barcodeContent.value !== ''
)
 
/** 是否显示「复制」按钮:与条码一致(同受配置控制) */
const showCopyButton = computed<boolean>(() => barcodeEnabled.value)
 
const copyBarcode = async () => {
  if (!barcodeContent.value) return
  await navigator.clipboard.writeText(barcodeContent.value)
}
 
/** 初始化 **/
onMounted(() => {
  getList()
})
 
</script>
 
<style scoped lang="scss">
 
/* 【本次需求】「已完成列表」标题栏:左侧主色竖线 + 加粗小标题,紧凑高度不挤压表格 */
.records-title {
  display: flex;
  align-items: center;
  flex: none;
  gap: 6px;
  padding: 2px 0 6px;
 
  &__bar {
    width: 3px;
    height: 14px;
    background-color: var(--el-color-primary);
    border-radius: 2px;
  }
 
  &__text {
    font-size: 14px;
    font-weight: 600;
    color: var(--el-text-color-primary);
  }
}
/* ==========================================================================
   需求:表单内容挤占了下方记录表格的空间 —— 压缩行间距。
   Element Plus 默认 `.el-form-item { margin-bottom: 18px }`;
   本页表单含 18 项患者信息(4 列 = 5 行)+ 9 项设备信息,
   仅间距就要上百 px,把 el-table 挤到看不见。
   这里统一压到 4px。注意 :deep 是必需的(el-form-item 是本组件的子组件渲染)。
   ========================================================================== */
.patient-compact-form :deep(.el-form-item) {
  margin-bottom: 4px;
}
 
/* ==========================================================================
   患者信息固定在内容区顶部。
   内容区自身不滚动(滚动条在记录表格上),因此**不需要 position:sticky** ——
   直接作为 flex 的固定项(flex:none)即可始终留在顶部。
   背景不透明,保证与下方记录表格视觉分离。
   ========================================================================== */
:deep(.doctor-page__content) > .patient-compact-form {
  flex: none;
  padding-bottom: 4px;
  background-color: var(--el-bg-color);
  border-bottom: 1px solid var(--el-border-color-lighter);
}
 
 
 
/* ==========================================================================
   患者信息固定在内容区顶部。
   内容区(.doctor-page__content)自身滚动,所以这里必须用 position:sticky
   才能让 18 项患者信息在记录列表滚动时保持可见。
   背景不透明,避免滚动内容从表单项间隙透出。
   ========================================================================== */
:deep(.doctor-page__content) > .patient-compact-form {
  position: sticky;
  top: 0;
  z-index: 3;
  padding-bottom: 4px;
  background-color: var(--el-bg-color);
  border-bottom: 1px solid var(--el-border-color-lighter);
}
 
/* ==========================================================================
   患者操作功能块:位于「患者信息」与「已完成记录列表」之间,独立成块。
   需求:各功能按钮(检查完成 / 放弃检查 / 重置 / 知情同意书 …)**排在一行**。
   做法:flex + gap,并 **禁止换行**(flex-wrap:nowrap);
   按钮用 size="small" 以容纳全部按钮;即使宽度不足也不折行。
   上下边框 + 底色,使它与患者信息、记录列表在视觉上分区。
   ========================================================================== */
.patient-actions {
  display: flex;
  flex: none;
  /* 按钮多时允许换行,避免挤在一行(检查页最多 6 个按钮) */
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  /*
    【本次需求】操作功能区做一点视觉区分,方便医生一眼定位:
    极浅的主色底 + 细边框 + 左侧 3px 主色竖条(与「▎已完成列表」标题条同款语言)。
    只做"稍有区分",不改按钮本身的尺寸/颜色/顺序。
  */
  padding: 8px 10px;
  margin: 2px 0 10px;
  background-color: var(--el-color-primary-light-9);
  border: 1px solid var(--el-color-primary-light-7);
  border-left: 3px solid var(--el-color-primary);
  border-radius: 4px;
 
  /* Element Plus 给相邻 el-button 默认加了 margin-left:12px,会与 gap 叠加,清掉 */
  :deep(.el-button + .el-button) {
    margin-left: 0;
  }
}
</style>