WXL
2025-12-30 e2eb5acfb3961315df21abfe6f33a959699b562b
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
<template>
  <div class="organ-allocation-detail">
    <!-- 基本信息部分 -->
    <el-card class="detail-card">
      <div slot="header" class="clearfix">
        <span class="detail-title">器官分配基本信息</span>
        <div style="float: right;">
          <el-button type="primary" @click="handleSave" :loading="saveLoading">
            保存
          </el-button>
          <el-button
            type="success"
            @click="handleAllocate"
            :disabled="form.allocationStatus === 'allocated'"
          >
            确认分配
          </el-button>
        </div>
      </div>
 
      <el-form :model="form" ref="form" :rules="rules" label-width="120px">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="住院号" prop="hospitalNo">
              <el-input v-model="form.hospitalNo" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="住院号" prop="caseNo">
              <el-input v-model="form.caseNo" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="捐献者姓名" prop="donorName">
              <el-input v-model="form.donorName" />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="性别" prop="gender">
              <el-select v-model="form.gender" style="width: 100%">
                <el-option label="男" value="0" />
                <el-option label="女" value="1" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="年龄" prop="age">
              <el-input v-model="form.age" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="出生日期" prop="birthDate">
              <el-date-picker
                v-model="form.birthDate"
                type="date"
                value-format="yyyy-MM-dd"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="疾病诊断" prop="diagnosis">
              <el-input
                type="textarea"
                :rows="2"
                v-model="form.diagnosis"
                placeholder="请输入疾病诊断信息"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="分配时间" prop="allocationTime">
              <el-date-picker
                v-model="form.allocationTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 100%"
                :disabled="form.allocationStatus !== 'allocated'"
              />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="登记人" prop="registrant">
              <el-input v-model="form.registrant" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="登记时间" prop="registrationTime">
              <el-date-picker
                v-model="form.registrationTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 100%"
                readonly
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
 
    <!-- 器官分配记录部分 -->
    <el-card class="allocation-card">
      <div slot="header" class="clearfix">
        <span class="detail-title">器官分配记录</span>
        <div style="float: right;">
          <el-tag
            :type="
              form.allocationStatus === 'allocated' ? 'success' : 'warning'
            "
          >
            {{ form.allocationStatus === "allocated" ? "已分配" : "待分配" }}
          </el-tag>
        </div>
      </div>
 
      <el-form
        ref="allocationForm"
        :rules="allocationRules"
        :model="allocationData"
        label-position="right"
      >
        <el-row>
          <el-col>
            <el-form-item label-width="100px" label="分配器官">
              <el-checkbox-group
                v-model="selectedOrgans"
                @change="handleOrganSelectionChange"
              >
                <el-checkbox
                  v-for="organ in organDict"
                  :key="organ.value"
                  :label="organ.value"
                  :disabled="form.allocationStatus === 'allocated'"
                >
                  {{ organ.label }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row>
          <el-col>
            <el-form-item>
              <el-table
                :data="allocationData.records"
                v-loading="loading"
                border
                style="width: 100%"
                :row-class-name="getOrganRowClassName"
              >
                <el-table-column
                  label="器官名称"
                  align="center"
                  width="120"
                  prop="organName"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.organName"
                      placeholder="器官名称"
                      :disabled="true"
                    />
                  </template>
                </el-table-column>
 
                <el-table-column
                  label="分配系统编号"
                  align="center"
                  width="150"
                  prop="systemNo"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.systemNo"
                      placeholder="分配系统编号"
                      :disabled="form.allocationStatus === 'allocated'"
                    />
                  </template>
                </el-table-column>
 
                <el-table-column
                  label="分配接收时间"
                  align="center"
                  width="180"
                  prop="applicantTime"
                >
                  <template slot-scope="scope">
                    <el-date-picker
                      clearable
                      size="small"
                      style="width: 100%"
                      v-model="scope.row.applicantTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择分配接收时间"
                      :disabled="form.allocationStatus === 'allocated'"
                    />
                  </template>
                </el-table-column>
 
                <el-table-column
                  label="受体姓氏"
                  align="center"
                  width="120"
                  prop="recipientName"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.recipientName"
                      placeholder="受体姓氏"
                      :disabled="form.allocationStatus === 'allocated'"
                    />
                  </template>
                </el-table-column>
 
                <el-table-column
                  label="移植医院"
                  align="center"
                  width="200"
                  prop="transplantHospitalNo"
                >
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.transplantHospitalNo"
                      placeholder="请选择移植医院"
                      style="width: 100%"
                      :disabled="form.allocationStatus === 'allocated'"
                      @change="handleHospitalChange(scope.row, $event)"
                    >
                      <el-option
                        v-for="hospital in hospitalList"
                        :key="hospital.hospitalNo"
                        :label="hospital.hospitalName"
                        :value="hospital.hospitalNo"
                      />
                    </el-select>
                  </template>
                </el-table-column>
 
                <el-table-column
                  label="说明"
                  align="center"
                  prop="reallocationReason"
                  min-width="200"
                >
                  <template slot-scope="scope">
                    <el-input
                      type="textarea"
                      clearable
                      v-model="scope.row.reallocationReason"
                      placeholder="请输入说明"
                      :disabled="form.allocationStatus === 'allocated'"
                    />
                  </template>
                </el-table-column>
 
                <el-table-column
                  label="操作"
                  align="center"
                  width="120"
                  class-name="small-padding fixed-width"
                  v-if="form.allocationStatus !== 'allocated'"
                >
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-copy-document"
                      @click="handleRedistribution(scope.row)"
                      :disabled="!scope.row.systemNo"
                    >
                      重分配
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-form-item>
          </el-col>
        </el-row>
 
        <!-- 分配统计信息 -->
        <div class="allocation-stats" v-if="allocationData.records.length > 0">
          <el-row :gutter="20">
            <el-col :span="6">
              <div class="stat-item">
                <span class="stat-label">已分配器官:</span>
                <span class="stat-value"
                  >{{ allocationData.records.length }} 个</span
                >
              </div>
            </el-col>
            <el-col :span="6">
              <div class="stat-item">
                <span class="stat-label">待完善信息:</span>
                <span class="stat-value">{{ incompleteRecords }} 个</span>
              </div>
            </el-col>
            <el-col :span="6">
              <div class="stat-item">
                <span class="stat-label">涉及医院:</span>
                <span class="stat-value">{{ uniqueHospitals }} 家</span>
              </div>
            </el-col>
            <el-col :span="6">
              <div class="stat-item">
                <span class="stat-label">分配状态:</span>
                <span class="stat-value">
                  <el-tag
                    :type="
                      form.allocationStatus === 'allocated'
                        ? 'success'
                        : 'warning'
                    "
                  >
                    {{
                      form.allocationStatus === "allocated"
                        ? "已完成"
                        : "进行中"
                    }}
                  </el-tag>
                </span>
              </div>
            </el-col>
          </el-row>
        </div>
 
        <div v-else class="empty-allocation">
          <el-empty description="暂无分配记录" :image-size="80">
            <span>请先选择要分配的器官</span>
          </el-empty>
        </div>
      </el-form>
 
      <div class="dialog-footer" v-if="form.allocationStatus !== 'allocated'">
        <el-button
          type="primary"
          @click="handleSaveAllocation"
          :loading="saveLoading"
          :disabled="allocationData.records.length === 0"
        >
          保存分配记录
        </el-button>
        <el-button
          type="success"
          @click="handleConfirmAllocation"
          :loading="confirmLoading"
          :disabled="incompleteRecords > 0"
        >
          确认完成分配
        </el-button>
      </div>
    </el-card>
 
    <!-- 附件管理部分 -->
    <el-card class="attachment-card">
      <div slot="header" class="clearfix">
        <span class="detail-title">相关附件</span>
        <upload-attachment
          :file-list="attachments"
          @change="handleAttachmentChange"
          :limit="10"
          :accept="'.pdf,.jpg,.jpeg,.png,.doc,.docx'"
        />
      </div>
 
      <div class="attachment-list">
        <el-table :data="attachments" style="width: 100%">
          <el-table-column label="文件名称" min-width="200">
            <template slot-scope="scope">
              <div class="file-info">
                <i
                  :class="getFileIcon(scope.row.fileName)"
                  style="margin-right: 8px; color: #409EFF;"
                ></i>
                <span>{{ scope.row.fileName }}</span>
              </div>
            </template>
          </el-table-column>
 
          <el-table-column label="文件类型" width="100" 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="100" align="center">
            <template slot-scope="scope">
              <span>{{ formatFileSize(scope.row.fileSize) }}</span>
            </template>
          </el-table-column>
 
          <el-table-column label="上传时间" width="160" align="center">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.uploadTime) }}</span>
            </template>
          </el-table-column>
 
          <el-table-column label="操作" width="150" align="center">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="handlePreviewAttachment(scope.row)"
                >预览</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-download"
                @click="handleDownloadAttachment(scope.row)"
                >下载</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                style="color: #F56C6C;"
                @click="handleRemoveAttachment(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
    <!-- 附件预览对话框 -->
    <attachment-preview
      :visible="attachmentPreviewVisible"
      :file-list="currentAttachmentList"
      :title="attachmentPreviewTitle"
      @close="attachmentPreviewVisible = false"
    />
    <!-- 重分配对话框 -->
    <el-dialog
      title="器官重分配"
      :visible.sync="redistributionDialogVisible"
      width="500px"
    >
      <el-form :model="redistributionForm" label-width="100px">
        <el-form-item label="原器官信息">
          <el-input v-model="redistributionForm.organName" readonly />
        </el-form-item>
        <el-form-item label="重分配原因" prop="reason">
          <el-input
            type="textarea"
            :rows="4"
            v-model="redistributionForm.reason"
            placeholder="请输入重分配原因"
          />
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="redistributionDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleRedistributionConfirm"
          >确认重分配</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import {
  getOrganAllocationDetail,
  updateOrganAllocation,
  saveAllocationRecords,
  getHospitalList,
  getOrganDict
} from "./organAllocation";
import UploadAttachment from "@/components/UploadAttachment";
import AttachmentPreview from "@/components/AttachmentPreview";
export default {
  name: "OrganAllocationDetail",
  components: {
    UploadAttachment,
    AttachmentPreview,
  },
  data() {
    return {
      // 表单数据
      form: {
        id: undefined,
        hospitalNo: "",
        caseNo: "",
        donorName: "",
        gender: "",
        age: "",
        birthDate: "",
        diagnosis: "",
        allocationStatus: "pending",
        allocationTime: "",
        registrant: "",
        registrationTime: ""
      },
      // 表单验证规则
      rules: {
        donorName: [
          { required: true, message: "捐献者姓名不能为空", trigger: "blur" }
        ],
        diagnosis: [
          { required: true, message: "疾病诊断不能为空", trigger: "blur" }
        ]
      },
      // 分配记录验证规则
      allocationRules: {},
      // 保存加载状态
      saveLoading: false,
      confirmLoading: false,
      // 加载状态
      loading: false,
      // 选中的器官
      selectedOrgans: [],
      // 器官字典
      organDict: [],
      // 医院列表
      hospitalList: [],
      // 分配记录数据
      allocationData: {
        records: []
      },
      // 附件数据
      attachments: [],
      // 重分配对话框
      redistributionDialogVisible: false,
      redistributionForm: {
        organName: "",
        reason: ""
      },
      currentRedistributeRecord: null
    };
  },
  computed: {
    // 当前用户信息
    currentUser() {
      return JSON.parse(sessionStorage.getItem("user") || "{}");
    },
    // 不完整的记录数量
    incompleteRecords() {
      return this.allocationData.records.filter(
        record =>
          !record.systemNo ||
          !record.applicantTime ||
          !record.recipientName ||
          !record.transplantHospitalNo
      ).length;
    },
    // 唯一医院数量
    uniqueHospitals() {
      const hospitals = this.allocationData.records
        .map(record => record.transplantHospitalNo)
        .filter(Boolean);
      return new Set(hospitals).size;
    }
  },
  created() {
    const id = this.$route.query.id;
    if (id) {
      this.getDetail(id);
    } else {
      this.generateCaseNo();
      this.form.registrant = this.currentUser.username || "当前用户";
      this.form.registrationTime = new Date()
        .toISOString()
        .replace("T", " ")
        .substring(0, 19);
    }
    this.getOrganDictionary();
    this.getHospitalData();
  },
  methods: {
    // 生成住院号
    generateCaseNo() {
      const timestamp = Date.now().toString();
      this.form.hospitalNo = "D" + timestamp.slice(-6);
      this.form.caseNo = "C" + timestamp.slice(-6);
    },
    // 获取详情
    getDetail(id) {
      this.loading = true;
      getOrganAllocationDetail(id)
        .then(response => {
          if (response.code === 200) {
            this.form = response.data;
            if (response.data.allocationRecords) {
              this.allocationData.records = response.data.allocationRecords;
              this.selectedOrgans = response.data.allocationRecords.map(
                item => item.organNo
              );
            }
          }
          this.loading = false;
        })
        .catch(error => {
          console.error("获取器官分配详情失败:", error);
          this.loading = false;
          this.$message.error("获取详情失败");
        });
    },
    // 获取器官字典
    getOrganDictionary() {
      getOrganDict().then(response => {
        if (response.code === 200) {
          this.organDict = response.data;
        }
      });
    },
    // 获取医院数据
    getHospitalData() {
      getHospitalList().then(response => {
        if (response.code === 200) {
          this.hospitalList = response.data;
        }
      });
    },
      handleAttachmentChange(fileList) {
console.log(fileList,'测试');
 
    },
    // 器官选择状态变化
    handleOrganSelectionChange(selectedValues) {
      const currentOrganNos = this.allocationData.records.map(
        item => item.organNo
      );
 
      // 新增选择的器官
      selectedValues.forEach(organValue => {
        if (!currentOrganNos.includes(organValue)) {
          const organInfo = this.organDict.find(
            item => item.value === organValue
          );
          if (organInfo) {
            this.allocationData.records.push({
              organName: organInfo.label,
              organNo: organValue,
              id: null,
              allocationId: this.form.id,
              systemNo: "",
              applicantTime: "",
              recipientName: "",
              transplantHospitalNo: "",
              transplantHospitalName: "",
              reallocationReason: "",
              organState: 1
            });
          }
        }
      });
 
      // 移除取消选择的器官
      this.allocationData.records = this.allocationData.records.filter(
        record => {
          if (selectedValues.includes(record.organNo)) {
            return true;
          } else {
            if (record.id) {
              this.$confirm(
                "删除器官分配数据后将无法恢复,您确认删除该条记录吗?",
                "提示",
                {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning"
                }
              )
                .then(() => {
                  // 实际项目中这里应该调用删除API
                  this.allocationData.records = this.allocationData.records.filter(
                    r => r.organNo !== record.organNo
                  );
                  this.$message.success("删除成功");
                })
                .catch(() => {
                  this.selectedOrgans.push(record.organNo);
                });
              return true; // 等待用户确认
            } else {
              return false; // 直接删除新记录
            }
          }
        }
      );
    },
    // 医院选择变化
    handleHospitalChange(row, hospitalNo) {
      const hospital = this.hospitalList.find(
        item => item.hospitalNo === hospitalNo
      );
      if (hospital) {
        row.transplantHospitalName = hospital.hospitalName;
      }
    },
    // 重分配操作
    handleRedistribution(row) {
      this.currentRedistributeRecord = row;
      this.redistributionForm.organName = row.organName;
      this.redistributionForm.reason = row.reallocationReason || "";
      this.redistributionDialogVisible = true;
    },
    // 确认重分配
    handleRedistributionConfirm() {
      if (!this.redistributionForm.reason) {
        this.$message.warning("请输入重分配原因");
        return;
      }
 
      if (this.currentRedistributeRecord) {
        this.currentRedistributeRecord.reallocationReason = this.redistributionForm.reason;
        this.$message.success("重分配原因已更新");
        this.redistributionDialogVisible = false;
      }
    },
    // 器官行样式
    getOrganRowClassName({ row }) {
      if (
        !row.systemNo ||
        !row.applicantTime ||
        !row.recipientName ||
        !row.transplantHospitalNo
      ) {
        return "warning-row";
      }
      return "";
    },
    // 保存基本信息
    handleSave() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.saveLoading = true;
          const apiMethod = this.form.id
            ? updateOrganAllocation
            : addOrganAllocation;
 
          apiMethod(this.form)
            .then(response => {
              if (response.code === 200) {
                this.$message.success("保存成功");
                if (!this.form.id) {
                  this.form.id = response.data.id;
                  this.$router.replace({
                    query: { ...this.$route.query, id: this.form.id }
                  });
                }
              }
            })
            .catch(error => {
              console.error("保存失败:", error);
              this.$message.error("保存失败");
            })
            .finally(() => {
              this.saveLoading = false;
            });
        }
      });
    },
    // 保存分配记录
    handleSaveAllocation() {
      if (!this.form.id) {
        this.$message.warning("请先保存基本信息");
        return;
      }
 
      this.saveLoading = true;
      saveAllocationRecords(this.form.id, this.allocationData.records)
        .then(response => {
          if (response.code === 200) {
            this.$message.success("分配记录保存成功");
          }
        })
        .catch(error => {
          console.error("保存分配记录失败:", error);
          this.$message.error("保存分配记录失败");
        })
        .finally(() => {
          this.saveLoading = false;
        });
    },
    // 确认完成分配
    handleConfirmAllocation() {
      if (this.incompleteRecords > 0) {
        this.$message.warning("请先完善所有分配记录的信息");
        return;
      }
 
      this.$confirm("确认完成器官分配吗?完成后将无法修改分配信息。", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.confirmLoading = true;
          this.form.allocationStatus = "allocated";
          this.form.allocationTime = new Date()
            .toISOString()
            .replace("T", " ")
            .substring(0, 19);
 
          updateOrganAllocation(this.form)
            .then(response => {
              if (response.code === 200) {
                this.$message.success("器官分配已完成");
              }
            })
            .catch(error => {
              console.error("确认分配失败:", error);
              this.$message.error("确认分配失败");
            })
            .finally(() => {
              this.confirmLoading = false;
            });
        })
        .catch(() => {});
    },
    // 上传附件
    handleUploadAttachment() {
      // 附件上传逻辑
      this.$message.info("附件上传功能");
    },
    // 预览附件
    handlePreviewAttachment(attachment) {
      // 附件预览逻辑
      this.$message.info("附件预览功能");
    },
    // 下载附件
    handleDownloadAttachment(attachment) {
      // 附件下载逻辑
      this.$message.info("附件下载功能");
    },
    // 删除附件
    handleRemoveAttachment(attachment) {
      this.$confirm("确定要删除这个附件吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$message.success("附件删除成功");
        })
        .catch(() => {});
    },
    // 获取文件图标
    getFileIcon(fileName) {
      const ext = fileName
        .split(".")
        .pop()
        .toLowerCase();
      const iconMap = {
        pdf: "el-icon-document",
        doc: "el-icon-document",
        docx: "el-icon-document",
        xls: "el-icon-document",
        xlsx: "el-icon-document",
        jpg: "el-icon-picture",
        jpeg: "el-icon-picture",
        png: "el-icon-picture"
      };
      return iconMap[ext] || "el-icon-document";
    },
    // 获取文件类型
    getFileType(fileName) {
      const ext = fileName
        .split(".")
        .pop()
        .toLowerCase();
      const typeMap = {
        pdf: "PDF",
        doc: "DOC",
        docx: "DOCX",
        xls: "XLS",
        xlsx: "XLSX",
        jpg: "JPG",
        jpeg: "JPEG",
        png: "PNG"
      };
      return typeMap[ext] || ext.toUpperCase();
    },
    // 文件大小格式化
    formatFileSize(size) {
      if (size === 0) 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];
    },
    // 时间格式化
    parseTime(time) {
      if (!time) return "";
      const date = new Date(time);
      return `${date.getFullYear()}-${(date.getMonth() + 1)
        .toString()
        .padStart(2, "0")}-${date
        .getDate()
        .toString()
        .padStart(2, "0")} ${date
        .getHours()
        .toString()
        .padStart(2, "0")}:${date
        .getMinutes()
        .toString()
        .padStart(2, "0")}`;
    }
  }
};
</script>
 
<style scoped>
.organ-allocation-detail {
  padding: 20px;
  background-color: #f5f7fa;
}
 
.detail-card {
  margin-bottom: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
 
.allocation-card {
  margin-bottom: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
 
.attachment-card {
  margin-bottom: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
 
.detail-title {
  font-size: 18px;
  font-weight: 600;
  color: #303133;
}
 
/* 统计信息样式 */
.allocation-stats {
  margin-top: 20px;
  padding: 15px;
  background: linear-gradient(135deg, #9eb7e5 0%, #53519c 100%);
  border-radius: 8px;
  color: white;
  font-size: 18px;
}
 
.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
}
 
.stat-label {
  /* font-size: 12px; */
  opacity: 0.9;
 
  /* color: #606266; */
  margin-bottom: 5px;
}
 
.stat-value {
  font-size: 20px;
  font-weight: bold;
  /* color: #303133; */
}
 
/* 空状态样式 */
.empty-allocation {
  text-align: center;
  padding: 40px 0;
  color: #909399;
}
 
/* 对话框底部按钮 */
.dialog-footer {
  margin-top: 20px;
  text-align: center;
  padding-top: 20px;
  border-top: 1px solid #e4e7ed;
}
 
/* 表格行样式 */
:deep(.warning-row) {
  background-color: #fff7e6;
}
 
:deep(.warning-row:hover) {
  background-color: #ffecc2;
}
 
/* 响应式设计 */
@media (max-width: 768px) {
  .organ-allocation-detail {
    padding: 10px;
  }
 
  .allocation-stats .el-col {
    margin-bottom: 10px;
  }
}
</style>