吴羡
12 小时以前 d2eed0eb7c2f9537d5eaab7ccc3b6ab258959227
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
<template>
  <!--  设备核查计划-->
  <div>
    <div style="margin: 10px 0 14px;">
      <div class="plan-top">
        <div class="plan-top-left">
          <span class="title" style="margin-bottom: 0;">{{ planInfo.planName || (planYear ? planYear + '年度设备核查计划' : '设备核查计划') }}</span>
          <el-select v-model="planYear" size="small" style="width: 110px; margin-left: 16px;" @change="handleYearChange">
            <el-option v-for="y in yearOptions" :key="y" :label="y" :value="y"></el-option>
          </el-select>
        </div>
        <div>
          <el-button size="small" type="primary" @click="handleAddRecord">新增核查记录</el-button>
          <el-button size="small" type="primary" @click="loadYearOptions">刷新</el-button>
          <el-button size="small" type="primary" @click="downLoadPost">导出</el-button>
        </div>
      </div>
      <div class="plan-info-bar">
        <span>编制人:{{ planInfo.writeName || '—' }}</span>
        <span>编制日期:{{ planInfo.writeTimeStr || '—' }}</span>
        <span v-if="planInfo.ratifyStatus === 1">批准状态:<el-tag type="success">批准</el-tag></span>
        <span v-else-if="planInfo.ratifyStatus === 0">批准状态:<el-tag type="danger">不批准</el-tag></span>
        <span v-if="planInfo.ratifyRemark">批准内容:{{ planInfo.ratifyRemark }}</span>
        <span v-if="isRatified && planInfo.ratifyName">批准人:{{ planInfo.ratifyName }}</span>
        <span v-if="isRatified && planInfo.ratifyTimeStr">批准时间:{{ planInfo.ratifyTimeStr }}</span>
      </div>
    </div>
    <div class="search">
      <div>
        <el-form :model="searchForm" ref="searchForm" size="small" :inline="true">
          <el-form-item label="设备编号" prop="deviceNumber">
            <el-input v-model="searchForm.deviceNumber" clearable size="small"
              @keyup.enter="handleQuery"></el-input>
          </el-form-item>
          <el-form-item label="设备名称" prop="deviceName">
            <el-input v-model="searchForm.deviceName" clearable size="small"
              @keyup.enter="handleQuery"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="small" @click="handleQuery">查询</el-button>
            <el-button size="small" @click="reset">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div>
      <el-table ref="yearTableDetailData" v-loading="yearTableDetailDataLoading" :data="yearTableDetailData" border
        :row-class-name="tableRowClassName" :height="'calc(100vh - 29em)'" style="width: 100%;">
        <!-- 表格列 -->
        <el-table-column align="center" header-align="center" label="序号" prop="prop" type="index"
          width="70"></el-table-column>
        <el-table-column label="设备编号" min-width="170" prop="deviceNumber"></el-table-column>
        <el-table-column label="设备名称" min-width="180" prop="deviceName" show-overflow-tooltip></el-table-column>
        <el-table-column label="核查时间" min-width="120" prop="checkTime"
          :formatter="formatCheckMonth"></el-table-column>
        <el-table-column label="核查指标" min-width="140" prop="checkIndex"> </el-table-column>
        <el-table-column label="核查方法" min-width="140" prop="checkMethod" show-overflow-tooltip></el-table-column>
        <el-table-column label="结果如何判定" min-width="140" prop="howResults" show-overflow-tooltip></el-table-column>
        <el-table-column label="核查负责人" min-width="120" prop="checkChargerUser"></el-table-column>
        <el-table-column label="审核状态" min-width="100" prop="recordStatus">
          <template #default="scope">
            <el-tag type="" v-if="scope.row.recordStatus === 0" disable-transitions>未开始</el-tag>
            <el-tag type="warning" v-if="scope.row.recordStatus === 1" disable-transitions>待批准</el-tag>
            <el-tag type="success" v-if="scope.row.recordStatus === 2" disable-transitions>通过</el-tag>
            <el-tag type="danger" v-if="scope.row.recordStatus === 3" disable-transitions>不通过</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="备注" min-width="130" prop="remark"></el-table-column>
        <el-table-column label="附件" min-width="140">
          <template #default="scope">
            <el-link v-if="scope.row.attachmentCount > 0" type="primary" @click="handleAttachment(scope.row)">
              查看附件({{ scope.row.attachmentCount }})
            </el-link>
            <el-link v-else-if="scope.row.fileUrl" type="primary" @click="openAttachment(scope.row)">
              {{ scope.row.fileName || '查看附件' }}
            </el-link>
            <span v-else>—</span>
          </template>
        </el-table-column>
        <!-- 操作按钮 -->
        <el-table-column align="center" fixed="right" label="操作" min-width="320">
          <template #default="scope">
            <el-button size="small" link type="primary"
              :disabled="scope.row.recordStatus === 2 || scope.row.recordStatus === 3"
              @click="handleForm('edit', scope.row)">编辑</el-button>
            <el-button size="small" link type="primary" @click="handleForm('view', scope.row)">查看</el-button>
            <el-button v-if="scope.row.recordStatus === 0 || scope.row.recordStatus === 1"
              size="small" link type="primary" :disabled="!scope.row.checkChargerUser"
              @click="handleRecord(scope.row)">审核</el-button>
            <el-button v-if="scope.row.recordStatus === 2 || scope.row.recordStatus === 3"
              size="small" link type="primary" @click="handleDown(scope.row)">导出</el-button>
            <el-button v-if="scope.row.recordStatus === 0 && scope.row.recordContrastStatus === 0"
              size="small" link type="danger" @click="deleteFun1(scope.row.planDetailsId)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination :current-page="pagination1.current" :page-size="pagination1.size"
        :page-sizes="[10, 20, 30, 50, 100]" :total="pagination1.total"
        layout="->,total, sizes, prev, pager, next, jumper" background
        @size-change="handleSizeChange1" @current-change="handleCurrentChange1">
      </el-pagination>
    </div>
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" v-model="dialogVisible"
      :title="operationType === 'view' ? '设备核查记录' : '编辑核查记录'" top="5vh" width="960px" @close="resetForm">
      <el-form ref="modelForm" :model="form" :rules="rules" label-width="104px">
        <div class="form-section">
          <div class="form-section-title">基本信息</div>
          <el-row :gutter="12">
            <el-col :span="12">
              <el-form-item label="仪器名称:" prop="deviceName">
                <el-input v-model="form.deviceName" disabled size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="检查日期:" prop="checkTime">
                <el-date-picker v-model="form.checkTime" :disabled="operationType === 'view'" clearable
                  format="YYYY-MM" placeholder="选择检查日期" size="small" style="width:100%" type="month"
                  value-format="YYYY-MM">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="管理编号:" prop="deviceNumber">
                <el-input v-model="form.deviceNumber" disabled size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="设备型号:" prop="deviceModel">
                <el-input v-model="form.deviceModel" disabled size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="核查人:" prop="checkChargerUserId">
                <el-select v-model="form.checkChargerUserId" @change="setCheckChargerUser" clearable filterable
                  :disabled="operationType === 'view'" placeholder="请选择" size="small" style="width: 100%">
                  <el-option v-for="item in chargerOptions" :key="item.id" :label="item.name"
                    :value="item.id"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div class="form-section">
          <div class="form-section-title">核查内容</div>
          <el-row :gutter="12">
            <el-col :span="8">
              <el-form-item label="环境温湿度:" prop="environment">
                <el-input v-model="form.environment" :disabled="operationType === 'view'" clearable size="small"
                  placeholder="如:25℃ / 50%RH"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="核查依据:" prop="checkBasis">
                <el-input v-model="form.checkBasis" :disabled="operationType === 'view'" clearable
                  size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="核查指标:" prop="checkIndex">
                <el-input v-model="form.checkIndex" :disabled="operationType === 'view'" clearable
                  size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="核查方式:" prop="checkMethod">
                <el-input v-model="form.checkMethod" :disabled="operationType === 'view'" clearable :rows="2"
                  size="small" type="textarea"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="结果如何判定:" prop="howResults">
                <el-input v-model="form.howResults" :disabled="operationType === 'view'" clearable :rows="2"
                  size="small" type="textarea"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="外观情况:">
                <el-radio-group v-model="form.appearanceStatus" :disabled="operationType === 'view'">
                  <el-radio value="良好">良好</el-radio>
                  <el-radio value="一般">一般</el-radio>
                  <el-radio value="损坏">损坏</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="运行状态:">
                <el-radio-group v-model="form.runningStatus" :disabled="operationType === 'view'">
                  <el-radio value="正常">正常</el-radio>
                  <el-radio value="异常">异常</el-radio>
                  <el-radio value="停机">停机</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注:" prop="remark">
                <el-input v-model="form.remark" :disabled="operationType === 'view'" clearable size="small"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div class="form-section">
          <div class="form-section-title">附件资料</div>
          <el-form-item label-width="0">
            <lims-attachment inline upload-url="/deviceExaminePlan/uploadAttachment"
              select-url="/deviceExaminePlan/selectAttachments" delete-url="/deviceExaminePlan/deleteAttachment"
              id-param="planDetailsId" name-field="deviceName" title="核查记录附件"
              :main-id="form.planDetailsId" :readonly="operationType === 'view'"></lims-attachment>
            <el-link v-if="form.fileUrl" type="primary" @click="openAttachment(form)">
              {{ form.fileName || '查看原附件' }}
            </el-link>
          </el-form-item>
        </div>
      </el-form>
      <template #footer><span class="dialog-footer">
        <el-button @click="resetForm">取 消</el-button>
        <el-button :loading="submitFormLoading" type="primary" @click="submitForm"
          v-if="operationType !== 'view'">确 认</el-button>
      </span></template>
    </el-dialog>
    <el-dialog v-model="downloadDialog" title="导出" width="480px">
      <div class="export-panel">
        <div class="export-panel-head">
          <span class="export-panel-name">仪器设备期间核查记录表</span>
          <el-tag v-if="downRow.recordStatus === 2" type="success" disable-transitions>通过</el-tag>
          <el-tag v-else-if="downRow.recordStatus === 1" type="warning" disable-transitions>待批准</el-tag>
          <el-tag v-else-if="downRow.recordStatus === 3" type="danger" disable-transitions>不通过</el-tag>
          <el-tag v-else type="info" disable-transitions>未开始</el-tag>
        </div>
        <div class="export-panel-meta">
          <div class="export-panel-item">
            <span class="export-panel-label">设备编号</span>{{ downRow.deviceNumber || '—' }}
          </div>
          <div class="export-panel-item">
            <span class="export-panel-label">设备名称</span>{{ downRow.deviceName || '—' }}
          </div>
          <div class="export-panel-item">
            <span class="export-panel-label">核查时间</span>{{ formatCheckMonth(null, null, downRow.checkTime) || '—' }}
          </div>
        </div>
        <div v-if="!canExport" class="export-panel-tip">
          {{ downRow.recordStatus === 1 ? '该计划行尚未审核完成,审核通过或不通过后才能导出。' : '该计划行还没有核查记录,录入并提交审核后才能导出。' }}
        </div>
      </div>
      <template #footer><span class="dialog-footer">
        <el-button @click="downloadDialog = false">取 消</el-button>
        <el-button :loading="outLoading" type="primary" :disabled="!canExport"
          @click="controlDown">导出记录表</el-button>
      </span></template>
    </el-dialog>
    <check-record v-if="checkRecord" ref="checkRecord" @closeDialog1="closeDialog1"></check-record>
    <lims-attachment ref="rowAttachment" upload-url="/deviceExaminePlan/uploadAttachment"
      select-url="/deviceExaminePlan/selectAttachments" delete-url="/deviceExaminePlan/deleteAttachment"
      id-param="planDetailsId" name-field="deviceName" title="核查记录附件" :readonly="attachmentReadonly"
      @closed="getYearTableDetailData"></lims-attachment>
  </div>
</template>
 
<script>
import CheckRecord from "./checkRecord.vue";
import LimsAttachment from '@/components/Attachment/lims-attachment.vue'
import {
  pageDeviceExaminePlan,
  getExaminePlanByYear,
  exportDeviceExaminePlanDetail,
  delDeviceExaminePlanDetail,
  pageDeviceExaminePlanDetail,
  updateDeviceExaminePlanDetail,
  exportReviewExamineRecordDetail,
  exportReviewExamineRecordContrast,
} from '@/api/cnas/resourceDemand/device.js'
import { selectUserCondition } from "@/api/performance/class";
import draftSave from '@/mixins/draftSave'
import { formatListDate } from './dateFormat'
export default {
  name: "equipment-verification-plan",
  // import 引入的组件需要注入到对象中才能使用
  components: { CheckRecord, LimsAttachment },
  mixins: [draftSave],
  props: {
    clickNodeVal: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  data() {
    // 这里存放数据
    return {
      planYear: '',
      yearOptions: [],
      planInfo: {},
      dialogVisible: false,
      searchForm: {
        deviceName: '',
        deviceNumber: '',
      },
      yearTableDetailData: [],
      pagination1: {
        size: 10,
        current: 1,
        total: 0,
      },
      form: {
        deviceNumber: '',
        deviceName: '',
        deviceModel: '',
        checkTime: '',
        checkIndex: '',
        checkMethod: '',
        howResults: '',
        checkChargerUserId: '',
        checkChargerUser: '',
        environment: '',
        checkBasis: '',
        appearanceStatus: '',
        runningStatus: '',
        remark: '',
        fileName: '',
        fileUrl: '',
        planId: '',
        planDetailsId: '',
      },
      operationType: '',
      rules: {
        checkMethod: [{ required: true, message: '请填写核查方式', trigger: 'blur' }],
      },
      yearTableDetailDataLoading: false,
      submitFormLoading: false,
      userList: [],
      attachmentReadonly: false,
      checkRecord: false,
      downloadDialog: false,
      outLoading: false,
      downRow: {},
    }
  },
  mounted() {
    this.loadYearOptions()
  },
  // 方法集合
  methods: {
    // 年份下拉只保留有计划明细的年份,空年份自动消失
    loadYearOptions() {
      pageDeviceExaminePlan({
        current: 1,
        size: 99,
      }).then(res => {
        let years = []
        if (res.code == 200) {
          years = (res.data.records || []).map(r => r.planYear).filter(Boolean)
        }
        const options = [...new Set(years)].sort((a, b) => b.localeCompare(a))
        this.yearOptions = options
        if (options.length === 0) {
          this.planYear = ''
          this.planInfo = {}
          this.yearTableDetailData = []
          this.pagination1.total = 0
          return
        }
        if (options.indexOf(this.planYear) === -1) {
          const currentYear = String(new Date().getFullYear())
          this.planYear = options.indexOf(currentYear) > -1 ? currentYear : options[0]
        }
        this.loadPlan()
      })
    },
    // 切换年份
    handleYearChange() {
      this.pagination1.current = 1
      this.loadPlan()
    },
    // 查询年份计划(不存在自动创建并补全到点明细),随后刷新明细
    loadPlan() {
      if (!this.planYear) {
        this.planInfo = {}
        this.yearTableDetailData = []
        this.pagination1.total = 0
        return
      }
      getExaminePlanByYear({ planYear: this.planYear }).then(res => {
        if (res.code == 200) {
          this.planInfo = res.data || {}
        }
        this.getYearTableDetailData()
      }).catch(() => {
        this.planInfo = {}
        this.yearTableDetailData = []
        this.pagination1.total = 0
        this.yearTableDetailDataLoading = false
      })
    },
    // 查询条件变化后从第一页开始查
    handleQuery() {
      this.pagination1.current = 1
      this.getYearTableDetailData()
    },
    // 明细-查询
    getYearTableDetailData() {
      if (!this.planInfo.planId) {
        return
      }
      this.yearTableDetailDataLoading = true
      pageDeviceExaminePlanDetail({
        current: this.pagination1.current,
        size: this.pagination1.size,
        planId: this.planInfo.planId,
        deviceName: this.searchForm.deviceName,
        deviceNumber: this.searchForm.deviceNumber,
      }).then(res => {
        if (res.code == 200) {
          this.yearTableDetailData = res.data.records
          this.pagination1.total = res.data.total
        }
        this.yearTableDetailDataLoading = false
      }).catch(err => {
        this.yearTableDetailDataLoading = false
      })
    },
    // 到点需核查的行标红
    // 手动录入的核查日期显示到日,系统登记的月份数据仍按年月显示
    formatCheckMonth(row, column, cellValue) {
      if (cellValue === null || cellValue === undefined || cellValue === '') {
        return cellValue
      }
      const str = String(cellValue).trim().replace(/[./]/g, '-')
      const dateMatched = str.match(/^(\d{4})-(\d{1,2})-(\d{1,2})/)
      if (dateMatched) {
        return `${dateMatched[1]}-${dateMatched[2].padStart(2, '0')}-${dateMatched[3].padStart(2, '0')}`
      }
      const matched = str.match(/^(\d{4})-(\d{1,2})/)
      if (matched) {
        return `${matched[1]}-${matched[2].padStart(2, '0')}`
      }
      const formatted = formatListDate(str)
      const fallback = String(formatted).match(/^(\d{4})-(\d{1,2})-(\d{1,2})/)
      if (fallback) {
        return `${fallback[1]}-${fallback[2].padStart(2, '0')}-${fallback[3].padStart(2, '0')}`
      }
      const monthFallback = String(formatted).match(/^(\d{4})-(\d{1,2})/)
      return monthFallback ? `${monthFallback[1]}-${monthFallback[2].padStart(2, '0')}` : cellValue
    },
    tableRowClassName({ row }) {
      return row.redFlag === 1 ? 'red-row' : ''
    },
    reset() {
      this.searchForm = {
        deviceName: '',
        deviceNumber: '',
      }
      this.pagination1.current = 1
      this.getYearTableDetailData()
    },
    // 分页
    handleSizeChange1(val) {
      this.pagination1.size = val
      this.getYearTableDetailData()
    },
    // 分页
    handleCurrentChange1(val) {
      this.pagination1.current = val
      this.getYearTableDetailData()
    },
    // 打开明细弹框
    handleForm(type, row) {
      this.getUserList()
      this.operationType = type
      this.dialogVisible = true
      this.form.planId = this.planInfo.planId
      this.$nextTick(() => {
        this.form = this.HaveJson(row)
        if (this.operationType !== 'view') {
          this.draftRestore('equipmentVerificationPlan', 'form', this.form.planDetailsId, 'dialogVisible')
        }
      })
    },
    // 提交表单
    submitForm() {
      this.$refs.modelForm.validate(valid => {
        if (valid) {
          this.submitFormLoading = true
          updateDeviceExaminePlanDetail(this.form).then(res => {
            if (res.code == 200) {
              this.$message.success('修改成功')
              this.draftClear('equipmentVerificationPlan')
              this.dialogVisible = false
              this.getYearTableDetailData()
            }
            this.submitFormLoading = false
          }).catch(err => {
            this.submitFormLoading = false
          })
        }
      })
    },
    // 明细-删除
    deleteFun1(id) {
      this.$confirm('删除后,若该设备还有审核通过的核查记录,档案的最近核查日期将回退到最近一次完成记录;若没有,则清空档案的核查日期和核查周期。是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delDeviceExaminePlanDetail({ planDetailsId: id }).then(res => {
          this.$message.success('删除成功!');
          this.loadYearOptions()
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 导出年度计划表
    downLoadPost() {
      exportDeviceExaminePlanDetail({ planId: this.planInfo.planId }).then(res => {
        this.saveDocx(res, '仪器设备期间核查计划表.docx')
      }).catch(() => { })
    },
    resetForm() {
      this.draftStop('equipmentVerificationPlan')
      this.$refs.modelForm.resetFields();
      this.dialogVisible = false
    },
    // 打开核查记录(待批准时用于审核)
    handleRecord(row) {
      this.checkRecord = true
      this.$nextTick(() => {
        this.$refs.checkRecord.openDialog(row)
      })
    },
    // 新增核查记录(可自选设备)
    handleAddRecord() {
      this.checkRecord = true
      this.$nextTick(() => {
        this.$refs.checkRecord.openAddDialog()
      })
    },
    // 打开附件
    openAttachment(row) {
      const isImage = /\.(jpg|jpeg|png|gif)$/i.test(row.fileUrl)
      window.open(this.javaApi + (isImage ? '/img/' : '/word/') + row.fileUrl, '_blank')
    },
    // 列表附件列只读查看(上传/删除入口只在编辑、新增弹窗内)
    handleAttachment(row) {
      this.attachmentReadonly = true
      this.$refs.rowAttachment.open(row)
    },
    // 关闭记录弹框
    closeDialog1() {
      this.checkRecord = false
      this.loadYearOptions()
    },
    // 打开导出弹框
    handleDown(row) {
      this.downRow = row
      this.downloadDialog = true
    },
    // 导出结果拦截: 后端返回错误 JSON 时提示错误, 不存成坏文件
    saveDocx(res, filename) {
      const reader = new FileReader();
      reader.readAsText(res, 'utf-8');
      reader.onload = () => {
        const text = (reader.result || '').trim();
        if (text.startsWith('{') || text.startsWith('[')) {
          let msg = '导出失败';
          try { msg = JSON.parse(text).msg || msg; } catch (e) { }
          this.$message.error(msg);
        } else {
          this.$download.saveAs(new Blob([res], { type: 'application/msword' }), filename);
        }
      };
      reader.onerror = () => {
        this.$download.saveAs(new Blob([res], { type: 'application/msword' }), filename);
      };
    },
    // 核查记录导出
    controlDown() {
      this.outLoading = true
      exportReviewExamineRecordDetail({ planDetailsId: this.downRow.planDetailsId }).then(res => {
        this.outLoading = false
        this.saveDocx(res, '仪器设备期间核查记录表.doc')
      }).catch(() => {
        this.outLoading = false
      })
    },
    // 核查对比导出
    processingDown() {
      this.outLoading = true
      exportReviewExamineRecordContrast({ planDetailsId: this.downRow.planDetailsId }).then(res => {
        this.outLoading = false
        this.saveDocx(res, '仪器设备期间核查比对记录表.doc')
      }).catch(() => {
        this.outLoading = false
      })
    },
    getUserList() {
      selectUserCondition({ type: 4 }).then(res => {
        this.userList = res.data
      })
    },
    setCheckChargerUser(val) {
      const index = this.userList.findIndex(item => item.id === val)
      if (index > -1) {
        this.form.checkChargerUser = this.userList[index].name
      }
    }
  },
  computed: {
    // 是否已完成审批(批准/不批准)
    isRatified() {
      return this.planInfo.ratifyStatus === 0 || this.planInfo.ratifyStatus === 1;
    },
    // 记录状态为通过或不通过(审核已结束)才允许导出
    canExport() {
      return this.downRow.recordStatus === 2 || this.downRow.recordStatus === 3;
    },
    // 责任人下拉:已保存的责任人不在候选列表时补一条,避免回显成用户ID
    chargerOptions() {
      const list = this.userList || []
      const id = this.form.checkChargerUserId
      if (id && !list.some(item => String(item.id) === String(id))) {
        return [...list, { id, name: this.form.checkChargerUser || String(id) }]
      }
      return list
    },
  },
}
</script>
 
<style scoped>
.search {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}
 
.title {
  position: relative;
  font-size: 16px;
  color: var(--lims-text);
  font-weight: 400;
  padding-left: 10px;
  margin-bottom: 10px;
}
 
.title::before {
  position: absolute;
  left: 0;
  top: 4px;
  content: '';
  width: 4px;
  height: 16px;
  background-color: var(--el-color-primary);
  border-radius: 2px;
}
 
.plan-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
 
.plan-top-left {
  display: flex;
  align-items: center;
}
 
.plan-info-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 32px;
  background: #f5f7fa;
  border-radius: 4px;
  padding: 10px 16px;
  margin-top: 14px;
  font-size: 14px;
  color: #606266;
}
 
:deep(.red-row td) {
  background: #ffcccc !important;
}
 
.form-section {
  padding: 12px 14px 0;
  border: 1px solid #ebeef5;
  border-radius: 6px;
  margin-bottom: 10px;
}
 
.form-section:last-child {
  margin-bottom: 0;
}
 
.form-section-title {
  display: flex;
  align-items: center;
  padding-left: 8px;
  border-left: 3px solid var(--el-color-primary);
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  color: #303133;
}
 
.form-section :deep(.el-form-item) {
  margin-bottom: 12px;
}
 
.export-panel {
  border: 1px solid #e4e7ed;
  border-radius: 6px;
  padding: 18px 20px;
  background: #fafbfc;
}
 
.export-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
 
.export-panel-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--lims-text);
}
 
.export-panel-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: #606266;
}
 
.export-panel-item {
  display: flex;
  align-items: center;
}
 
.export-panel-label {
  width: 72px;
  flex-shrink: 0;
  color: #909399;
}
 
.export-panel-tip {
  margin-top: 14px;
  padding: 8px 12px;
  border-radius: 4px;
  background: #fdf6ec;
  color: #e6a23c;
  font-size: 13px;
  line-height: 1.5;
}
</style>