董国庆
2026-05-18 e6bf6b85a32b5c394a7ae26d2a49c5ac6280e377
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
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
<template>
  <div>
    <HeaderBox :title="projectName" />
    <div class="pt--35 px--20 pb--54">
      <!-- 返回 -->
      <div class="flex a-center">
        <img
          @click="backFun"
          src="../../assets/img/back.png"
          class="w--22 h--20 shrink0 mr--13 cursor-pointer"
        />
        <div @click="backFun" class="c-fff lh--22 fs--22 SHSBold cursor-pointer">设备列表</div>
      </div>
      <!-- 搜索 -->
      <div class="flex a-center gap--16 mt--24 mb--20">
        <!-- 项目选择(委托方才显示) -->
        <div
          v-if="isClientMode"
          class="flex a-center j-between pl--18 pr--15 h--40 relative w--300 bgcolor1 searchBox"
        >
          <el-select
            filterable
            v-model="projectId"
            placeholder="请选择项目"
            class="flex1"
            @change="handleProjectChange"
          >
            <el-option
              v-for="item in projectList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <div class="flex a-center gap--5">
            <i
              @click.stop="clearProjectSelect"
              class="el-icon-circle-close c-fff cursor-pointer"
              v-show="projectId"
            />
            <img
              src="../../assets/img/down-circle@2x.png"
              class="w--15 h--16 shrink0"
            />
          </div>
        </div>
 
        <div
          class="flex a-center j-between pl--18 pr--15 h--40 relative w--300 bgcolor1 searchBox"
        >
          <el-select
            filterable
            v-model="type"
            placeholder="请选择设备类型"
            class="flex1"
            @change="handleSearch"
          >
            <el-option
              v-for="item in deviceTypeList"
              :key="item.code"
              :label="item.name"
              :value="item.code"
            >
            </el-option>
          </el-select>
          <div class="flex a-center gap--5">
            <i
              @click.stop="clearDeviceType"
              class="el-icon-circle-close c-fff cursor-pointer"
              v-show="type"
            />
            <img
              src="../../assets/img/down-circle@2x.png"
              class="w--15 h--16 shrink0"
            />
          </div>
        </div>
        <div
          class="flex a-center j-between px--20 w--300 h--40 relative bgcolor1 picker"
        >
          <el-date-picker
            v-model="dateTime"
            ref="datetime1"
            type="datetime"
            placeholder=""
            @change="handleSearch"
            clearable
          >
          </el-date-picker>
          <div
            @click.stop="handleClick(1)"
            class="absolute h100 flex a-center c-fff fs--14 SHS pointer-events-none"
            style="left: 20px; right: 60px; z-index: 1"
            v-if="startTime"
          >
            {{ startTime }}
          </div>
          <div
            @click.stop="handleClick(1)"
            v-else
            class="absolute h100 flex a-center c-fff fs--14 SHSR pointer-events-none"
            style="left: 20px; right: 60px; z-index: 1"
          >
            请选择日期
          </div>
          <div
            class="flex a-center gap--5"
            style="position: relative; z-index: 2"
          >
            <i
              @click.stop="clearStartTime"
              class="el-icon-circle-close c-fff cursor-pointer"
              v-show="dateTime"
            />
            <img
              @click="handleClick(1)"
              src="../../assets/img/home/Shape@2x (6).png"
              class="w--13 h--13 shrink0 cursor-pointer"
            />
          </div>
        </div>
        <div
          class="flex a-center j-between px--20 w--300 h--40 relative bgcolor1 picker"
        >
          <el-date-picker
            v-model="dateTime2"
            ref="datetime2"
            type="datetime"
            placeholder=""
            @change="handleSearch"
            clearable
          >
          </el-date-picker>
          <div
            @click="handleClick(2)"
            class="absolute h100 flex a-center c-fff fs--14 SHS pointer-events-none"
            style="left: 20px; right: 60px; z-index: 1"
            v-if="endTime"
          >
            {{ endTime }}
          </div>
          <div
            @click="handleClick(2)"
            v-else
            class="absolute h100 flex a-center c-fff fs--14 SHSR pointer-events-none"
            style="left: 20px; right: 60px; z-index: 1"
          >
            请选择日期
          </div>
          <div
            class="flex a-center gap--5"
            style="position: relative; z-index: 2"
          >
            <i
              @click.stop="clearEndTime"
              class="el-icon-circle-close c-fff cursor-pointer"
              v-show="dateTime2"
            />
            <img
              @click="handleClick(2)"
              src="../../assets/img/home/Shape@2x (6).png"
              class="w--13 h--13 shrink0 cursor-pointer"
            />
          </div>
        </div>
        <div
          class="flex a-center j-between w--300 pl--20 h--40 relative bgcolor1 searchBox"
        >
          <el-input
            v-model="content"
            placeholder="请输入搜索内容"
            class="flex1"
            clearable
            @keyup.enter.native="handleSearch"
          ></el-input>
          <div class="btn SHSR" @click="handleSearch">搜索</div>
        </div>
      </div>
      <!-- 表格 -->
      <CustomTable
        :data="tableList"
        height="800"
        style="border: 2px solid #3d7fff"
      >
        <el-table-column
          v-if="isClientMode"
          label="项目名称"
          prop="projectName"
        />
        <el-table-column label="设备类型" prop="type">
          <template #default="{ row }">
            <div>{{ getDeviceTypeName(row.type) }}</div>
          </template>
        </el-table-column>
        <el-table-column label="设备编号" prop="name" />
        <el-table-column label="设备出厂日期" prop="createTime">
          <template #default="{ row }">
            <div>
              {{
                getPropertyValue(row, "设备出厂日期") || row.createTime || "-"
              }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="使用单位" prop="projectName">
          <template #default="{ row }">
            <div class="flex flex-column gap--4">
              <div
                v-for="(item, index) in getPropertyValues(row, '使用单位')"
                :key="index"
              >
                {{ item }}
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="工程起重机械生产单位">
          <template #default="{ row }">
            <div class="flex flex-column gap--4">
              <div
                v-for="(item, index) in getPropertyValues(
                  row,
                  '工程起重机械生产单位'
                )"
                :key="index"
              >
                {{ item }}
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="工程起重机械租赁单位">
          <template #default="{ row }">
            <div class="flex flex-column gap--4">
              <div
                v-for="(item, index) in getPropertyValues(
                  row,
                  '工程起重机械租赁单位'
                )"
                :key="index"
              >
                {{ item }}
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="工程起重机械维保单位">
          <template #default="{ row }">
            <div class="flex flex-column gap--4">
              <div
                v-for="(item, index) in getPropertyValues(
                  row,
                  '工程起重机械维保单位'
                )"
                :key="index"
              >
                {{ item }}
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="工程起重机械安拆单位">
          <template #default="{ row }">
            <div class="flex flex-column gap--4">
              <div
                v-for="(item, index) in getPropertyValues(
                  row,
                  '工程起重机械安拆单位'
                )"
                :key="index"
              >
                {{ item }}
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="本月检查情况" prop="checkResult">
          <template #default="{ row }">
            <div class="flex a-center j-center">
              <div class="ripple">
                <div
                  class="ripple-wave wave-1"
                  :class="{ bgColor3: row.checkResult === '已检查' }"
                ></div>
                <div
                  class="ripple-wave wave-2"
                  :class="{ bgColor4: row.checkResult === '已检查' }"
                ></div>
                <div
                  class="ripple-wave wave-3"
                  :class="{ bgColor5: row.checkResult === '已检查' }"
                ></div>
              </div>
              <div class="ml--6 SHSR">{{ row.checkResult }}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="最近一次检查时间" prop="checkTime" />
        <el-table-column label="操作">
          <template #default="{ row }">
            <el-button
              @click="toHiddenDanger(row, 3)"
              type="text"
              class="btnColor"
              >隐患</el-button
            >
            <el-button
              type="text"
              class="btnColor"
              @click="openDetailDialog(row)"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </CustomTable>
      <CustomPagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="total"
      />
    </div>
    <!-- 项目列表弹窗 -->
    <CustomDialog
      title="检查计划列表"
      :visible.sync="projectVisible"
      width="1420px"
    >
      <CustomTable :data="detailCheckList" height="630">
        <el-table-column label="检查计划" prop="planName" />
        <el-table-column label="计划类型" prop="planType" >
          <template #default="{ row }">
            {{ formatPlanType(row.planType) }}
          </template>
        </el-table-column>
        <el-table-column label="检测时间" prop="checkTime" />
        <el-table-column label="分数" prop="score">
          <template #default="{ row }">
            <div>{{ getScoreDisplay(row) }}</div>
          </template>
        </el-table-column>
        <el-table-column label="风险类型" prop="riskLevel" v-if="shouldShowRiskLevel">
          <template #default="{ row }">
            {{ formatRiskLevel(row.riskLevel) }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="{ row }">
            <el-popover
              trigger="click"
              popper-class="custom-popper"
              :disabled="!hasAnyReport(row)"
            >
              <template #reference>
                <el-button
                  type="text"
                  :class="hasAnyReport(row) ? 'btnColor' : 'btnDisabled'"
                  :disabled="!hasAnyReport(row)"
                  @click="checkReportAvailability(row)"
                >
                  查看报告
                </el-button>
              </template>
              <div
                class="h100 flex flex-column a-center j-between c-fff fs--16 SHSBold"
              >
                <div
                  @click="openReport('safe', row)"
                  class="py--12 w100 txt-center br--10 bgcolor6 report-btn"
                  :class="{
                    'report-disabled': row.containSystemRes !== 1,
                    'report-enabled': row.containSystemRes === 1,
                  }"
                >
                  <span>安全报告</span>
                  <span v-if="row.containSystemRes !== 1" class="no-report-tag"
                    >(暂无)</span
                  >
                </div>
                <div
                  @click="openReport('device', row)"
                  class="py--12 w100 txt-center br--10 bgcolor7 report-btn"
                  :class="{
                    'report-disabled': row.containDeviceRes !== 1,
                    'report-enabled': row.containDeviceRes === 1,
                  }"
                >
                  <span>设备报告</span>
                  <span v-if="row.containDeviceRes !== 1" class="no-report-tag"
                    >(暂无)</span
                  >
                </div>
              </div>
            </el-popover>
          </template>
        </el-table-column>
      </CustomTable>
      <CustomPagination
        @size-change="handleDetailSizeChange"
        @current-change="handleDetailCurrentChange"
        :current-page="detailCurrentPage"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="detailPageSize"
        :total="detailTotal"
      />
    </CustomDialog>
    <!-- 检查报告弹窗 -->
    <CustomDialog
      title="检查报告"
      :visible.sync="reportVisible"
      width="1420px"
      @close="closeReportDialog"
    >
      <div style="height: 691px" class="flex flex-column" v-loading="loading">
        <!-- PDF预览容器 -->
        <div
          v-if="showPreview && pdfUrl"
          style="width: 100%; height: 100%; overflow: auto; background: #525659"
        >
          <iframe
            :src="pdfUrl"
            style="width: 100%; height: 100%; border: none"
            frameborder="0"
          ></iframe>
        </div>
        <!-- 加载提示 -->
        <div v-else class="flex flex-column a-center j-center h100">
          <div class="c-fff fs--18 mb--20">正在加载报告...</div>
        </div>
        <!-- 底部操作按钮 -->
        <div class="flex j-center gap--20 mt--20">
          <el-button
            type="primary"
            @click="downloadReport"
            :disabled="!reportBlobUrl"
            >下载报告</el-button
          >
          <el-button @click="closeReportDialog">关闭</el-button>
        </div>
      </div>
    </CustomDialog>
  </div>
</template>
 
<script>
import HeaderBox from '../header/index.vue'
import moment from 'moment'
import {
  deviceTypes,
  getProjectList,
  getDeviceListByType,
  getDeviceDetailCheckListByType
} from './service.js'
import {
  getFuzzyReportWord,
  getScoreReportWord,
  getFuzzyReportPdfUrl,
  getScoreReportPdfUrl
} from '../planOfAudit/service'
export default {
  components: { HeaderBox },
  props: {},
  data () {
    return {
      dateTime: null,
      dateTime2: null,
      projectId: null,
      projectName: '',
      dateTxt: '',
      type: '', // 设备类型
      startTime: '', // 开始时间
      endTime: '', // 结束时间
      content: '', // 搜索内容
      currentPage: 1,
      pageSize: 10,
      total: 0,
      projectVisible: false,
      reportVisible: false,
      reportUrl: '', // 已废弃,保留兼容性
      reportBlobUrl: '', // Blob URL用于下载
      pdfUrl: '', // PDF预览URL
      loading: false,
      showPreview: false, // 是否显示预览
      deviceTypeList: [], // 设备类型列表
      tableList: [], // 数据列表
      // 详情弹窗相关数据
      detailCheckList: [], // 设备详情检查列表
      detailCurrentPage: 1,
      detailPageSize: 10,
      detailTotal: 0,
      currentDeviceId: null, // 当前查看详情的设备ID
      currentRow: null, // 当前选中的行数据
      // 委托方相关
      projectList: [], // 项目列表(委托方使用)
      isClient: false, // 是否委托方端
 
      pdfProjectName: '', // 项目名称用于报告下载
      commentType: sessionStorage.getItem('commentType') // 评价类型
    }
  },
  computed: {
    // 是否是项目端(路由传入projectId参数)
    isProjectMode () {
      return !this.isClient
    },
    // 是否是委托方端(使用独立标识)
    isClientMode () {
      return this.isClient
    },
    // 是否显示风险类型列(commentType 不为 2 时显示)
    shouldShowRiskLevel () {
      return this.commentType !== '2'
    }
  },
  watch: {
    dateTime: {
      handler (newVal, oldVal) {
        if (newVal) {
          this.startTime = moment(newVal).format('YYYY年MM月DD日 HH:mm:ss')
        } else {
          this.startTime = ''
        }
      },
      immediate: true
    },
    dateTime2: {
      handler (newVal, oldVal) {
        if (newVal) {
          this.endTime = moment(newVal).format('YYYY年MM月DD日 HH:mm:ss')
        } else {
          this.endTime = ''
        }
      },
      immediate: true
    },
    // 监听弹窗关闭,重置详情数据
    projectVisible (newVal) {
      if (!newVal) {
        this.detailCheckList = []
        this.detailCurrentPage = 1
        this.detailPageSize = 10
        this.detailTotal = 0
        this.currentDeviceId = null
      }
    }
  },
  created () {
    // 判断是项目端还是委托方端
    if (this.$route.query.projectId) {
      this.projectId = this.$route.query.projectId
      this.isClient = false // 项目端
    } else {
      this.isClient = true // 委托方端
      this.loadProjectList() // 加载项目列表
    }
 
    if (this.$route.query.projectName) {
      this.projectName = this.$route.query.projectName
    }
 
    // 接收从 home 页面传递过来的时间参数并回填
    if (this.$route.query.startTime) {
      this.dateTime = moment(this.$route.query.startTime).format(
        'YYYY-MM-DD HH:mm:ss'
      )
    }
    if (this.$route.query.endTime) {
      this.dateTime2 = moment(this.$route.query.endTime).format(
        'YYYY-MM-DD HH:mm:ss'
      )
    }
 
    this.getTypeList()
    this.getList()
  },
  mounted () {},
  methods: {
    // 加载项目列表(委托方使用)
    async loadProjectList () {
      try {
        // 从 sessionStorage 获取 userInfo
        const userInfoStr = sessionStorage.getItem('userInfo')
        if (!userInfoStr) {
          console.error('未找到用户信息')
          return
        }
        const clientId = sessionStorage.getItem('clientId')
 
        if (!clientId) {
          console.error('用户信息中未找到 clientId')
          return
        }
 
        const activeTabIndex = Number(sessionStorage.getItem('activeTab')) - 1
        const res = await getProjectList({
          clientId: clientId,
          projectCategory: ['ongoing', 'fixed'][activeTabIndex]
        })
        if (res && res) {
          this.projectList = res.map((item) => ({
            label: item.name,
            value: item.id
          }))
        }
      } catch (error) {
        console.error('加载项目列表失败:', error)
      }
    },
    // 格式化计划类型
    formatPlanType (type) {
      const typeMap = {
        0: '安全检查',
        1: '质量检查',
        2: '综合检查',
        3: '设备检查',
        4: '运营检查'
      }
      return typeMap[type] || '-'
    },
    // 格式化风险类型
    formatRiskLevel (level) {
      const levelMap = {
        0: '拒绝接受风险',
        1: '不可接受风险',
        2: '可接受风险',
        3: '可容忍风险',
        4: '可忽略风险'
      }
      return levelMap[level] || '-'
    },
 
    // 项目选择改变(委托方使用)
    handleProjectChange () {
      // 选择项目后,只作为筛选条件,不改变页面标题
      this.currentPage = 1
      this.getList()
    },
 
    // 清除项目选择(委托方使用)
    clearProjectSelect () {
      this.projectId = null
      this.currentPage = 1
      this.getList()
    },
 
    // 清除设备类型
    clearDeviceType () {
      this.type = ''
      this.handleSearch()
    },
 
    // 获取设备类型
    getTypeList () {
      deviceTypes().then((res) => {
        this.deviceTypeList = res
      })
    },
    // 根据设备类型下标获取设备类型名称
    getDeviceTypeName (typeIndex) {
      if (typeIndex === null || typeIndex === undefined || typeIndex === '') {
        return '-'
      }
      // 如果 typeIndex 是数字下标,从设备类型列表中获取对应的名称
      if (typeof typeIndex === 'number' && this.deviceTypeList[typeIndex]) {
        return this.deviceTypeList[typeIndex].name
      }
      // 如果 typeIndex 是 code,从设备类型列表中查找对应的名称
      const deviceType = this.deviceTypeList.find(
        (item) => item.code === typeIndex
      )
      return deviceType ? deviceType.name : typeIndex
    },
    toHiddenDanger (row, type) {
      this.$router.push({
        path: '/hiddenDanger',
        query: {
          projectId: this.projectId || row.projectId,
          projectName: this.projectName || row.projectName,
          activeTab: type
        }
      })
    },
    getList () {
      // 将 code 转换为下标
      let typeIndex = ''
      if (this.type) {
        const index = this.deviceTypeList.findIndex(
          (item) => item.code === this.type
        )
        typeIndex = index !== -1 ? index : ''
      }
      console.log(this.dateTime, this.dateTime2)
 
      let params = {
        projectId: this.projectId,
        projectName: this.projectName,
        content: this.content,
        type: typeIndex, // 传递下标而不是 code
        pageNum: this.currentPage,
        pageSize: this.pageSize
      }
      if (this.dateTime) {
        params.startTime = moment(this.dateTime).format('YYYY-MM-DD HH:mm:ss')
      }
      if (this.dateTime2) {
        params.endTime = moment(this.dateTime2).format('YYYY-MM-DD HH:mm:ss')
      }
      if (this.isClient) {
        params.clientId = sessionStorage.getItem('clientId')
        params.category = sessionStorage.getItem('activeTab')
      }
 
      // 使用统一方法,根据用户类型调用对应接口
      getDeviceListByType({ ...params }, this.isClient).then((res) => {
        // 处理 properties 字段
        this.tableList = res.records.map((item) => {
          return {
            ...item,
            parsedProperties: this.parseProperties(item.properties)
          }
        })
        this.total = res.total
      })
    },
    // 解析 properties 字段
    parseProperties (properties) {
      if (!properties) return []
      try {
        // 如果是字符串,先解析为数组
        const propertiesArray =
          typeof properties === 'string' ? JSON.parse(properties) : properties
        // 确保返回的是数组
        return Array.isArray(propertiesArray)
          ? propertiesArray
          : [propertiesArray]
      } catch (error) {
        console.error('解析 properties 失败:', error)
        return []
      }
    },
    // 获取 properties 中某个字段的所有值(数组形式)
    getPropertyValues (row, fieldName) {
      if (!row.parsedProperties || row.parsedProperties.length === 0) {
        return ['-']
      }
      // 从所有 properties 对象中提取指定字段的值
      const values = row.parsedProperties
        .map((prop) => prop[fieldName])
        .filter((val) => val && val.trim() !== '') // 过滤空值
 
      return values.length > 0 ? values : ['-']
    },
    // 获取 properties 中某个字段的第一个值(单个值)
    getPropertyValue (row, fieldName) {
      if (!row.parsedProperties || row.parsedProperties.length === 0) {
        return '-'
      }
      // 从第一个 properties 对象中获取指定字段的值
      const value = row.parsedProperties[0][fieldName]
      return value && value.trim() !== '' ? value : '-'
    },
 
    handleSizeChange (val) {
      this.pageSize = val
      this.currentPage = 1 // 改变每页条数时重置到第一页
      this.getList()
    },
 
    handleCurrentChange (val) {
      this.currentPage = val
      this.getList()
    },
 
    // 搜索方法
    handleSearch () {
      this.currentPage = 1 // 搜索时重置到第一页
      this.getList()
    },
 
    handleClick (type) {
      this.$refs[`datetime${type}`].focus()
    },
 
    // 清除开始时间
    clearStartTime () {
      this.dateTime = null
      this.handleSearch()
    },
 
    // 清除结束时间
    clearEndTime () {
      this.dateTime2 = null
      this.handleSearch()
    },
 
    backFun () {
      this.$router.go(-1)
    },
 
    // 检查是否有任何报告
    hasAnyReport (row) {
      return row.containSystemRes === 1 || row.containDeviceRes === 1
    },
 
    // 检查报告可用性(当按钮被禁用时点击)
    checkReportAvailability (row) {
      if (!this.hasAnyReport(row)) {
        this.$message.warning('该设备暂无可查看的报告')
      }
    },
 
    // 打开报告
    async openReport (type, row) {
      // 根据类型检查是否有对应报告
      const hasReport =
        type === 'safe'
          ? row.containSystemRes === 1
          : row.containDeviceRes === 1
 
      if (!hasReport) {
        this.$message.warning(`暂无${type === 'safe' ? '安全' : '设备'}报告`)
        return
      }
 
      this.currentRow = row
      this.reportVisible = true
      this.showPreview = false
      this.loading = true
 
      try {
        // 从 sessionStorage 获取模板 ID
        const deviceTemplateId = sessionStorage.getItem('deviceTemplateId')
        const safetyId = sessionStorage.getItem('safetyId')
        const safetyName =
          this.pdfProjectName + sessionStorage.getItem('safetyName')
        const deviceTemplateName =
          this.pdfProjectName + sessionStorage.getItem('deviceTemplateName')
        // console.log('row', row)
        // return
 
        // 检查任务 ID
        const checkTaskId = row.id
        if (!checkTaskId) {
          this.$message.error('缺少检查任务ID')
          this.loading = false
          this.reportVisible = false
          return
        }
 
        // 第一步:调用接口生成Word文档(返回Word文档流)
        let wordBlob
        try {
          if (type === 'safe') {
            // 安全报告(模糊评价)
            if (!safetyId) {
              this.$message.error('缺少安全报告模板ID')
              this.loading = false
              this.reportVisible = false
              return
            }
            wordBlob = await getFuzzyReportWord({
              checkTaskId: checkTaskId,
              templateId: safetyId,
              uuid: safetyName
            })
          } else {
            // 设备报告(打分评价)
            if (!deviceTemplateId) {
              this.$message.error('缺少设备报告模板ID')
              this.loading = false
              this.reportVisible = false
              return
            }
            wordBlob = await getScoreReportWord({
              checkTaskId: checkTaskId,
              templateId: deviceTemplateId,
              uuid: deviceTemplateName
            })
          }
        } catch (error) {
          // 捕获生成Word文档时的错误
          console.error('生成Word文档失败:', error)
          this.$message.error(error.message || '生成报告失败')
          this.loading = false
          this.reportVisible = false
          return
        }
 
        // 检查 Word 文档是否生成成功
        if (!wordBlob || wordBlob.size === 0) {
          this.$message.error('报告生成失败')
          this.loading = false
          this.reportVisible = false
          return
        }
 
        // 第二步:使用uuid获取PDF链接
        let pdfUrlResponse
        try {
          if (type === 'safe') {
            pdfUrlResponse = await getFuzzyReportPdfUrl({ uuid: safetyName })
          } else {
            pdfUrlResponse = await getScoreReportPdfUrl({
              uuid: deviceTemplateName
            })
          }
        } catch (error) {
          // 捕获获取PDF链接时的错误
          console.error('获取PDF链接失败:', error)
          this.$message.error(error.message || '获取PDF链接失败')
          this.loading = false
          this.reportVisible = false
          return
        }
 
        // 根据后端返回的数据结构获取PDF链接
        // 假设后端返回格式为 { data: "http://xxx.pdf" } 或直接返回字符串
        const pdfUrl = pdfUrlResponse.data || pdfUrlResponse
 
        if (!pdfUrl) {
          this.$message.error('获取PDF链接失败')
          this.loading = false
          this.reportVisible = false
          return
        }
 
        // 保存PDF链接用于预览和下载
        this.pdfUrl = pdfUrl
        this.reportBlobUrl = pdfUrl // 用于下载
        this.showPreview = true
 
        this.$message.success('报告加载成功')
      } catch (error) {
        console.error('获取报告失败:', error)
        // 优先显示错误对象中的 message
        if (error.message) {
          this.$message.error(error.message)
        } else if (error.response) {
          const status = error.response.status
          if (status === 404) {
            this.$message.error('报告不存在')
          } else if (status === 500) {
            this.$message.error('服务器错误,请稍后重试')
          } else {
            this.$message.error(
              `获取报告失败: ${error.response.statusText || '未知错误'}`
            )
          }
        } else {
          this.$message.error('获取报告失败,请检查网络连接')
        }
        this.showPreview = false
        this.reportVisible = false
      } finally {
        this.loading = false
      }
    },
 
    // 下载报告
    downloadReport () {
      if (!this.reportBlobUrl) {
        this.$message.warning('报告未加载')
        return
      }
 
      try {
        // 直接打开PDF链接进行下载
        window.open(this.reportBlobUrl, '_blank')
        this.$message.success('报告下载成功')
      } catch (error) {
        console.error('下载报告失败:', error)
        this.$message.error('下载报告失败')
      }
    },
 
    // 关闭报告弹窗
    closeReportDialog () {
      this.reportVisible = false
      this.showPreview = false
 
      // 清空PDF链接(不需要释放URL,因为是服务器链接)
      this.reportBlobUrl = ''
      this.pdfUrl = ''
      this.reportUrl = '' // 保留兼容性
    },
 
    // 打开详情弹窗
    openDetailDialog (row) {
      this.currentDeviceId = row.projectId
      this.pdfProjectName = row.projectName
      this.detailCurrentPage = 1
      this.projectVisible = true
      this.getDetailCheckList()
    },
 
    // 获取设备详情检查列表
    getDetailCheckList () {
      if (!this.currentDeviceId && !this.projectId) return
 
      let params = {
        projectId: this.currentDeviceId || this.projectId,
        pageNum: this.detailCurrentPage,
        pageSize: this.detailPageSize
      }
 
      // 使用统一方法,根据用户类型调用对应接口
      getDeviceDetailCheckListByType(params, this.isClient)
        .then((res) => {
          this.detailCheckList = res.records || []
          this.detailTotal = res.total || 0
        })
        .catch((err) => {
          console.error('获取设备详情检查列表失败:', err)
          this.detailCheckList = []
          this.detailTotal = 0
        })
    },
 
    // 详情弹窗分页 - 每页条数改变
    handleDetailSizeChange (val) {
      this.detailPageSize = val
      this.detailCurrentPage = 1
      this.getDetailCheckList()
    },
 
    // 详情弹窗分页 - 当前页改变
    handleDetailCurrentChange (val) {
      this.detailCurrentPage = val
      this.getDetailCheckList()
    },
 
    // 根据评价类型显示分数
    getScoreDisplay (row) {
      // commentType: 1模糊评价 2打分评价
      const commentType = sessionStorage.getItem('commentType')
      console.log('commentType', commentType, 'row row', row)
 
      if (commentType === '1') {
        return row.fuzzyScore || '-'
      } else if (commentType === '2') {
        return row.score || '-'
      }
      return row.fuzzyScore
    }
  }
}
</script>
<style lang="less">
.custom-popper {
  background: transparent;
  background-image: url("../../assets/img/home/77Combined Shape@2x.png");
  background-size: 100% 100%;
  padding: 31px 38px;
  border-radius: 0px;
  border: none;
  box-shadow: none;
  width: 227px;
  height: 180px;
 
  .popper__arrow {
    display: none;
  }
}
</style>
<style scoped lang="less">
.bgcolor1 {
  background: rgba(2, 0, 77, 0.8);
  box-shadow: inset 0px 0px 34px 0px rgba(17, 40, 255, 0.66);
  border: 2px solid #0d53b7;
}
 
.bgColor2 {
  background: rgba(24, 69, 135, 0.9);
}
 
.bgColor3 {
  background: rgba(67, 221, 189, 1) !important;
}
 
.bgColor4 {
  background: rgba(67, 221, 189, 0.6) !important;
}
 
.bgColor5 {
  background: rgba(67, 221, 189, 0.4) !important;
}
 
.bgcolor6 {
  background: linear-gradient(270deg, #64aef0 0%, #4b70ec 100%);
}
 
.bgcolor7 {
  background: linear-gradient(270deg, #3dabea 0%, #28a5ec 100%);
}
 
.picker {
  ::v-deep .el-input__icon {
    display: none;
  }
 
  ::v-deep .el-range-separator {
    display: none;
  }
 
  ::v-deep .el-input__inner {
    background: transparent;
    border: none;
    color: transparent;
  }
 
  ::v-deep .el-range-input {
    background: transparent;
    border: none;
    color: transparent;
  }
 
  .el-icon-circle-close {
    font-size: 16px;
    transition: color 0.3s;
 
    &:hover {
      color: #00ebfc;
    }
  }
}
 
.searchBox {
  ::v-deep .el-input__inner {
    background: transparent;
    border: none;
    color: #fff;
    padding: 0;
  }
 
  ::v-deep .el-input__suffix {
    display: none;
  }
 
  ::v-deep .el-select__caret {
    display: none;
  }
 
  .btn {
    position: absolute;
    top: -2px;
    right: -2px;
    background: linear-gradient(
      90deg,
      #3467d0 0%,
      #0d226a 50.35%,
      #376fe0 100%
    );
    height: 38px;
    display: flex;
    align-items: center;
    font-size: 14px;
    color: #ffffff;
    padding: 0 26px;
    border: 1px solid #307ad9;
    box-sizing: border-box;
    cursor: pointer;
  }
 
  .el-icon-circle-close {
    font-size: 16px;
    transition: color 0.3s;
 
    &:hover {
      color: #00ebfc;
    }
  }
}
 
.btnColor {
  color: #00ebfc;
}
 
.btnDisabled {
  color: #666666 !important;
  cursor: not-allowed !important;
}
 
.report-btn {
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
}
 
.report-enabled {
  &:hover {
    opacity: 0.8;
    transform: translateY(-2px);
  }
}
 
.report-disabled {
  opacity: 0.4;
  cursor: not-allowed !important;
  pointer-events: none;
}
 
.no-report-tag {
  font-size: 12px;
  margin-left: 4px;
  opacity: 0.7;
}
 
::v-deep .el-descriptions {
  .el-descriptions__body {
    background-color: transparent;
 
    .el-descriptions-item__container {
      color: #ffffff;
      font-family: "Source Han Sans CN Regular";
    }
  }
}
 
.ripple {
  position: relative;
  width: 14px;
  height: 14px;
}
 
.ripple-wave {
  position: absolute;
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
 
.wave-1 {
  width: 14px;
  height: 14px;
  background-color: rgba(255, 55, 95, 1);
}
 
.wave-2 {
  width: 20px;
  height: 20px;
  background-color: rgba(255, 55, 95, 0.6);
  animation: ripple-effect 2s ease-out infinite;
}
 
.wave-3 {
  width: 24px;
  height: 24px;
  background-color: rgba(255, 55, 95, 0.4);
  animation: ripple-effect 2s ease-out infinite 1s;
}
 
@keyframes ripple-effect {
  0% {
    transform: translate(-50%, -50%) scale(0.7);
    opacity: 0;
  }
 
  20% {
    opacity: 1;
    opacity: 1;
  }
 
  100% {
    -webkit-transform: translate(-50%, -50%) scale(1.4);
    opacity: 0;
  }
}
</style>