马宇豪
2025-05-27 d0d78b9fbe144326f136ee048bb59d314413032e
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
<template>
    <div class="system-menu-dialog-container">
        <el-dialog :title="reportDialogState.title" v-model="reportDialogState.reportDialogVisible" width="80%">
          <div style="text-align: center;font-size: 20px;font-weight: bolder;color: #0c4995">{{reportDialogState.reportForm.experimentName}}实验安全风险评估报告表(带<span style="color: red">*</span>为填写内容)</div>
            <el-form ref="reportFormRef" :rules="reportDialogState.reportFormRules" :model="reportDialogState.reportForm" size="default" label-width="0">
                <table class="report-table">
                    <th class="m-color b-font" style="text-align: center">实验基本信息</th>
                    <tr>
                        <td class="w-25 m-color">实验名称</td>
                        <td class="w-75 m-color">
                            <el-form-item prop="experimentName">
                                <el-input readonly v-model="reportDialogState.reportForm.experimentName" placeholder="请输入实验名称" />
                            </el-form-item>
                        </td>
                    </tr>
                    <tr>
                        <td class="w-25 m-color">实验类型</td>
                        <td class="w-75" style="text-align: left;padding-left: 11px">
<!--                            <el-radio-group style="text-align: center" disabled v-model="reportDialogState.reportForm.experimentType">-->
<!--                                <el-radio :label="1">化学类</el-radio>-->
<!--                                <el-radio :label="2">生物类</el-radio>-->
<!--                                <el-radio :label="3">辐射类</el-radio>-->
<!--                                <el-radio :label="4">机电类</el-radio>-->
<!--                                <el-radio :label="5">特种设备类</el-radio>-->
<!--                                <el-radio :label="6">其他类</el-radio>-->
<!--                            </el-radio-group>-->
<!--                            {{reportDialogState.experimentTypeList.find(i=>i.id === reportDialogState.reportForm.experimentAndType)?.name}}-->
                          {{typeValue}}
                        </td>
                    </tr>
                    <tr>
                      <td class="w-25 m-color">负责人</td>
                      <td class="w-25 m-color">
<!--                        <el-select style="width: 100%" disabled v-model="reportDialogState.reportForm.liabilityUserId" clearable filterable @change="getLiabilityUserPhone($event)">-->
<!--                          <el-option-->
<!--                              v-for="item in reportDialogState.systemPersonList"-->
<!--                              :key="item.id"-->
<!--                              :value="item.id"-->
<!--                              :label="item.realName"-->
<!--                          ></el-option>-->
<!--                        </el-select>-->
                        <el-input readonly v-model="reportDialogState.reportForm.personUser" />
                      </td>
                      <td class="w-25 m-color">电话</td>
                      <td class="w-25 m-color">
                        <el-input disabled v-model="reportDialogState.reportForm.personUserPhone" />
                      </td>
                    </tr>
                    <tr>
                      <td class="w-25 m-color">安全负责人</td>
                      <td class="w-25 m-color">
<!--                        <el-select v-if="reportDialogState.reportForm.safeLiabilityUserId" style="width: 100%" disabled v-model="reportDialogState.reportForm.safeLiabilityUserId" @change="getSafeLiabilityUserPhone($event)" clearable filterable>-->
<!--                          <el-option-->
<!--                              v-for="item in reportDialogState.allPersonList"-->
<!--                              :key="item.id"-->
<!--                              :value="item.id"-->
<!--                              :label="item.personName"-->
<!--                          ></el-option>-->
<!--                        </el-select>-->
                        <el-input disabled v-model="reportDialogState.reportForm.safePersonUser" />
                      </td>
                      <td class="w-25 m-color">电话</td>
                      <td class="w-25 m-color">
                        <el-input readonly v-model="reportDialogState.reportForm.safePersonUserPhone" />
                      </td>
                    </tr>
                    <tr>
                      <td class="w-25 m-color">部门</td>
                      <td class="w-75 m-color">
                        <el-input readonly v-model="reportDialogState.reportForm.dep" />
                      </td>
                    </tr>
                    <tr class="m-color b-font" style="text-align: center">实验场所</tr>
                    <tr>
                      <td class="w-14 m-color">场所名称</td>
                      <td class="w-14 m-color">所在楼栋</td>
                      <td class="w-14 m-color">房间</td>
                      <td class="w-14 m-color">有无消防设施</td>
                      <td class="w-14 m-color">有无隔断</td>
                      <td class="w-14 m-color">场所性质</td>
                    </tr>
                    <tr v-for="(item,index) in reportDialogState.reportForm.experimentSite" :key="index">
                      <td class="w-14">
<!--                        <el-select disabled filterable v-model="item.siteId">-->
<!--                          <el-option-->
<!--                              v-for="item in reportDialogState.allRoomList"-->
<!--                              :key="item.id"-->
<!--                              :value="item.id"-->
<!--                              :label="item.siteName"-->
<!--                          >-->
<!--                          </el-option>-->
<!--                        </el-select>-->
                        <el-input disabled v-model="item.siteName" />
                      </td>
                      <td class="w-14">
                        <el-input disabled v-model="item.floor" />
                      </td>
                      <td class="w-14">
                        <el-input disabled v-model="item.room" />
                      </td>
                      <td class="w-14">
                        <div>{{item.fireFacilities== 1 ? '有' : item.fireFacilities== 2 ? '无' : ''}}</div>
                      </td>
                      <td class="w-14">
                        <div>{{item.partitionStatus == 1 ? '有' : item.partitionStatus == 2 ? '无' : ''}}</div>
                      </td>
                      <td class="w-14">
                        <div>{{item.siteType}}</div>
                      </td>
                    </tr>
 
                    <tr class="m-color b-font" style="text-align: center">实验概况</tr>
                    <tr>
<!--                        <el-input type="textarea" :autosize="{ minRows: 3}" disabled v-model="reportDialogState.reportForm.experimentDesc" placeholder="(简要描述实验原理、实验步骤、所用试剂或材料设备等)" />-->
                      <el-input type="textarea" :autosize="{ minRows: 3}" disabled v-model="reportDialogState.reportForm.process" placeholder="(简要描述实验原理、实验步骤、所用试剂或材料设备等)" />
                    </tr>
                    <tr class="m-color b-font" style="text-align: center">实验涉及的危险源</tr>
                    <tr>
                      <td class="w-25 m-color">危险源种类</td>
                      <td class="w-75 m-color">
<!--                        <el-radio-group disabled v-model="reportDialogState.reportForm.dangerSource">-->
<!--                          <el-radio :label="1">化学安全</el-radio>-->
<!--                          <el-radio :label="2">辐射安全</el-radio>-->
<!--                          <el-radio :label="3">特种设备安全</el-radio>-->
<!--                          <el-radio :label="4">机电安全</el-radio>-->
<!--                          <el-radio :label="5">电气安全</el-radio>-->
<!--                          <el-radio :label="6">生物安全</el-radio>-->
<!--                          <el-radio :label="7">激光安全</el-radio>-->
<!--                          <el-radio :label="8">其他安全</el-radio>-->
<!--                        </el-radio-group>-->
                        <el-checkbox-group disabled class="checkTip">
                          <el-checkbox v-for="item in reportDialogState.reportForm.riskSourceType" :label="item.riskSourceType" :checked="item.status==1?true:false"/>
                        </el-checkbox-group>
                      </td>
                    </tr>
 
                    <select-danger ref="selectDangerRef" v-model:data="reportDialogState.reportForm.riskSource" v-model:disabled="reportDialogState.disabled"></select-danger>
 
<!--                    <tr class="m-color b-font required" style="text-align: center">安全风险分析(总结)</tr>-->
<!--                    <tr>-->
<!--                      <el-input type="textarea" :autosize="{ minRows: 3}" :disabled="reportDialogState.disabled" v-model="reportDialogState.reportForm.safeRiskAnalysis" placeholder="1.实验过程中是否有爆炸、火灾、腐蚀、中毒风险、产生危险废弃物等(根据危险源清单,分析实验过程中可能对人身安全、人体健康、实验室环境和周边环境等带来的负面影响)" />-->
<!--                    </tr>-->
 
                    <tr class="m-color b-font required" style="text-align: center">安全风险分析(总结)</tr>
                    <tr>
                      <el-input type="textarea" :autosize="{ minRows: 3}" :disabled="reportDialogState.disabled" v-model="reportDialogState.reportForm.safeRiskAnalysis" placeholder="1.实验过程中是否有爆炸、火灾、腐蚀、中毒风险、产生危险废弃物等(根据危险源清单,分析实验过程中可能对人身安全、人体健康、实验室环境和周边环境等带来的负面影响)" />
                    </tr>
                    <tr class="m-color b-font" style="text-align: center">拟采取的防护和应急措施</tr>
                    <tr>
                      <el-input type="textarea" :autosize="{ minRows: 3}" disabled v-model="reportDialogState.reportForm.emergencyMeasure" placeholder="" />
                    </tr>
                    <tr class="m-color b-font required" style="text-align: center">实验和实验项目综合风险等级评定</tr>
                    <tr>
                      <td class="m-color" style="width: 100%;height: 65px">
                        <el-radio-group :disabled="reportDialogState.disabled"  v-model="reportDialogState.reportForm.assessLevel" class="checkTip">
                            <div style="display: flex;justify-content: center">
                                <div style="display: flex;flex-direction: column">
                                    <el-radio :label="1">重大风险(一级)</el-radio>
                                    <el-tag v-if="reportDialogState.reportForm.assessLevel == 1" class="tag-style tag-bg1" />
                                </div>
                                <div style="display: flex;flex-direction: column">
                                    <el-radio :label="2">较大风险(二级)</el-radio>
                                    <el-tag v-if="reportDialogState.reportForm.assessLevel == 2" class="tag-style tag-bg2"  />
                                </div>
                                <div style="display: flex;flex-direction: column">
                                    <el-radio :label="3">一般风险(三级)</el-radio>
                                    <el-tag v-if="reportDialogState.reportForm.assessLevel == 3" class="tag-style tag-bg3"  />
                                </div>
                                <div style="display: flex;flex-direction: column">
                                    <el-radio :label="4">低风险(四级)</el-radio>
                                    <el-tag v-if="reportDialogState.reportForm.assessLevel == 4" style="width: 43px;margin-left: 20px;" class="tag-bg4" />
                                </div>
                            </div>
                        </el-radio-group>
                      </td>
                    </tr>
                    <tr>
                      <el-input type="textarea" :autosize="{ minRows: 3}" :disabled="reportDialogState.disabled" v-model="reportDialogState.reportForm.description" placeholder="评定依据(必填)" />
                    </tr>
                    <tr>
                      <td class="w-25 m-color required">评估人</td>
                      <td class="w-75 m-color">
                        <!--                        <el-select style="width: 100%" :disabled="reportDialogState.disabled" v-model="reportDialogState.reportForm.assessPerson" clearable filterable>-->
                        <!--                          <el-option-->
                        <!--                              v-for="item in reportDialogState.allPersonList"-->
                        <!--                              :key="item.id"-->
                        <!--                              :value="item.id"-->
                        <!--                              :label="item.personName"-->
                        <!--                          ></el-option>-->
                        <!--                        </el-select>-->
                        <el-input :disabled="reportDialogState.disabled" v-model="reportDialogState.reportForm.assessPerson" placeholder="评估人" />
                      </td>
                      <!--                      <td class="w-25 m-color required">评估时间</td>-->
                      <!--                      <td class="w-25 m-color">-->
                      <!--                        <el-date-picker :disabled="reportDialogState.disabled"  type="datetime" format="YYYY/MM/DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" v-model="reportDialogState.reportForm.assessTime" />-->
                      <!--                      </td>-->
                    </tr>
                    <tr v-if="reportDialogState.reportForm.person?.length>0" class="m-color b-font" style="text-align: center">审批内容</tr>
                  <template v-if="reportDialogState.reportForm.person?.length > 0">
                    <template v-for="item in reportDialogState.reportForm.person">
                      <tr>
                        <td class="w-25 m-color">{{item.approveStage}}</td>
                        <td class="w-25">{{item.approvePerson}}</td>
                        <td class="w-25 m-color">审批结果</td>
                        <td class="w-25" :class="item.approveStatus==3?'redTit':''">{{item.approveStatus==1?'未审批':item.approveStatus==2?'通过':'未通过'}}</td>
                      </tr>
                      <tr>
                        <td class="w-25 m-color autoheight">审批意见</td>
                        <td class="w-75 autoheight l-border">
                          {{ item.approveDesc }}
                        </td>
                      </tr>
                    </template>
                  </template>
                </table>
            </el-form>
            <template #footer>
              <span class="dialog-footer" style="padding-top:10px;text-align: center !important;">
                <el-button @click="reportDialogState.reportDialogVisible = !reportDialogState.reportDialogVisible" size="default">取 消</el-button>
                <el-button type="primary" v-if="!reportDialogState.disabled" @click="onSubmitProject()" size="default">提交审批</el-button>
                <el-button type="primary" v-if="reportDialogState.disabled" @click="startGeneration()" size="default">导出评估报告</el-button>
              </span>
            </template>
        </el-dialog>
    </div>
</template>
 
<script setup lang="ts">
import {defineAsyncComponent, nextTick, onMounted, reactive, ref} from "vue";
import {generateWordDocument} from "/@/views/experiment/developing/components/exportWord.js";
import {ElMessage} from "element-plus";
import {projectApi} from "/@/api/experiment/project";
import {personApi} from "/@/api/basic/person";
import {userApi} from "/@/api/systemManage/user";
import {roomApi} from "/@/api/basic/room";
import {assessApplyApi} from "/@/api/analyse/assessApply";
const typeValue = ref([])
const SelectDanger = defineAsyncComponent(() => import('./selectDanger.vue'))
const selectDangerRef = ref()
const reportFormRef = ref()
const reportDialogState = reactive<ReportDialogType>({
    title: '',
    disabled: false,
    reportDialogVisible: false,
    reportForm: {
        id: null,
        experimentName: "",
        experimentType: null,
        personUser: '',
        personUserId: null,
        personUserPhone: '',
        safePersonUserId: null,
        safePersonUser: '',
        safePersonUserPhone: '',
        dep: "",
        experimentSite: [],
        experimentDesc: '',
        emergencyMeasure: '',
        assessPerson:'',
        safeRiskAnalysis: '',
        assessLevel:null,
        riskSource: [],
        riskSourceType: [],
        description: '',
        person:[],
        process: '',
      experimentAndType: [],
      oldRiskAssess: []
    },
    reportFormRules: {
      assessPerson: [{ required: true, message: '请填写评估人员', trigger: 'blur' }],
      safeRiskAnalysis: [{ required: true, message: '请填写安全风险分析', trigger: 'blur' }],
      assessLevel: [{ required: true, message: '请选择风险等级评定', trigger: 'blur' }],
      description: [{ required: true, message: '请填写风险等级评定依据', trigger: 'blur' }],
    },
    allPersonList: [],
    allRoomList: [],
    phaList: [],
    details: {},
    systemPersonList: [],
    experimentTypeList: [
      {id: 1, name: '化学类'},
      {id: 2, name: '生物类'},
      {id: 3, name: '辐射类'},
      {id: 4, name: '机电类'},
      {id: 5, name: '特种设备类'},
      {id: 6, name: '其它类'}
    ],
  stuffTypeList: [
    {id: 1, name: '化学试剂'},
    {id:2, name: '基础材料'}
  ],
  stuffStorageList: [
    {id:1, name: '智能试剂柜'},
    {id:2, name: '普通储存柜'},
  ],
  stuffUnitList: [
    {id:1, name: 'g'},
    {id:2, name: 'kg'},
    {id:3, name: 'ml'},
    {id:4, name: 'l'},
  ],
  classifyList:[
    {id:1, name: '有机'},
    {id:2, name: '酸'},
    {id:3, name: '碱性'},
    {id:4, name: '固体废弃物'},
    {id:5, name: '医疗废弃物'},
    {id:6, name: '过期化学品'},
    {id:7, name: '其他'}
  ],
  wasteStorageList: [
    {id:1, name: '吨袋'},
    {id:2, name: '吨桶'},
    {id:3, name: '小桶'},
    {id:4, name: '托盘'},
    {id:5, name: '其他'},
  ],
  riskSourceTypeList: [
    {id: 1, name: '化学安全'},
    {id: 2, name: '辐射安全'},
    {id: 3, name: '生物安全'},
    {id: 4, name: '机电安全'},
    {id: 5, name: '电气安全'},
    {id: 6, name: '激光安全'},
    {id: 7, name: '特种设备安全'},
    {id: 8, name: '其他安全'},
  ],
  riskLevelList: [
    {id: 1, name: '重大风险(一级)'},
    {id: 2, name: '较大风险(二级)'},
    {id: 3, name: '一般风险(三级)'},
    {id: 4, name: '低风险(四级)'},
  ],
})
 
const showReportDialog = (title: string, value: ProjectType, allRoomList: RoomType []) => {
    getReportData(value.id)
    reportDialogState.details = value
    reportDialogState.reportDialogVisible = true;
    reportDialogState.allRoomList = allRoomList
    setTimeout(() => {
        reportFormRef.value.clearValidate();
    });
    if(title === '提交'){
      reportDialogState.title = '提交报告';
      reportDialogState.disabled = false
      // for(let i in reportDialogState.reportForm) {
      //   if(isValidKey(i, reportDialogState.reportForm)) {
      //     reportDialogState.reportForm[i] = value[i];
      //   }
      // }
      reportDialogState.reportForm.riskSource = []
      setTimeout(()=>{
        selectDangerRef.value.dangerSourceState.dangerList = []
      },2000)
    }else if(title === '修改'){
      reportDialogState.title = '修改报告';
      reportDialogState.disabled = false
    }else{
        reportDialogState.title = '查看';
        reportDialogState.disabled = true
        // for(let i in reportDialogState.reportForm) {
        //     if(isValidKey(i, reportDialogState.reportForm)) {
        //         reportDialogState.reportForm[i] = value[i];
        //     }
        // }
    }
};
 
const isValidKey = (key: string | number | symbol, object:object): key is keyof typeof object =>{
    return key in object;
};
 
const getReportData = async (id:number|null|undefined) => {
  let res = await assessApplyApi().getRiskReportPage({
    experimentId: id,
    pageIndex: 1,
    pageSize: 10,
    tag: 3,
    exportTag:true
  });
  if(res.data.code === 100){
    reportDialogState.reportForm = {
      id: null,
      experimentName: "",
      experimentType: null,
      personUser: '',
      personUserId: null,
      personUserPhone: '',
      safePersonUserId: null,
      safePersonUser: '',
      safePersonUserPhone: '',
      dep: "",
      experimentSite: [],
      experimentDesc: '',
      emergencyMeasure: '',
      assessPerson:'',
      safeRiskAnalysis: '',
      assessLevel:null,
      riskSource: [],
      riskSourceType: [],
      description: '',
      person:[],
      process: '',
      experimentAndType: [],
      oldRiskAssess: []
    }
    if(res.data.data&&res.data.data.length==0){
      ElMessage({
        type: 'warning',
        message: '暂时无法获取实验信息,可能评估流程未完成,用户无法查看'
      });
    }else{
      for(let i in reportDialogState.reportForm) {
        if(isValidKey(i, reportDialogState.reportForm)) {
          reportDialogState.reportForm[i] = res.data.data[0][i];
        }
      }
      reportDialogState.phaList = res.data.data[0].riskPlanMethodBO ?res.data.data[0].riskPlanMethodBO: []
      const arr = reportDialogState.reportForm.experimentAndType.map(item => item.type.experimentType)
      typeValue.value = arr.join(',')
    }
  }else{
    ElMessage({
      type: 'warning',
      message: res.data.msg
    });
  }
};
 
// const getLiabilityUserPhone = (value: number)=>{
//   const data = reportDialogState.systemPersonList.find(item => item.id === value) as AllPersonListType
//   reportDialogState.reportForm.liabilityUserPhone = data.phone
// }
//
// const getSafeLiabilityUserPhone = (value: number)=>{
//   const data = reportDialogState.allPersonList.find(item => item.id === value) as AllPersonListType
//   reportDialogState.reportForm.safeLiabilityUserPhone = data.phone
// }
 
// const hasSafeSystem = (value: number) =>{
//   if(value == 2){
//     reportDialogState.reportForm.safeInformationSystem = ''
//   }
// }
 
const onSubmitProject = () => {
    reportFormRef.value.validate(async(valid: boolean) => {
        if(valid){
          reportDialogState.reportForm.riskSource = selectDangerRef.value.dangerSourceState.dangerList
          const { id,assessPerson,riskSource,safeRiskAnalysis,assessLevel,description } = reportDialogState.reportForm
          const data = { id,assessPerson,riskSource,safeRiskAnalysis,assessLevel,description }
            if(reportDialogState.title === '提交报告'){
              for(let i in data.riskSource){
                riskSource[i].reportId = data.id
                riskSource[i].riskSourceIndex = i + 1
              }
                let res = await assessApplyApi().updateRiskReport(data);
                if(res.data.code === 100){
                    emit('refresh')
                    reportDialogState.reportDialogVisible = false;
                    ElMessage({
                        type: 'success',
                        message: '提交报告成功'
                    })
                }else{
                    ElMessage({
                        type: 'warning',
                        message: res.data.msg,
                    });
                }
            }else{
                let res = await assessApplyApi().updateRiskReportInfo(data)
                if(res.data.code === 100){
                  emit('refresh')
                  reportDialogState.reportDialogVisible = false;
                  ElMessage({
                    type: 'success',
                    message: '修改报告成功'
                  })
                }else{
                  ElMessage({
                    type: 'warning',
                    message: res.data.msg,
                  });
                }
            }
        }else{
            ElMessage({
                type: 'warning',
                message: '请完善基本信息',
            });
        }
    })
};
 
const getPersonList = async () => {
    let res = await userApi().getUserList({
        pageIndex: 1,
        pageSize: 99999,
        searchParams:{
          roleId: null,
          name: '',
          realName: ''
        }
    });
    if(res.data.code === 100){
        reportDialogState.systemPersonList = JSON.parse(JSON.stringify(res.data.data));
    }else{
        ElMessage({
            type: 'warning',
            message: res.data.msg
        })
    }
};
 
const getAllPersonList = async () => {
    let res = await personApi().getAllPerson();
    if(res.data.code === 100){
        reportDialogState.allPersonList = JSON.parse(JSON.stringify(res.data.data));
    }else{
        ElMessage({
            type: 'warning',
            message: res.data.msg
        })
    }
};
 
const templatePath = '/static/exampleScience.docx'
 
const startGeneration = async () => {
  let data = JSON.parse(JSON.stringify(reportDialogState.reportForm))
  const experimentTypeNameList = data.experimentAndType.map(item => {
    return {
      id: item.type.id,
      experimentType: item.type.experimentType
    }
  })
 
  const experimentTypeListExample =  JSON.parse(JSON.stringify(reportDialogState.experimentTypeList))
  experimentTypeListExample.forEach(item => {
    if(experimentTypeNameList.some(i => i.experimentType == item.name)){
      item.label = item.name
      item.checked = false
    }else {
      item.label = item.name
      item.checked = true
    }
  })
  data.typeList = experimentTypeListExample
  data.depNameList = data.dep
  const siteTest = data.experimentSite.map(item => item.siteName)
  data.siteList = siteTest.join(',')
 
  const riskType = data.riskSourceType.filter(item => item.status == 1)
  const riskListExample = reportDialogState.riskSourceTypeList
  riskListExample.forEach(item => {
    if(riskType.some(i => i.riskSourceType === item.name)){
      item.label = item.name
      item.checked = false
    }else {
      item.label = item.name
      item.checked = true
    }
  })
  data.riskList = riskListExample
 
  const level = data.assessLevel.toString().split(',')
  const levelExample =  JSON.parse(JSON.stringify(reportDialogState.riskLevelList))
  levelExample.forEach(item => {
    if(level.some(i => i == item.id)){
      item.label = item.name
      item.checked = false
    }else {
      item.label = item.name
      item.checked = true
    }
  })
  data.riskLevel = levelExample
  data.tableData = data.oldRiskAssess ?data.oldRiskAssess: []
  data.phaData = reportDialogState.phaList?reportDialogState.phaList.map(item=>{
    return {
      ...item,
      riskLevelName: item.riskLevel == 1?'低风险':item.riskLevel == 2?'一般风险':item.riskLevel == 3?'较大风险':item.riskLevel == 4?'重大风险':'--'
    }
  }):[]
  data.siteData = data.experimentSite?data.experimentSite.map(item=>{
    return {
      ...item,
      hasFireFacilities: item.fireFacilities== 1 ? '有' : item.fireFacilities== 2 ? '无' : '',
      hasPartitionStatus: item.partitionStatus == 1 ? '有' : item.partitionStatus == 2 ? '无' : ''
    }
  }):[]
  data.materialData = reportDialogState.details.stuffList?reportDialogState.details.stuffList.map(item=>{
    return {
      ...item,
      typeName: reportDialogState.stuffTypeList.find(i=>i.id == item.stuffType)?.name,
      storageName: reportDialogState.stuffStorageList.find(i=>i.id == item.stuffStorage)?.name,
      unitName: reportDialogState.stuffUnitList.find(i=>i.id == item.stuffUnit)?.name
    }
  }):[]
  data.equipData = reportDialogState.details.deviceList?reportDialogState.details.deviceList.map(item=>{
    return {
      ...item,
      isSpecial: item.specialDevice == 1 ? '是' : item.specialDevice == 2 ? '否' : ''
    }
  }):[]
  data.dangerData = reportDialogState.details.hazardousWasteList?reportDialogState.details.hazardousWasteList.map((item,index)=>{
    return {
      ...item,
      sort: index + 1,
      classifyName: reportDialogState.classifyList.find(i=>i.id == item.classify)?.name,
      wasteStorageName: reportDialogState.wasteStorageList.find(i=>i.id == item.wasteStorage)?.name
    }
  }):[]
  data.peopleData = reportDialogState.details.persons?reportDialogState.details.persons.map((item,index)=>{
    return {
      ...item,
      sex: item.personGender == 1 ? '男' : item.personGender == 2 ? '女' : ''
    }
  }):[]
  data.emergyData = reportDialogState.details.emergencyList?reportDialogState.details.emergencyList:[]
  const {experimentStep,experimentMethod,process,keyProcess,measure,timeout,timeoutManager,closed,unclosedManager,explosionProof,fireProof,poisonProof} = reportDialogState.details
  data = {...data,experimentStep,experimentMethod,process,keyProcess,measure,timeout:timeout == 1?'存在':timeout == 2?'不存在':'',timeoutManager,closed:closed == 1?'存在':closed == 2?'不存在':'',unclosedManager,explosionProof,fireProof,poisonProof}
 
  data.riskSource = data.riskSource ? data.riskSource.map(item => {
    return {
      ...item,
      description: item.description ? item.description: ''
    }
  }) :  []
 
  data.safeRiskAnalysis = data.safeRiskAnalysis ?data.safeRiskAnalysis : ''
 
  try {
    generateWordDocument(templatePath, data, `材料科学姑苏实验室安全风险评估表---${data.experimentName}.docx`);
  } catch (error){
    ElMessage({
      type: 'warning',
      message: '失败'
    });
  }
};
 
const emit = defineEmits(['refresh']);
 
defineExpose({
    showReportDialog,
});
 
onMounted(() => {
    getAllPersonList();
    getPersonList()
});
</script>
 
<style scoped lang="scss">
.site-layout-background {
    background: #fff;
}
 
.report-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #337ecc;
    margin: 20px 0;
 
th {
    padding: 10px 0;
    border: 1px solid #337ecc;
    border-left: none;
}
 
tr {
    width: 100%;
    height: 44px;
    line-height: 42px;
    border-bottom: 1px solid #ccc;
 
  &.required {
    &::before {
      content: "*";
      display: inline-block;
      color: red;
    }
  }
 
&:last-of-type {
     border-bottom: none;
 }
 
td {
    border-right: 1px solid #ccc;
    display: inline-block;
    height: 44px;
    vertical-align: middle;
    text-align: center;
    line-height: 42px;
 
  :deep(.el-input__wrapper ){
    box-shadow: none;
    margin-top: 6px;
  }
 
&:last-of-type {
     border-right: none;
 }
 
&.required {
  &::before {
    content: "*";
    display: inline-block;
    color: red;
  }
}
 
&.w-14 {
     width: calc((100/7)/100 * 100%);
 }
 
&.w-16 {
     width: calc((100/6)/100 * 100%);
 }
 
&.w-18 {
     width: 16.59%;
 }
 
&.w-20 {
     width: 20%;
 }
 
&.w-25 {
     width: 25%;
 }
 
&.w-50 {
     width: 50%;
 }
 
&.w-75 {
     width: 75%;
 }
 
&.redTit{
  color: red;
}
 
.ant-input {
    height: 100%;
    border: none;
    background: #f5f7fa;
}
 
.ant-picker {
    width: 100%;
    height: 100%;
}
}
}
 
.b-font {
    font-size: 16px;
    font-weight: bolder;
}
}
 
.m-color {
    color: #0c4995;
}
.tag-style{
    width: 58px;
    margin-left: 20px;
}
.tag-bg1 {
    background: rgba(255,0,0,0.65);
}
.tag-bg2 {
    background: rgba(248,82,8,0.65);
}
.tag-bg3 {
    background: rgba(247,255,0,0.65);
}
.tag-bg4 {
    background: rgba(0,112,192,0.65);
}
.roomSelect{
  ::v-deep(.el-popper){
    .el-select-dropdown__item{
      height: auto;
      padding: 0;
 
      .roomTable{
        width: 100%;
        display: flex;
        border-bottom: 1px solid #ebeef5;
 
        &:last-of-type{
          border-bottom: none;
        }
 
        &>div{
          width: 25%;
          border-right: 1px dashed #ebeef5;
          &:last-of-type{
            border-right: none;
          }
 
          div{
            width: 100%;
          }
          .roomTit{
            border-bottom: 1px solid #ebeef5;
          }
        }
      }
    }
    .el-select-dropdown__item.selected{
      .roomTit{
        color: #606266;
        font-weight: normal;
      }
    }
  }
}
 
:deep(.el-dialog__footer){
    padding-top: 20px;
    display: flex;
    justify-content: center;
}
:deep(.el-tag){
    border: none;
}
 
 
</style>
<style>
.checkTip{
  .is-disabled{
    .el-checkbox__label{
      color: #606266 !important
    }
    .el-radio__label{
      color: #606266 !important
    }
    &.is-checked{
      .el-checkbox__label{
        color: #409eff !important
      }
      .el-radio__label{
        color: #409eff !important
      }
      .el-checkbox__inner{
        background-color: #409eff;
        &::after{
          border-color: #fff !important
        }
      }
      .el-radio__inner{
        background-color: #409eff !important;
        &::after{
          background-color: #fff !important
        }
      }
    }
  }
}
</style>