WXL
2 天以前 c8e9849cb5f24848df0174c13bfbbff37bb08a5a
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
<template>
  <div class="confirmation-detail">
    <case-basic-info :case-id="caseId" :show-attachment="true" />
 
    <el-card class="detail-card">
      <!-- 基础信息 -->
      <div slot="header" class="clearfix">
        <span class="detail-title">捐献确认信息</span>
        <!-- <el-button
          type="primary"
          style="float: right;margin-left: 20px;"
          @click="handleSave"
          :loading="saveLoading"
        >
          保存确认信息
        </el-button>
        <el-button
          type="success"
          style="float: right;margin-left: 20px;"
          @click="accomplish"
          :loading="saveLoading"
        >
          确认完成
        </el-button> -->
      </div>
 
      <el-form :model="form" ref="form" label-width="120px">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="协调员1" prop="coordinatedusernameo">
              <el-input v-model="form.coordinatedusernameo" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="协调员2" prop="coordinatedusernamet">
              <el-input v-model="form.coordinatedusernamet" />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="8">
            <el-form-item label="业务人员" prop="responsibleusername">
              <el-input v-model="form.responsibleusername" />
            </el-form-item>
          </el-col> -->
        </el-row>
 
        <!-- <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="签字时间" prop="signdate">
              <el-date-picker
                v-model="form.signdate"
                type="datetime"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
        </el-row> -->
 
        <!-- 亲属信息 -->
        <el-divider content-position="left">亲属确认信息</el-divider>
 
        <el-alert
          title="第一条数据为主要亲属,需填写完整的姓名、关系、身份证和电话信息"
          type="info"
          show-icon
          :closable="false"
          style="margin-bottom: 15px;"
        >
        </el-alert>
        <el-row style="margin-top: 15px;">
          <el-button
          style="float: right; margin-bottom: 5px;"
            type="primary"
            size="mini"
            icon="el-icon-plus"
            @click="openFamilyDialog(false)"
          >
            添加其他家属
          </el-button>
        </el-row>
        <el-table :data="familyMemberList" size="small" border>
          <el-table-column label="序号" width="60" align="center">
            <template slot-scope="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column label="姓名" prop="name" min-width="120">
            <template slot-scope="scope">
              <span :class="{ 'main-family': scope.$index === 0 }">{{
                scope.row.name
              }}</span>
            </template>
          </el-table-column>
          <el-table-column label="与捐赠者关系" prop="relation" min-width="140">
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.sys_FamilyRelation"
                :value="scope.row.relation"
              />
            </template>
          </el-table-column>
          <el-table-column label="身份证号" prop="idcard" min-width="180">
            <template slot-scope="scope">
              <span v-if="scope.$index === 0">{{ scope.row.idcard }}</span>
              <span v-else style="color: #909399;">-</span>
            </template>
          </el-table-column>
          <el-table-column label="联系电话" prop="phone" min-width="130">
            <template slot-scope="scope">
              <span v-if="scope.$index === 0">{{ scope.row.phone }}</span>
              <span v-else style="color: #909399;">-</span>
            </template>
          </el-table-column>
          <el-table-column label="类型" width="70" align="center">
            <template slot-scope="scope">
              <el-tag v-if="scope.$index === 0" type="warning" size="small"
                >主要</el-tag
              >
              <el-tag v-else type="info" size="small">其他</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="150" align="center">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="editFamilyMember(scope.$index)"
              >
                编辑
              </el-button>
              <el-button
                v-if="scope.$index > 0"
                size="mini"
                type="text"
                style="color:red"
                @click="deleteFamilyMember(scope.$index)"
              >
                删除
              </el-button>
              <span v-else style="color: #909399; font-size: 12px;"
                >不可删除</span
              >
            </template>
          </el-table-column>
        </el-table>
 
        <el-row>
          <el-form-item label-width="100px" label="捐献决定">
            <el-checkbox-group v-model="organdecision">
              <el-checkbox
                v-for="item in organselection"
                :key="item"
                :label="item"
                >{{ item }}
              </el-checkbox>
            </el-checkbox-group>
            <el-input
              v-if="organdecision.includes('其他')"
              v-model="organdecisionOther"
              placeholder="请输入其他捐献决定的具体内容"
              style="margin-top: 10px; width: 300px;"
            ></el-input>
          </el-form-item>
        </el-row>
 
        <el-form-item label="家属意见备注" prop="relativeRemark">
          <el-input
            type="textarea"
            :rows="3"
            v-model="form.relativeRemark"
            placeholder="记录家属的意见和沟通情况"
          />
        </el-form-item>
      </el-form>
    </el-card>
 
    <!-- 添加这里:底部居中按钮 -->
 
    <!-- 附件信息 - 按类型分类 -->
    <el-card class="attachment-card">
      <div slot="header" class="clearfix">
        <span class="detail-title">相关附件上传</span>
      </div>
 
      <el-tabs v-model="activeAttachmentType" type="card">
        <el-tab-pane
          v-for="type in attachmentTypes"
          :key="type.value"
          :label="type.label"
          :name="type.value"
        >
          <div class="attachment-section">
            <div class="attachment-header">
              <span class="upload-title">{{ type.label }}</span>
              <el-tooltip content="点击上传该类型附件" placement="top">
                <el-button
                  size="mini"
                  type="primary"
                  icon="el-icon-plus"
                  @click="openUploadDialog(type.value)"
                >
                  添加附件
                </el-button>
              </el-tooltip>
            </div>
 
            <div class="attachment-list">
              <el-table
                :data="getAttachmentsByType(type.value)"
                size="small"
                v-loading="attachmentLoading"
                style="width: 100%;"
              >
                <el-table-column label="文件名" min-width="200">
                  <template slot-scope="scope">
                    <i
                      class="el-icon-document"
                      style="color: #409EFF; margin-right: 8px;"
                    ></i>
                    <span class="file-name">{{ scope.row.fileName }}</span>
                  </template>
                </el-table-column>
 
                <el-table-column label="文件类型" width="90" align="center">
                  <template slot-scope="scope">
                    <el-tag size="small">{{
                      getFileType(scope.row.fileName)
                    }}</el-tag>
                  </template>
                </el-table-column>
 
                <el-table-column label="文件大小" width="90" align="center">
                  <template slot-scope="scope">
                    <span>{{ formatFileSize(scope.row.fileSize) }}</span>
                  </template>
                </el-table-column>
 
                <el-table-column label="上传时间" width="155" align="center">
                  <template slot-scope="scope">
                    <span>{{ formatDateTime(scope.row.uploadTime) }}</span>
                  </template>
                </el-table-column>
 
                <el-table-column label="操作" width="145" align="center">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="primary"
                      @click="handlePreview(scope.row)"
                    >
                      预览
                    </el-button>
                    <el-button
                      size="mini"
                      type="danger"
                      @click="handleRemoveAttachment(type.value, scope.$index)"
                    >
                      删除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
 
              <div
                v-if="getAttachmentsByType(type.value).length === 0"
                class="empty-attachment"
              >
                <el-empty
                  :description="`暂无${type.label}附件`"
                  :image-size="80"
                ></el-empty>
              </div>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-card>
    <!-- 底部操作按钮 -->
    <div style="text-align: center; margin: 30px 0;">
      <el-button
        type="primary"
        @click="handleSave"
        :loading="saveLoading"
        style="margin-right: 20px; min-width: 140px;"
      >
        保存确认信息
      </el-button>
      <el-button
        type="success"
        @click="accomplish"
        :loading="saveLoading"
        style="min-width: 140px;"
      >
        确认完成
      </el-button>
    </div>
    <!-- 家属弹窗 -->
    <el-dialog
      :title="familyDialogTitle"
      :visible.sync="familyDialogVisible"
      width="420px"
      :close-on-click-modal="false"
    >
      <el-form :model="currentFamilyMember" label-width="110px">
        <el-form-item label="姓名" prop="name">
          <el-input
            v-model="currentFamilyMember.name"
            placeholder="请输入姓名"
          />
        </el-form-item>
 
        <el-form-item label="与捐赠者关系" prop="relation">
          <el-select
            v-model="currentFamilyMember.relation"
            style="width:100%"
            placeholder="请选择关系"
          >
            <el-option
              v-for="dict in dict.type.sys_FamilyRelation"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
 
        <template v-if="currentFamilyMember.isMain">
          <el-form-item label="身份证号" prop="idcard">
            <el-input
              v-model="currentFamilyMember.idcard"
              placeholder="请输入身份证号"
              maxlength="18"
            />
          </el-form-item>
 
          <el-form-item label="联系电话" prop="phone">
            <el-input
              v-model="currentFamilyMember.phone"
              placeholder="请输入联系电话"
              maxlength="11"
            />
          </el-form-item>
        </template>
      </el-form>
 
      <span slot="footer">
        <el-button @click="familyDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="saveFamilyMember">确定</el-button>
      </span>
    </el-dialog>
 
    <!-- 上传对话框 -->
    <el-dialog
      :title="`上传${getCurrentTypeLabel}附件`"
      :visible.sync="uploadDialogVisible"
      width="480px"
      :close-on-click-modal="false"
    >
      <el-upload
        ref="uploadRef"
        class="upload-demo"
        drag
        :action="uploadAction"
        :headers="headers"
        multiple
        :file-list="tempFileList"
        :before-upload="beforeUpload"
        :on-change="handleFileChange"
        :on-remove="handleTempRemove"
        :on-success="handleUploadSuccess"
        :auto-upload="false"
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">
          支持上传pdf、jpg、png、doc、docx格式文件,单个文件不超过10MB
        </div>
      </el-upload>
 
      <span slot="footer" class="dialog-footer">
        <el-button @click="uploadDialogVisible = false">取消</el-button>
        <el-button
          type="primary"
          @click="submitUpload"
          :loading="uploadLoading"
          :disabled="tempFileList.length === 0"
        >
          确认上传
        </el-button>
      </span>
    </el-dialog>
 
    <!-- 文件预览弹窗 -->
    <FilePreviewDialog
      :visible="previewVisible"
      :file="currentPreviewFile"
      @close="previewVisible = false"
      @download="handleDownload"
    />
  </div>
</template>
 
<script>
import { relativesList, relativesEdit, relativesAdd } from "@/api/businessApi";
import FilePreviewDialog from "@/components/FilePreviewDialog";
import CaseBasicInfo from "@/components/CaseBasicInfo";
import { getToken } from "@/utils/auth";
 
export default {
  name: "ConfirmationDetail",
  components: {
    FilePreviewDialog,
    CaseBasicInfo
  },
  dicts: ["sys_FamilyRelation"],
  data() {
    return {
      caseId: null,
      isEdit: false,
      form: {
        id: undefined,
        infoid: undefined,
        caseNo: "",
        name: "",
        sex: "",
        age: "",
        diagnosisname: "",
        treatmenthospitalname: "",
        coordinatedusernameo: "",
        coordinatedusernamet: "",
        responsibleusername: "",
        relativeconfirmationsign: "0",
        signdate: "",
        relativeconfirmationsignname: "",
        signfamilyrelations: "",
        relativeidcardno: "",
        relativephone: "",
        relativeRemark: "",
        assessannex: "",
        otherFamilyMembers: ""
      },
      // 统一亲属列表(第一条为主要亲属,其余为其他亲属)
      familyMemberList: [],
      // 当前编辑的家属(弹窗用)
      currentFamilyMember: {
        name: "",
        relation: "",
        phone: "",
        idcard: "",
        isMain: false
      },
      isEditFamilyMember: false,
      editFamilyMemberIndex: -1,
      familyDialogVisible: false,
      familyDialogTitle: "添加家属",
 
      uploadAction: process.env.VUE_APP_BASE_API + "/common/upload",
      headers: {
        Authorization: "Bearer " + getToken()
      },
      organdecision: [],
      organdecisionOther: "",
      organselection: [
        "肝脏",
        "肾脏",
        "心脏",
        "肺脏",
        "胰腺",
        "小肠",
        "眼角膜",
        "其他"
      ],
      loading: false,
      saveLoading: false,
      infoid: null,
      activeAttachmentType: "1",
      attachmentLoading: false,
      uploadDialogVisible: false,
      uploadLoading: false,
      tempFileList: [],
      currentUploadType: "",
      previewVisible: false,
      currentPreviewFile: null,
      attachmentTypes: [
        { value: "1", label: "人体器官潜在捐献者登记表" },
        { value: "2", label: "人体器官捐献亲属确认登记表" },
        { value: "3", label: "捐献者及直系亲属身份证、户口簿相关证明" },
        { value: "4", label: "公民身故后人体器官(角膜)遗体捐献告知书" },
        { value: "5", label: "脑死亡判定知情同意书" },
        { value: "6", label: "心死亡判定知情同意书" }
      ],
      attachmentData: {
        "1": [],
        "2": [],
        "3": [],
        "4": [],
        "5": [],
        "6": []
      }
    };
  },
  computed: {
    getCurrentTypeLabel() {
      const type = this.attachmentTypes.find(
        t => t.value === this.currentUploadType
      );
      return type ? type.label : "";
    }
  },
  created() {
    this.infoid = this.$route.query.infoid;
    this.caseId = this.$route.query.infoid;
    this.isEdit = this.$route.query.confirm === "true";
    if (this.infoid) {
      this.getDetail(this.infoid);
    }
  },
  methods: {
    async getDetail(infoid) {
      this.loading = true;
      try {
        const response = await relativesList({ infoid });
        if (response.code === 200) {
          this.handleDetailData(response);
        } else {
          this.$message.error("获取详情失败:" + (response.msg || "未知错误"));
        }
      } catch (error) {
        console.error("获取捐献确认详情失败:", error);
        this.$message.error("获取详情失败");
      } finally {
        this.loading = false;
      }
    },
 
    handleDetailData(response) {
      let detailData = null;
      if (response.data) {
        if (Array.isArray(response.data)) {
          detailData = response.data[0] || {};
        } else if (response.data.rows && Array.isArray(response.data.rows)) {
          detailData = response.data.rows[0] || {};
        } else if (Array.isArray(response.data.list)) {
          detailData = response.data.list[0] || {};
        } else {
          detailData = response.data;
        }
      } else {
        detailData = response;
      }
 
      this.form = {
        ...this.form,
        id: detailData.id || this.$route.query.id,
        infoid: detailData.infoid || this.infoid,
        caseNo: detailData.caseNo || "",
        name: detailData.name || "",
        sex: detailData.sex || "",
        age: detailData.age || "",
        diagnosisname: detailData.diagnosisname || "",
        treatmenthospitalname: detailData.treatmenthospitalname || "",
        coordinatedusernameo: detailData.coordinatedusernameo || "",
        coordinatedusernamet: detailData.coordinatedusernamet || "",
        responsibleusername: detailData.responsibleusername || "",
        relativeconfirmationsign: detailData.relativeconfirmationsign || "0",
        signdate: detailData.signdate,
        relativeconfirmationsignname:
          detailData.relativeconfirmationsignname || "",
        signfamilyrelations: detailData.signfamilyrelations || "",
        relativeidcardno: detailData.relativeidcardno || "",
        relativephone: detailData.relativephone || "",
        relativeRemark: detailData.relativeRemark || "",
        assessannex: detailData.assessannex || ""
      };
 
      // 初始化家属列表
      this.familyMemberList = [];
      if (detailData.relativeconfirmationsignname) {
        this.familyMemberList.push({
          name: detailData.relativeconfirmationsignname,
          relation: detailData.signfamilyrelations || "",
          phone: detailData.relativephone || "",
          idcard: detailData.relativeidcardno || ""
        });
      }
      if (detailData.otherFamilyMembers) {
        try {
          const otherMembers =
            typeof detailData.otherFamilyMembers === "string"
              ? JSON.parse(detailData.otherFamilyMembers)
              : detailData.otherFamilyMembers || [];
          otherMembers.forEach(member => {
            this.familyMemberList.push({
              name: member.name,
              relation: member.relation,
              phone: member.phone || "",
              idcard: member.idcard || ""
            });
          });
        } catch (e) {
          console.warn("解析其他家属数据失败:", e);
        }
      }
 
      if (detailData.organdecision) {
        this.organdecision = Array.isArray(detailData.organdecision)
          ? detailData.organdecision
          : detailData.organdecision.split(",");
      }
 
      this.processAssessannexData();
    },
 
    processAssessannexData() {
      if (this.form.assessannex) {
        try {
          const annexData =
            typeof this.form.assessannex === "string"
              ? JSON.parse(this.form.assessannex)
              : this.form.assessannex;
          Object.keys(this.attachmentData).forEach(key => {
            this.attachmentData[key] = [];
          });
          if (Array.isArray(annexData)) {
            annexData.forEach(attachment => {
              const type = attachment.type || "1";
              if (this.attachmentData[type]) {
                this.attachmentData[type].push(attachment);
              }
            });
          }
        } catch (error) {
          console.warn("assessannex数据解析失败:", error);
        }
      }
    },
 
    getAttachmentsByType(type) {
      return this.attachmentData[type] || [];
    },
 
    openUploadDialog(type) {
      this.currentUploadType = type;
      this.tempFileList = [];
      this.uploadDialogVisible = true;
      this.$nextTick(() => {
        if (this.$refs.uploadRef) {
          this.$refs.uploadRef.clearFiles();
        }
      });
    },
 
    beforeUpload(file) {
      const allowedTypes = [
        "application/pdf",
        "image/jpeg",
        "image/png",
        "application/msword",
        "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
      ];
      const maxSize = 10 * 1024 * 1024;
      const isTypeOk =
        allowedTypes.includes(file.type) ||
        file.name.endsWith(".pdf") ||
        file.name.endsWith(".jpg") ||
        file.name.endsWith(".jpeg") ||
        file.name.endsWith(".png") ||
        file.name.endsWith(".doc") ||
        file.name.endsWith(".docx");
      if (!isTypeOk) {
        this.$message.error(
          "文件格式不支持,请上传pdf、jpg、png、doc或docx格式文件"
        );
        return false;
      }
      if (file.size > maxSize) {
        this.$message.error("文件大小不能超过10MB");
        return false;
      }
      return true;
    },
 
    handleFileChange(file, fileList) {
      this.tempFileList = fileList;
    },
 
    handleTempRemove(file, fileList) {
      this.tempFileList = fileList;
    },
 
    handleUploadSuccess(response, file) {
      if (response.code !== 200) {
        this.$message.error(response.msg || "上传失败");
        return;
      }
      const newAttachment = {
        id: Date.now(),
        fileName: file.name,
        fileUrl: response.url,
        fileSize: file.size,
        fileType: this.getFileExtension(file.name),
        type: this.currentUploadType,
        uploadTime: this.getCurrentTime(),
        uploader: "当前用户"
      };
      this.attachmentData[this.currentUploadType].push(newAttachment);
      this.updateAssessannexField();
      this.$message.success("上传成功");
      this.uploadLoading = false;
      this.uploadDialogVisible = false;
      this.tempFileList = [];
    },
 
    submitUpload() {
      if (this.tempFileList.length === 0) {
        this.$message.warning("请先选择要上传的文件");
        return;
      }
      this.uploadLoading = true;
      this.$refs.uploadRef.submit();
    },
 
    handleRemoveAttachment(type, index) {
      this.$confirm("确定要删除这个附件吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          if (this.attachmentData[type] && this.attachmentData[type][index]) {
            this.attachmentData[type].splice(index, 1);
            this.$message.success("附件删除成功");
            this.updateAssessannexField();
          }
        })
        .catch(() => {});
    },
 
    // 家属操作方法
    openFamilyDialog(isMain) {
      this.isEditFamilyMember = false;
      this.editFamilyMemberIndex = -1;
      this.familyDialogTitle = "添加其他家属";
 
      // 如果还没有任何家属,则添加主要亲属
      if (this.familyMemberList.length === 0) {
        this.currentFamilyMember = {
          name: "",
          relation: "",
          phone: "",
          idcard: "",
          isMain: true
        };
        this.familyDialogTitle = "添加主要亲属";
      } else {
        this.currentFamilyMember = {
          name: "",
          relation: "",
          phone: "",
          idcard: "",
          isMain: false
        };
      }
 
      this.familyDialogVisible = true;
    },
 
    editFamilyMember(index) {
      this.isEditFamilyMember = true;
      this.editFamilyMemberIndex = index;
      const member = this.familyMemberList[index];
      this.currentFamilyMember = {
        name: member.name,
        relation: member.relation,
        phone: member.phone || "",
        idcard: member.idcard || "",
        isMain: index === 0
      };
      this.familyDialogTitle = index === 0 ? "编辑主要亲属" : "编辑其他家属";
      this.familyDialogVisible = true;
    },
 
    deleteFamilyMember(index) {
      if (index === 0) {
        this.$message.warning("主要亲属不可删除");
        return;
      }
      this.$confirm("确认删除该家属?", "提示", { type: "warning" })
        .then(() => {
          this.familyMemberList.splice(index, 1);
          this.updateFamilyMemberField();
        })
        .catch(() => {});
    },
 
    saveFamilyMember() {
      if (!this.currentFamilyMember.name) {
        this.$message.warning("请输入姓名");
        return;
      }
      if (!this.currentFamilyMember.relation) {
        this.$message.warning("请选择与捐赠者关系");
        return;
      }
 
      // 如果是主要亲属,验证身份证和电话
      if (this.currentFamilyMember.isMain) {
        if (!this.currentFamilyMember.idcard) {
          this.$message.warning("请输入主要亲属的身份证号");
          return;
        }
        if (
          !/^(\d{15}|\d{18}|\d{17}(\d|X|x))$/.test(
            this.currentFamilyMember.idcard
          )
        ) {
          this.$message.warning("请输入正确的身份证号");
          return;
        }
        if (!this.currentFamilyMember.phone) {
          this.$message.warning("请输入主要亲属的联系电话");
          return;
        }
        if (!/^1[3-9]\d{9}$/.test(this.currentFamilyMember.phone)) {
          this.$message.warning("请输入正确的手机号");
          return;
        }
      }
 
      const memberData = {
        name: this.currentFamilyMember.name,
        relation: this.currentFamilyMember.relation,
        phone: this.currentFamilyMember.isMain
          ? this.currentFamilyMember.phone
          : "",
        idcard: this.currentFamilyMember.isMain
          ? this.currentFamilyMember.idcard
          : ""
      };
 
      if (this.isEditFamilyMember) {
        this.familyMemberList.splice(this.editFamilyMemberIndex, 1, memberData);
      } else {
        this.familyMemberList.push(memberData);
      }
 
      this.updateFamilyMemberField();
      this.familyDialogVisible = false;
      this.$message.success(this.isEditFamilyMember ? "编辑成功" : "添加成功");
    },
 
    updateFamilyMemberField() {
      if (this.familyMemberList.length > 0) {
        const mainMember = this.familyMemberList[0];
        this.form.relativeconfirmationsignname = mainMember.name;
        this.form.signfamilyrelations = mainMember.relation;
        this.form.relativeidcardno = mainMember.idcard || "";
        this.form.relativephone = mainMember.phone || "";
 
        const otherMembers = this.familyMemberList.slice(1).map(member => ({
          name: member.name,
          relation: member.relation,
          phone: member.phone || "",
          idcard: member.idcard || ""
        }));
        this.form.otherFamilyMembers = JSON.stringify(otherMembers);
      } else {
        this.form.relativeconfirmationsignname = "";
        this.form.signfamilyrelations = "";
        this.form.relativeidcardno = "";
        this.form.relativephone = "";
        this.form.otherFamilyMembers = "[]";
      }
    },
 
    updateAssessannexField() {
      const allAttachments = [];
      Object.values(this.attachmentData).forEach(attachments => {
        allAttachments.push(...attachments);
      });
      this.form.assessannex = JSON.stringify(allAttachments);
    },
 
    handlePreview(file) {
      this.currentPreviewFile = {
        fileName: file.fileName,
        fileUrl: file.fileUrl,
        fileType: this.getFileType(file.fileName)
      };
      this.previewVisible = true;
    },
 
    handleDownload(file) {
      const fileUrl = file.fileUrl;
      const fileName = file.fileName;
      if (fileUrl) {
        const link = document.createElement("a");
        link.href = fileUrl;
        link.download = fileName;
        link.style.display = "none";
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
        this.$message.success("开始下载文件");
      } else {
        this.$message.warning("文件路径不存在,无法下载");
      }
    },
 
    getFileType(fileName) {
      if (!fileName) return "other";
      const extension = this.getFileExtension(fileName);
      const imageTypes = ["jpg", "jpeg", "png"];
      const pdfTypes = ["pdf"];
      const officeTypes = ["doc", "docx"];
      if (imageTypes.includes(extension)) return "image";
      if (pdfTypes.includes(extension)) return "pdf";
      if (officeTypes.includes(extension)) return "office";
      return "other";
    },
 
    getFileExtension(filename) {
      return filename
        .split(".")
        .pop()
        .toLowerCase();
    },
 
    formatFileSize(size) {
      if (!size) return "0 B";
      const k = 1024;
      const sizes = ["B", "KB", "MB", "GB"];
      const i = Math.floor(Math.log(size) / Math.log(k));
      return parseFloat((size / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
    },
 
    formatDateTime(dateTime) {
      if (!dateTime) return "";
      try {
        const date = new Date(dateTime);
        if (isNaN(date.getTime())) return dateTime;
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, "0");
        const day = String(date.getDate()).padStart(2, "0");
        const hours = String(date.getHours()).padStart(2, "0");
        const minutes = String(date.getMinutes()).padStart(2, "0");
        return `${year}-${month}-${day} ${hours}:${minutes}`;
      } catch (error) {
        return dateTime;
      }
    },
 
    getCurrentTime() {
      const now = new Date();
      return `${now.getFullYear()}-${(now.getMonth() + 1)
        .toString()
        .padStart(2, "0")}-${now
        .getDate()
        .toString()
        .padStart(2, "0")} ${now
        .getHours()
        .toString()
        .padStart(2, "0")}:${now
        .getMinutes()
        .toString()
        .padStart(2, "0")}:${now
        .getSeconds()
        .toString()
        .padStart(2, "0")}`;
    },
 
    accomplish() {
      this.$confirm("是否完成该案例捐献确认步骤?", "提醒", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.form.state = 3;
          this.handleSave();
        })
        .catch(() => {});
    },
 
    async handleSave() {
      try {
        await this.$refs.form.validate();
        this.saveLoading = true;
 
        this.updateFamilyMemberField();
        this.updateAssessannexField();
 
        const saveData = {
          ...this.form,
          infoid: this.infoid,
          organdecision: this.organdecision.join(","),
          organdecisionOther: this.organdecisionOther
        };
        if (saveData.state == 1 || !saveData.state) {
          saveData.state = 2;
        }
 
        let response = null;
        if (saveData.id) {
          response = await relativesEdit(saveData);
        } else {
          response = await relativesAdd(saveData);
        }
 
        if (response.code === 200) {
          this.$message.success("保存成功");
          this.$router.push("/case/affirm");
        } else {
          this.$message.error("保存失败:" + (response.msg || "未知错误"));
        }
      } catch (error) {
        if (error !== "cancel") {
          console.error("保存失败:", error);
          this.$message.error("保存失败");
        }
      } finally {
        this.saveLoading = false;
      }
    }
  }
};
</script>
 
<style scoped>
.confirmation-detail {
  padding: 20px;
}
 
.detail-card {
  margin-bottom: 20px;
}
 
.main-family {
  font-weight: bold;
  color: #e6a23c;
}
 
.attachment-card {
  margin-bottom: 20px;
}
 
.detail-title {
  font-size: 16px;
  font-weight: bold;
  margin-right: 20px;
}
 
.attachment-section {
  padding: 15px;
}
 
.attachment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #ebeef5;
}
 
.upload-title {
  font-size: 14px;
  font-weight: 600;
  color: #303133;
}
 
.attachment-list {
  margin-top: 15px;
}
 
.empty-attachment {
  text-align: center;
  padding: 30px 0;
  color: #909399;
}
 
.file-name {
  font-size: 13px;
  color: #606266;
}
</style>