qx
qx
2025-04-03 a8c0679305c980a9878bc44a44408de9c00d3a64
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
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="体检号" prop="tjNumber">
        <el-input ref="inputName" v-model="queryParams.tjNumber" placeholder="请输入体检号" clearable
          @keyup.enter.native="handleQuery" @blur="hb" style="width: 170px" />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery"
          style="width: 110px" />
      </el-form-item>
      <el-form-item label="申请时间" prop="applicationTime">
        <el-date-picker v-model="createTimeList" @change="dateChangebirthday1" :default-time="['00:00:00', '23:00:00']"
          format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" range-separator="-"
          start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
      </el-form-item>
      <el-form-item label="单位名称" prop="compName" style="margin-left: 20px; margin-right: 500px">
        <el-select :remote-method="getRemoteData" v-model="queryParams.tjCompName" value-key="drugManufacturerId"
          style="width: 200px" remote filterable placeholder="请选择单位名称" clearable @change="searchSelect">
          <el-option v-for="dict in CompanyList" :key="dict.drugManufacturerId" :label="dict.cnName" :value="dict" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="是否采样" prop="isSignFor">
                    <el-select1 style="width:100px" v-model="queryParams.isSignFor" placeholder="是否采样">
                            <el-option v-for="dict in dict.type.sampling_type" :key="dict.value" :label="dict.label"
                                :value="dict.value"></el-option>
                        </el-select1>
            </el-form-item> -->
      <!-- <el-form-item label="体检时间" prop="tjTime">
                <el-date-picker clearable v-model="queryParams.tjTime" type="date" value-format="yyyy-MM-dd"
                    placeholder="请选择体检时间" style="width: 140px;">
                </el-date-picker>
            </el-form-item> -->
      <!-- <el-form-item label="项目id父项" prop="proId">
                <el-input v-model="queryParams.proId" placeholder="请输入项目id父项" clearable @keyup.enter.native="handleQuery" />
            </el-form-item> -->
      <!-- <el-form-item label="项目名称" prop="proName">
                <el-input v-model="queryParams.proName" placeholder="请输入项目名称" clearable @keyup.enter.native="handleQuery" style="width: 140px;"/>
            </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <!-- <el-button
          type="primary"
          icon="el-icon-thumb"
          size="mini" style="margin:0 15px;"
          @click="Confirmreceipt"
          >确认采样</el-button
        > -->
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="10">
        <el-radio-group v-model="tjStatus" @input="radioChange" style="margin: 10px 15px">
          <el-radio-button label="1" :disabled="qiehuan && disabledId === 0">未采样</el-radio-button>
          <el-radio-button label="0" :disabled="qiehuan && disabledId === 1">已采样</el-radio-button>
        </el-radio-group>
      </el-col>
      <el-col :span="12" style="margin: 10px 15px" v-if="samplingList.length > 0 && tjStatus == 1">
        <el-button type="primary" @click="Merging">合并项目</el-button>
        <!-- <el-button
          type="primary"
          icon="el-icon-thumb"
          style="margin: 0 15px"
          v-hasPermi="['hosp:detail:add']"
          @click="Confirmreceipt"
          >确认采样</el-button
        > -->
        <el-button type="primary" :disabled="!disabled" @click="Cancellation">撤销合并</el-button>
        <el-button type="primary" @click="Confirmreceipt" :disabled="!selectList.length">采样打码</el-button>
        <el-button type="primary" @click="piliangPrint" :disabled="!isAllSelected">批量打印</el-button>
      </el-col>
      <el-col :span="12" style="margin: 10px 15px" v-show="samplingList.length > 0 && tjStatus == 0">
        <el-button type="primary" :disabled="!selectList.length" @click="buda">补打条码</el-button>
        <!-- @click="Collection" -->
        <el-button type="primary" :disabled="!disabled" @click="Cancellation">撤销合并</el-button>
      </el-col>
    </el-row>
 
    <div style="width: 100%; margin-left: 10px; display: flex">
      <div style="width: 40%; margin-right: 20px">
        <el-table id="ta" v-loading="loading1" ref="tb" :data="samplingList" @selection-change="handleSelectionChange"
          border height="520px" :row-class-name="tableRowClassName">
          <el-table-column type="selection" width="40" align="center" :selectable="selectable" />
          <el-table-column label="体检号" align="center" prop="tjNumber" width="160px" />
          <el-table-column label="姓名" align="center" prop="cusName" width="80px" />
          <el-table-column label="性别" align="center" prop="cusSex" width="60px">
            <!-- <template slot-scope="scope">
              {{ scope.row.customer.cusSex === 0 ? "男" : "女" }}
            </template> -->
            <template slot-scope="scope">
              <span v-if="scope.row.cusSex == '0'">男</span>
              <span v-if="scope.row.cusSex == '1'">女</span>
              <span v-if="scope.row.cusSex == '2'">未知</span>
            </template>
          </el-table-column>
          <el-table-column label="手机号" align="center" prop="cusPhone" width="120px" />
          <el-table-column label="单位名称" align="center" prop="compName" width="120px" />
          <el-table-column label="申请时间" align="center" prop="applicationTime" width="210">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.applicationTime) }}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div style="width: 50%">
        <!-- v-if="this.rightTabShow" -->
        <el-table :row-key="getRowKey" v-if="tableList.length > 0" v-loading="loading" :data="tableList" @selection-change="handleChange"
          :span-method="objectSpanMethod" ref="tab1" :row-class-name="tableRowClassName" border height="520px">
          <el-table-column type="selection" width="40" align="center" />
          <!--  :selectable="selectEnable" -->
          <!-- <el-table-column label="是否签收" align="center" prop="isSignFor" /> -->
          <!-- <el-table-column label="体检时间" align="center" prop="tjTime" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.tjTime, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column> -->
          <el-table-column label="标本类型" align="center" prop="specimenType" width="120">
          </el-table-column>
          <el-table-column label="采样编号" align="center" prop="jyxh" :show-overflow-tooltip="true" width="120" />
          <el-table-column label="项目名称" align="center" prop="proName" />
          <!-- <el-table-column
            label="性别"
            align="center"
            prop="proSex"
            width="90"
          /> -->
          <el-table-column label="是否合并" align="center" prop="isMerge" width="90">
            <template slot-scope="scope">
              <span :style="{ color: scope.row.isMerge === 0 ? '' : '#409EFF' }">
                {{ scope.row.isMerge === 0 ? "未合并" : "已合并" }}
              </span>
            </template>
          </el-table-column>
 
          <!-- <el-table-column
            label="采样状态"
            align="center"
            prop="isSignFor"
            width="90"
          >
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.sampling_type"
                :value="scope.row.isSignFor"
              />
            </template>
          </el-table-column> -->
          <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['sampling:sampling:edit']">修改
                    </el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                        v-hasPermi="['sampling:sampling:remove']">删除
                    </el-button>
                </template>
            </el-table-column> -->
        </el-table>
      </div>
 
      <div id="printSection" style="display: none">
        <!-- 动态生成多个条形码的容器 -->
        <div v-for="(item, index) in selectList" :key="index">
          <svg :id="'barcode' + index"></svg>
          <div class="name">{{ getTruncatedName(item.proName).truncated }}</div>
          <div class="name1">
            {{ getTruncatedName(item.proName).remaining }}
          </div>
          <!-- <div class="name">{{ item.proName.slice(0, msg) }}</div>
          <div class="name1">
            {{ item.proName.slice(msg) }}
          </div> -->
          <div class="last">
            <p>{{ item.cusName }}</p>
            <div>
              <span>{{ item.customer.cusSex == 0 ? "男" : "女" }}</span>
              <span>{{ item.customer.age }}</span>
            </div>
          </div>
          <div class="tj">
            <span>体检中心</span>
            <!-- <span>{{ item.cardId.slice(0, 14) }}</span> -->
            <!-- <span>{{ item.cardId }}</span> -->
            <span>{{ item.cardId ? item.cardId.substring(0, 14) : "" }}</span>
          </div>
          <div class="tj">
            <span>{{ item.jyxh }}</span>
            <span>{{ formatDate(item.applicationTime) }}</span>
          </div>
        </div>
      </div>
    </div>
    <!-- 
        <div style="margin-right: 70%;">
            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList" />
        </div> -->
 
    <div style="margin-right: 50%">
      <!-- <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :pager-count="5" :current-page.sync="currentPage1" :current-page="page"
                :page-sizes="pageSize" :page-size="size" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination> -->
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
 
 
  </div>
</template>
 
<script>
import {
  listSampling,
  getSampling,
  getList,
  delSampling,
  addSampling,
  updateSampling,
  confirmSampling,
  getCusCyList,
  mergeCaiYang,
  chexiaoCaiYang,
  getTxmmccd,
  getTxmkd,
} from "@/api/sampling/sampling";
import { getNewDateList } from "@/api/hosp/order";
import moment from "moment";
import {
  SubmitCompany,
  getCompany,
  queryCompany,
  addbatch,
} from "@/api/team/tuanti";
export default {
  dicts: [
    "sys_user_sex",
    "sampling_type",
    "sys_dict_specimen",
    "dict_user_marry",
    "dict_user_national",
  ],
  name: "Sampling",
  data() {
    return {
      CheckBox: {},
 
      CompanyList: [],
      piliangList: [],
      msg: "",
      getNumbr: null,
      valueUrl: "ws://127.0.0.1/websocket",
      webSocket: null,
      list: [],
      selectList: [],
      selectedRows: [],
      createTimeList: [],
      // 遮罩层
      loading: true,
      loading1: true,
      // 选中数组
      ids: [],
      // 绑定单选按钮
      tjStatus: "1",
      dayinData: [],
      jsonObj: {},
 
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      page: 1,
      size: 2,
      currentPage1: 3,
      pageSize: [2, 4, 6, 8, 10],
      // 体检采样管理表格数据
      samplingList: [],
      tableList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        name: null,
        tjNumber: null,
        applicationTime: null,
        isSignFor: null,
        tjTime: null,
        specimenType: null,
        proId: null,
        proName: null,
      },
      startTime: "",
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // rightTabShow: false
      allSelected: false,
      disableSelections: false, // 控制选择禁用状态
    };
  },
  created() {
    // this.getNowTime();
    getTxmmccd().then((res) => {
      this.msg = Number(res.msg);
      console.log(res, 444);
    });
    getCompany(this.queryParams).then((response) => {
      this.CompanyList = response.data;
 
      this.loading = false;
    });
    this.getdate();
  },
  mounted() {
    this.$nextTick(() => {
      this.$refs.inputName.focus();
    });
  },
  computed: {
    disabled() {
      return (
        this.selectList.length > 0 &&
        this.selectList[this.selectList.length - 1].isMerge === 1
      );
    },
    qiehuan() {
      return this.selectList.length > 0;
    },
    disabledId() {
      return this.tjStatus == "1" ? 1 : 0;
    },
    isAllSelected() {
      return this.samplingList.length > 0 && this.selectedRows.length === this.samplingList.length;
    },
  },
 
  methods: {
    // 选框数据
    searchSelect(val) {
      this.CheckBox = val;
      this.queryParams.dw = this.CheckBox.drugManufacturerId;
      console.log(this.CheckBox, 9999);
    },
    getRemoteData(query) {
      if (query) {
        let compName = query;
        queryCompany(compName).then((response) => {
          this.CompanyList = response.data;
          this.CompanyList.forEach((item) => {
            this.queryParams = item;
          });
        });
      }
    },
    async piliangPrint() {
      // 检查是否有选中的数据
      if (this.piliangList.length === 0) {
        this.$message.warning('请先选择要打印的数据');
        return;
      }
 
      const loadingInstance = this.$loading({
        lock: true,
        text: '打印中...',
        spinner: 'el-icon-loading',
        background: 'rgba(255, 255, 255, 0.7)'
      });
 
      try {
        for (const item of this.piliangList) {
          try {
            // 获取数据,并等待数据更新完成
            const tableList = await this.fetchData(item.tjNumber);
 
            // 检查 tableList 是否有数据
            if (!tableList || tableList.length === 0) {
              console.error(`体检号 ${item.tjNumber} 无相关数据`);
              continue;
            }
 
            // 直接使用所有数据
            this.selectList = tableList;
 
            // 检查 selectList 是否有数据
            if (this.selectList.length === 0) {
              console.error(`体检号 ${item.tjNumber} 的 selectList 为空,跳过 WebSocket 操作`);
              continue;
            }
 
            // 使用更新后的 tableList 获取 ids
            let ids = this.selectList.map(row => row.id);
            if (ids.length === 0) {
              console.error(`体检号 ${item.tjNumber} 无有效 ID`);
              continue;
            }
 
            // 确认采样
            await this.Confirmreceipt1(ids);
 
            // 等待一段时间
            await new Promise(resolve => setTimeout(resolve, 5000));
          } catch (error) {
            console.error(`处理体检号 ${item.tjNumber} 时出错:`, error);
          }
        }
      } finally {
        this.ids = []; // 清空 ids
        this.selectList = []; // 清空 selectList
        loadingInstance.close();
      }
    },
    getTruncatedName(proName) {
      // 去掉所有空格
      const trimmedProName = proName.replace(/\s+/g, "");
 
      const number = this.msg;
 
      const truncated =
        trimmedProName.length > number
          ? trimmedProName.slice(0, number)
          : trimmedProName;
      let remaining =
        trimmedProName.length > number ? trimmedProName.slice(number) : "";
 
      if (remaining.length > number) {
        remaining = remaining.slice(0, number) + "...";
      }
      return { truncated, remaining }; // 返回结果
    },
 
    /* getTruncatedName(proName) {
      const trimmedProName = proName.replace(/\s+/g, ""); // 去掉所有空格
      const truncated =
        trimmedProName.length > 35
          ? trimmedProName.slice(0, 35)
          : trimmedProName;
      const remaining =
        trimmedProName.length > 35 ? trimmedProName.slice(35) : "";
      return { truncated, remaining };
    }, */
 
    // 示例的日期格式化方法
    formatDate(date) {
      const options = { year: "numeric", month: "2-digit", day: "2-digit" };
      return new Date(date).toLocaleDateString(undefined, options);
    },
    getdate() {
      getNewDateList().then((res) => {
        this.createTimeList = [
          moment(res.data).format("YYYY-MM-DD 00:00:00"),
          moment(res.data).format("YYYY-MM-DD 23:59:00"),
        ];
        this.getList();
      });
    },
    handleSizeChange(val) {
      this.size = val;
      this.page = 1;
      this.getList();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getList();
    },
    // / 处理默认选中当前日期
    getNowTime() {
      var curDate = new Date().getTime();
      var dayNum = 7 * 24 * 3600 * 1000;
      var threeDays = curDate - dayNum;
      var sDay = this.getLocalTime(threeDays);
      var end = this.getLocalTime(curDate);
      this.createTimeList = [sDay, end];
    },
    add0(m) {
      return m < 10 ? "0" + m : m;
    },
    getLocalTime(nS) {
      var time = new Date(nS);
      var y = time.getFullYear();
      var m = time.getMonth() + 1;
      var d = time.getDate();
      return y + "-" + this.add0(m) + "-" + this.add0(d);
    },
    dateChangebirthday1(val) {
      this.createTimeList = val;
    },
    formatDate(applicationTime) {
      // 确保 applicationTime 是有效的字符串
      if (applicationTime) {
        return applicationTime.split(" ")[0]; // 通过空格分隔日期和时间,只返回日期部分
      }
      return ""; // 如果 applicationTime 无效,返回空字符串
    },
    /** 查询体检采样管理列表 */
    /** 查询体检采样管理列表 */
getList() {
  this.queryParams.compId = this.CheckBox.drugManufacturerId;
  this.loading1 = true;
  this.queryParams.isSignFor = this.tjStatus;
 
  if (this.createTimeList) {
    this.queryParams.beginTime = this.createTimeList[0];
    this.queryParams.endTime = this.createTimeList[1];
  } else {
    this.queryParams.beginTime = null;
    this.queryParams.endTime = null;
  }
 
  getList(this.queryParams).then((response) => {
    this.loading1 = false;
    if (response.data && response.data.list && response.data.list.length > 0) {
      this.samplingList = response.data.list;
      this.total = response.data.total;
      // 移除默认选中第一行的逻辑
      // this.$nextTick(() => {
      //   this.$refs.tb.toggleRowSelection(this.samplingList[0], true); // 默认选中第一行
      //   this.fetchData(this.samplingList[0].tjNumber); // 刷新右侧表格
      // });
    } else {
      this.samplingList = [];
      this.tableList = [];
      this.selectList = []; // 清空 selectList
      this.ids = []; // 清空 ids
      if (this.$refs.tab1) {
        this.$refs.tab1.clearSelection(); // 清空右侧表格选中状态
      }
    }
    this.loading1 = false;
  });
},
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        samplingNumber: null,
        tjNumber: null,
        applicationTime: null,
        isSignFor: null,
        tjTime: null,
        specimenType: null,
        proId: null,
        proName: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        deleted: null,
      };
    },
    hb() {
      if (this.queryParams.tjNumber != null) {
        this.handleQuery();
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.createTimeList = []; // 清空日期范围
      this.queryParams.tjNumber = null; // 清空体检号
      this.queryParams.name = null; // 清空姓名
      this.queryParams.tjCompName = null; // 清空单位名称
      this.selectList = []; // 清空右侧选中项
      this.selectedRows = []; // 清空左侧选中项
      this.tableList = []; // 清空右侧表格数据
      this.ids = []; // 清空选中的 ID
      this.$refs.tb.clearSelection(); // 清空左侧表格选中状态
      if (this.$refs.tab1) {
        this.$refs.tab1.clearSelection(); // 清空右侧表格选中状态
      }
      this.handleQuery(); // 重新查询
    },
 
    handleSelectionChange(selection) {
      this.piliangList = selection;
      const selectedCount = selection.length;
      const totalCount = this.samplingList.length;
 
      // 如果只有一条数据,不要禁用选择,并展示右侧列表
      if (selectedCount === 1) {
        this.disableSelections = false;
        const selectedPerson = selection[0];
        const tjNumber = selectedPerson.tjNumber;
        console.log(`选中的体检号: ${tjNumber}`);
        this.fetchData(tjNumber);
      } else if (selectedCount === totalCount && selectedCount > 1) {
        // 全选时禁用选择新行
        this.disableSelections = true;
        this.tableList = [];
        this.$message.info('已全选所有行');
      } else {
        // 非全选时启用选择
        this.disableSelections = false;
        if (selectedCount > 1) {
          // 保留单选功能,取消多选
          let del_row = selection.shift();
          this.$refs.tb.toggleRowSelection(del_row, false);
        }
      }
 
      if (selectedCount === 0) {
        this.tableList = [];
      }
 
      // 更新单选和多选状态
      this.single = selectedCount === 1;
      this.multiple = selectedCount === 0;
 
      // 更新选中的行
      this.selectedRows = selection;
 
      // 调试日志
      console.log(`当前选中数量: ${selectedCount}`);
      console.log(`是否禁用选择: ${this.disableSelections}`);
    },
 
    getRowKey(row) {
      return row.id; // 必须唯一且稳定
    },
 
    fetchData(tjNumber) {
      return new Promise((resolve, reject) => {
        this.loading = true;
        getCusCyList(tjNumber, this.tjStatus)
          .then((response) => {
            if (response.data) {
              this.tableList = response.data;
              this.$nextTick(() => {
                if (this.$refs.tab1) {
                  this.$refs.tab1.doLayout(); // 修改为正确的 ref 名称
                  this.$refs.tab1.clearSelection(); // 清空选中状态
                }
              });
              resolve(this.tableList);
            } else {
              this.tableList = [];
              this.selectList = [];
              this.ids = [];
              if (this.$refs.tab1) {
                this.$refs.tab1.clearSelection();
              }
              resolve([]);
            }
          })
          .catch((error) => {
            console.error("Error fetching data:", error);
            reject(error);
          })
          .finally(() => {
            this.loading = false;
          });
      });
    },
 
    /* 点击合并按钮 */
    Merging() {
      // 检查是否选中了数据
      if (this.selectedRows.length === 0) {
        this.$message.error("至少选中一个人");
        return;
      }
      if (this.selectList.length === 0) {
        this.$message.error("请选择要合并项目");
        return;
      }
      if (this.selectList.every((item) => item.isMerge === 0)) {
        const baseSpecimenTypeCode = this.selectList[0].specimenTypeCode;
 
        // 检查 specimenTypeCode 是否一致
        const canMergeBySpecimenTypeCode = this.selectList.every(
          (row) => row.specimenTypeCode === baseSpecimenTypeCode
        );
 
        // 根据 canMergeBySpecimenTypeCode 判断是否合并
        if (canMergeBySpecimenTypeCode) {
          let data = this.ids;
 
          mergeCaiYang(data).then((response) => {
            this.$message.success("合并成功。");
            // console.log("合并的行:", this.selectedRows);
            // this.getList();
            this.fetchData(this.selectedRows[0].tjNumber);
          });
        } else {
          this.$message.error("标本类型不一致,无法合并!");
        }
      } else {
        this.$message.error("该项目已合并");
      }
    },
 
    /** 点击撤销按钮 **/
    Cancellation() {
      let data = this.ids;
      console.log("撤销");
      if (data.length === 0) {
        // 如果没有已合并的项目,给出提示信息
        this.$message.error("没有已合并的项目可以撤销!");
        return;
      }
 
      // console.log("撤销的已合并项目ID:", data);
 
      // 调用撤销采样的接口
      chexiaoCaiYang(data)
        .then((res) => {
          if (res && res.code === 200) {
            this.$message.success("撤销成功!");
            // 刷新数据列表或进行其他操作
            // this.getList();
            this.fetchData(this.selectedRows[0].tjNumber);
          } else {
            this.$message.error(res.msg || "撤销失败,请重试!");
          }
        })
        .catch((error) => {
          this.$message.error("请求失败,请重试!");
        });
    },
 
    /** 点击补打条码按钮 **/
    async Collection() {
      const jyxh = this.selectList.map((item) => item.jyxh);
      console.log("jyxh:", jyxh);
      try {
        // 请求接口并获取宽度值
        const widthResponse = await getTxmkd();
        const barcodeWidth = `${Number(widthResponse.msg)}%` || "70%"; // 获取宽度值,默认使用 70%
 
        jyxh.forEach((number, index) => {
          const barcodeContent = number; // 确保 jyxh 是有效的
          if (barcodeContent && barcodeContent !== "未提供体检号") {
            JsBarcode(`#barcode${index}`, barcodeContent, {
              format: "CODE128",
              width: 2,
              height: 50,
              displayValue: false,
            });
          } else {
            console.log(`条形码内容无效: ${barcodeContent}`); // 调试输出
          }
        });
 
        // await this.$nextTick();
 
        const barcodeElements = jyxh.map((_, index) =>
          document.querySelector(`#barcode${index}`)
        );
 
        if (barcodeElements) {
          barcodeElements.forEach((element) => {
            if (element) {
              console.log(element.innerHTML); // 打印条形码的内容,看看是否生成成功
            }
          });
        } else {
          console.log("条形码元素未找到");
        }
 
        const newWindow = window.open("", "_blank", "width=800,height=600");
        const printContents = document.getElementById("printSection").innerHTML;
 
        console.log(printContents);
        newWindow.document.write(`
      <html>
        <head>
          <title>Print Barcode</title>
          <style>
            @media print {
              * {
                margin: 0;
                padding: 0; /* 重置所有元素的 margin 和 padding */
                box-sizing: border-box; /* 使内边距和边框包含在元素的总宽度和高度内 */
              }
              .name, .name1, .last, .tj, .last div span, .last p, .tj span {
                font-family: Arial, sans-serif !important; /* 重新指定字体 */
                font-weight: bold !important; /* 强制加粗 */
              }
              body {
                margin: 0;
                padding: 0;
              }
              .barcode-container {
                // width: 100%; /* 根据需要调整 */
                // text-align: center; /* 确保条形码居中 */
              }
              .name, .name1 {
                padding: 0;
                font-size: 18px;
                width: 70%;
                font-family: "Arial Black", sans-serif; /* 设置黑体 */
              }
              p {
                margin: 0;
                padding: 0;
              }
              svg {
                display: block;
                width: ${barcodeWidth}; /* 使用从接口获取的宽度 */
                margin-left: 10mm;
                height: auto;
                margin-bottom: 0;
              }
              .last {
                width: 66%;
                display: flex;
                font-size: 19px;
                justify-content: space-between;
                // font-weight: bold;
                // font-family: "Arial Black", sans-serif !important; 
              }
              .last div span {
              // font-weight: bold;
                margin-left: 10px;
                // font-family: "Arial Black", sans-serif !important;
              }
              .last p {
              // font-weight: bold;
                margin-left: 1px; 
                // font-family: "Arial Black", sans-serif !important; 
              }
                p {
                margin-left: 1px; 
                // font-weight: bold;
                // font-family: "Arial Black", sans-serif !important;  
              }
              .tj {
                width: 70%;
                display: flex;
                font-size: 19px;
                justify-content: space-between;
                // font-weight: bold;
                 font-family: "Arial Black", sans-serif !important; 
              }
              .tj span {
                margin-left: 1px;
              }
            }
          </style>
        </head>
        <body>${printContents}</body>
      </html>
    `);
        newWindow.document.close();
        newWindow.focus();
        newWindow.print();
        newWindow.close();
      } catch (error) {
        console.error("获取宽度时出错:", error); // 捕获错误
      }
    },
 
    tableRowClassName({ row, rowIndex }) {
      for (let i = 0; i < this.selectList.length; i++) {
        if (row === this.selectList[i]) {
          return "warning-row";
        }
      }
    },
 
    handleChange(selection) {
      this.selectList = selection;
      var array = selection;
      this.ids = array.map((item) => item.id);
    },
    buda() {
      var websocket = null;
      var url = this.valueUrl;
      if ("WebSocket" in window) {
        websocket = new WebSocket(url);
      } else if ("MozWebSocket" in window) {
        websocket = new MozWebSocket(url);
      }
      if (websocket == null) {
        alert("创建WebSocket对象失败");
      }
      websocket.onerror = function () {
        alert("请检查读卡器连接是否正常");
      };
      websocket.onopen = () => {
        this.websocket = websocket;
        console.log(this.selectList, "this.selectList")
        this.dayinData = this.selectList.map((item) => ({
          jyxh: item.jyxh,
          proName: item.proName,
          cusName: item.cusName,
          cusSex: item.customer.cusSex,
          age: item.customer.age,
          cardId: item.cardId,
          tjTime: item.createTime,
        }));
 
 
        // 连接设备
        this.jsonObj = {
          type: "3",
          array: {
            data: this.dayinData,
          },
        };
        var jStr = JSON.stringify(this.jsonObj);
        console.log(jStr, "jStr");
 
        this.websocket.send(jStr);
        this.$refs.tab1.clearSelection(); // 清除右侧表格的选中状态
        this.selectList = []; // 清空 selectList
        this.ids = []; // 清空 ids
        this.jsonObj = {};
        // this.dialogVisible = false;
      };
      // this.getList();
    },
    // 确认采样
    Confirmreceipt() {
      const loadingInstance = this.$loading({
        lock: true,
        text: "加载中...",
        spinner: "el-icon-loading",
        background: "rgba(255, 255, 255, 0.7)",
      });
      confirmSampling(this.ids)
        .then((res) => {
          if (res.code === 200) {
            this.buda(); // 打印条码
 
            this.getList(); // 刷新左侧表格
            console.log("采样后 - selectList:", this.selectList, "qiehuan:", this.qiehuan);
          } else {
            this.$message.error(res.msg);
          }
        })
        .catch((error) => {
          console.error("采样失败:", error);
        })
        .finally(() => {
          loadingInstance.close();
        });
    },
    Confirmreceipt1(ids) {
      confirmSampling(ids)
        .then((res) => {
          if (res.code === 200) {
            this.buda();
            this.getList();
          } else {
            this.$message.error(res.msg);
          }
        })
        .catch((error) => {
        })
        .finally(() => {
          loadingInstance.close();
        });
    },
    // 单选按钮
   // 单选按钮
radioChange(value) {
  this.loading = true;
  this.queryParams.isSignFor = value;
  getList(this.queryParams).then((response) => {
    if (response.data) {
      if (response.data.list == null) {
        this.samplingList = [];
        this.tableList = [];
        this.loading = false;
      } else {
        this.samplingList = response.data.list;
        this.loading = false;
        // 移除默认选中第一行的逻辑
        // if (this.samplingList.length != 0) {
        //   this.$nextTick(() => {
        //     this.$refs.tb.toggleRowSelection(this.samplingList[0], true);
        //   });
        // } else {
        //   this.$refs.tb.clearSelection();
        // }
      }
      this.total = response.data.total;
      this.loading = false;
    } else {
      this.samplingList = [];
      this.tableList = [];
      this.loading = false;
    }
  });
},
 
    // 默认接受四个值 { 当前行的值, 当前列的值, 行的下标, 列的下标 }
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      let fields = ["specimenType"];
      let cellValue = row[column.property];
      if (cellValue && fields.includes(column.property)) {
        let prevRow = this.tableList[rowIndex - 1];
        let nextRow = this.tableList[rowIndex + 1];
        if (prevRow && prevRow[column.property] === cellValue) {
          return { rowspan: 0, colspan: 0 };
        } else {
          let countRowspan = 1;
          while (nextRow && nextRow[column.property] === cellValue) {
            nextRow = this.tableList[++countRowspan + rowIndex];
          }
          if (countRowspan > 1) {
            return { rowspan: countRowspan, colspan: 1 };
          }
        }
      }
    },
 
    // 导出
    handleExport() { },
 
    /** 控制行是否可选 */
    selectable(row, index) {
      if (this.disableSelections) {
        // 仅允许取消已选中的行
        return this.selectedRows.some(selectedRow => selectedRow.id === row.id);
      }
      return true; // 允许选择所有行
    },
 
    resetSelection() {
      this.$refs.tb.clearSelection();
      this.disableSelections = false;
      this.selectedRows = [];
      this.single = false;
      this.multiple = true;
      this.tableList = [];
 
      // 调试日志
      console.log(`重置选择,是否禁用选择: ${this.disableSelections}`);
    },
  },
};
</script>
 
<style>
#ta .el-table__header-wrapper .el-checkbox {
  /* display: none; */
}
 
.el-table .warning-row {
  background-color: #e5f3ff !important;
  /* font-weight: bold; */
}
</style>