WXL
2026-03-13 45680b99ccdfb0d323088c57c237e0bc714a8e0b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
<template>
  <div class="maintenance-detail">
    <!-- 基础信息 -->
    <el-card class="detail-card">
      <div slot="header" class="clearfix">
        <span class="detail-title">供者基本信息</span>
        <el-button type="success" style="float: right;" @click="handleSave">
          保存信息
        </el-button>
      </div>
 
      <el-form :model="form" ref="form" label-width="120px">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="住院号" prop="caseNo">
              <el-input v-model="form.caseNo" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="捐献者姓名" prop="name">
              <el-input v-model="form.name" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="性别" prop="gender">
              <el-select v-model="form.sex" style="width: 100%">
                <el-option label="男" value="0" />
                <el-option label="女" value="1" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20">
          <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="diagnosisname">
              <el-input v-model="form.diagnosisname" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="首诊医疗机构" prop="treatmenthospitalname">
              <el-input v-model="form.treatmenthospitalname" />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="患者状态" prop="recordstate">
              <el-select v-model="form.recordstate" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.sys_DonationCategory || []"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="未完成原因"
              prop="incompleteReason"
              v-if="form.recordstate === '5'"
            >
              <el-input
                v-model="form.incompleteReason"
                placeholder="请输入未完成捐献的原因"
              />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="上报时间" prop="reporttime">
              <el-date-picker
                v-model="form.reporttime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="死亡时间" prop="deathTime">
              <el-date-picker
                v-model="form.deathTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="协调员" prop="coordinatorName">
              <el-input v-model="form.coordinatorName" />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="血型" prop="bloodtype">
              <el-select v-model="form.bloodtype" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.sys_BloodType"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="Rh(D)" prop="rhYin">
              <el-radio-group v-model="form.rhYin">
                <el-radio
                  v-for="dict in dict.type.sys_bloodtype_rhd || []"
                  :key="dict.value"
                  :label="dict.value"
                  >{{ dict.label }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-form-item label="特殊病史" prop="specialMedicalHistory">
          <el-input
            type="textarea"
            :rows="3"
            v-model="form.specialMedicalHistory"
            placeholder="记录特殊病史信息"
          />
        </el-form-item>
      </el-form>
    </el-card>
 
    <el-card class="assessment-card">
      <div slot="header" class="clearfix">
        <span class="detail-title">供者评估各项记录</span>
        <el-button
          type="primary"
          size="mini"
          @click="toggleEditMode"
          style="float: right;"
        >
          {{ isEdit ? "完成编辑" : "开始编辑" }}
        </el-button>
      </div>
 
      <el-tabs v-model="activeTab" type="card" @tab-click="handleTabClick">
        <!-- 培养结果记录 -->
        <el-tab-pane label="培养结果" name="culture">
          <el-card class="culture-card">
            <div slot="header" class="clearfix">
              <span class="detail-title">培养结果记录</span>
              <el-button
                type="primary"
                size="mini"
                icon="el-icon-plus"
                @click="handleAddCulture"
              >
                新增培养记录
              </el-button>
            </div>
 
            <el-table :data="cultureList" v-loading="cultureLoading">
              <el-table-column
                label="培养类型"
                align="center"
                prop="cultureType"
              />
              <el-table-column
                label="采样时间"
                align="center"
                prop="sampleTime"
              />
              <el-table-column label="培养结果" align="center" prop="result">
                <template slot-scope="scope">
                  <el-tag
                    :type="scope.row.result === '阴性' ? 'success' : 'danger'"
                    effect="plain"
                  >
                    {{ scope.row.result }}
                  </el-tag>
                </template>
              </el-table-column>
              <el-table-column label="附件" align="center">
                <template slot-scope="scope">
                  <el-button
                    v-if="
                      scope.row.attachments && scope.row.attachments.length > 0
                    "
                    size="mini"
                    type="text"
                    @click="handleViewCultureAttachments(scope.row)"
                  >
                    查看附件({{ scope.row.attachments.length }})
                  </el-button>
                  <span v-else>无附件</span>
                </template>
              </el-table-column>
              <el-table-column
                label="操作"
                align="center"
                width="200"
                class-name="small-padding fixed-width"
              >
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-edit"
                    @click="handleEditCulture(scope.row)"
                    >编辑</el-button
                  >
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-delete"
                    style="color: #F56C6C;"
                    @click="handleDeleteCulture(scope.row)"
                    >删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-card>
        </el-tab-pane>
 
        <!-- 肝功能肾功能 -->
        <el-tab-pane label="肝功能肾功能" name="liverKidney">
          <liver-kidney-panel
            ref="liverKidney"
            :initial-data="assessmentData.liverKidney"
            :is-editing="isEdit && activeTab === 'liverKidney'"
            @data-change="handleLiverKidneyDataChange"
          />
        </el-tab-pane>
 
        <!-- 血常规 -->
        <el-tab-pane label="血常规" name="bloodRoutine">
          <blood-routine-panel
            ref="bloodRoutine"
            :initial-data="assessmentData.bloodRoutine"
            :is-editing="isEdit && activeTab === 'bloodRoutine'"
            @data-change="handleBloodRoutineDataChange"
          />
        </el-tab-pane>
 
        <!-- 尿常规 -->
        <el-tab-pane label="尿常规" name="urineRoutine">
          <urine-routine-panel
            ref="urineRoutine"
            :initial-data="assessmentData.urineRoutine"
            :is-editing="isEdit && activeTab === 'urineRoutine'"
            @data-change="handleUrineRoutineDataChange"
          />
        </el-tab-pane>
      </el-tabs>
    </el-card>
 
    <!-- 护理核查记录 -->
    <el-card class="record-card">
      <div slot="header" class="clearfix">
        <span class="detail-title">护理核查记录</span>
        <el-button
          type="primary"
          size="mini"
          icon="el-icon-plus"
          @click="handleAddRecord"
        >
          新增核查记录
        </el-button>
      </div>
 
      <el-table :data="recordList" v-loading="recordLoading">
        <el-table-column
          label="核查时间"
          align="center"
          prop="recordTime"
          width="160"
        />
        <el-table-column
          label="核查人"
          align="center"
          prop="recorder"
          width="100"
        />
        <el-table-column
          label="核查记录"
          align="center"
          prop="checkRecord"
          min-width="200"
          show-overflow-tooltip
        />
        <el-table-column label="附件" align="center" width="120">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.attachments && scope.row.attachments.length > 0"
              size="mini"
              type="text"
              @click="handleViewRecordAttachments(scope.row)"
            >
              查看附件({{ scope.row.attachments.length }})
            </el-button>
            <span v-else>无附件</span>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          width="180"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleEditRecord(scope.row)"
              >编辑</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              style="color: #F56C6C;"
              @click="handleDeleteRecord(scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-card>
 
    <!-- 培养记录编辑对话框 -->
    <el-dialog
      :title="cultureDialogTitle"
      :visible.sync="cultureDialogVisible"
      width="700px"
      :close-on-click-modal="false"
    >
      <el-form
        :model="cultureForm"
        ref="cultureForm"
        :rules="cultureRules"
        label-width="120px"
      >
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="培养类型" prop="cultureType">
              <el-select
                v-model="cultureForm.cultureType"
                placeholder="请选择培养类型"
                style="width: 100%"
              >
                <el-option
                  v-for="item in cultureTypeOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.label"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="采样时间" prop="sampleTime">
              <el-date-picker
                v-model="cultureForm.sampleTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择采样时间"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="培养结果" prop="result">
              <el-select
                v-model="cultureForm.result"
                placeholder="请选择培养结果"
                style="width: 100%"
              >
                <el-option label="阴性" value="阴性" />
                <el-option label="阳性" value="阳性" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-form-item label="附件">
          <UploadAttachment
            ref="cultureUploadAttachment"
            :file-list="cultureFileList"
            :limit="10"
            :accept="attachmentAccept"
            :multiple="true"
            @change="handleCultureAttachmentChange"
            @upload-success="handleCultureUploadSuccess"
            @upload-error="handleCultureUploadError"
            @remove="handleCultureAttachmentRemove"
          />
        </el-form-item>
      </el-form>
 
      <span slot="footer" class="dialog-footer">
        <el-button @click="cultureDialogVisible = false">取消</el-button>
        <el-button
          type="primary"
          @click="handleSaveCulture"
          :loading="cultureSaveLoading"
          >保存</el-button
        >
      </span>
    </el-dialog>
 
    <!-- 护理核查记录编辑对话框 -->
    <el-dialog
      :title="recordDialogTitle"
      :visible.sync="recordDialogVisible"
      width="700px"
      :close-on-click-modal="false"
    >
      <el-form
        :model="recordForm"
        ref="recordForm"
        :rules="recordRules"
        label-width="120px"
      >
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="核查时间" prop="recordTime">
              <el-date-picker
                v-model="recordForm.recordTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择核查时间"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="核查人" prop="recorder">
              <el-input
                v-model="recordForm.recorder"
                placeholder="请输入核查人姓名"
              />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-form-item label="核查记录" prop="checkRecord">
          <el-input
            type="textarea"
            :rows="4"
            v-model="recordForm.checkRecord"
            placeholder="请输入核查记录内容"
          />
        </el-form-item>
 
        <el-form-item label="附件">
          <UploadAttachment
            ref="recordUploadAttachment"
            :file-list="recordFileList"
            :limit="10"
            :accept="attachmentAccept"
            :multiple="true"
            @change="handleRecordAttachmentChange"
            @upload-success="handleRecordUploadSuccess"
            @upload-error="handleRecordUploadError"
            @remove="handleRecordAttachmentRemove"
          />
        </el-form-item>
      </el-form>
 
      <span slot="footer" class="dialog-footer">
        <el-button @click="recordDialogVisible = false">取消</el-button>
        <el-button
          type="primary"
          @click="handleSaveRecord"
          :loading="recordSaveLoading"
          >保存</el-button
        >
      </span>
    </el-dialog>
 
    <!-- 附件预览对话框 -->
    <el-dialog
      :title="attachmentPreviewTitle"
      :visible.sync="attachmentPreviewVisible"
      width="900px"
      @close="handleAttachmentPreviewClose"
    >
      <el-table :data="currentAttachmentList" style="width: 100%" size="small">
        <el-table-column label="文件名" min-width="200">
          <template slot-scope="scope">
            <i
              class="el-icon-document"
              :style="{ color: getFileIconColor(scope.row.fileName) }"
            ></i>
            <span class="file-name">{{ scope.row.fileName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="文件类型" width="100">
          <template slot-scope="scope">
            <el-tag :type="getFileTagType(scope.row.fileName)" size="small">
              {{ getFileTypeText(scope.row.fileName) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="上传时间" width="160">
          <template slot-scope="scope">
            <span>{{ formatDateTime(scope.row.uploadTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="文件大小" width="100">
          <template slot-scope="scope">
            <span>{{ formatFileSize(scope.row.fileSize) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150" fixed="right">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              @click="handlePreviewAttachment(scope.row)"
              :disabled="!isPreviewable(scope.row.fileName)"
            >
              预览
            </el-button>
            <el-button
              size="mini"
              type="success"
              @click="handleDownloadAttachment(scope.row)"
            >
              下载
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
 
    <!-- 文件预览弹窗 -->
    <FilePreviewDialog
      :visible="filePreviewVisible"
      :file="currentPreviewFile"
      @close="filePreviewVisible = false"
      @download="handleDownloadAttachment"
    />
  </div>
</template>
 
<script>
import { maintainList, maintainedit, maintainAdd } from "@/api/businessApi";
import Pagination from "@/components/Pagination";
import UploadAttachment from "@/components/UploadAttachment";
import FilePreviewDialog from "@/components/FilePreviewDialog";
import LiverKidneyPanel from "./components/LiverKidneyPanel.vue";
import BloodRoutinePanel from "./components/BloodRoutinePanel.vue";
import UrineRoutinePanel from "./components/UrineRoutinePanel.vue";
import dayjs from "dayjs";
 
export default {
  name: "MaintenanceDetail",
  components: {
    Pagination,
    UploadAttachment,
    FilePreviewDialog,
    LiverKidneyPanel,
    BloodRoutinePanel,
    UrineRoutinePanel
  },
  dicts: [
    "sys_donornode",
    "sys_BloodType",
    "sys_EthicalReview",
    "sys_BaseAssessConclusion",
    "sys_bloodtype_rhd",
    "sys_DonationCategory"
  ],
 
  data() {
    return {
      isEdit: false,
      currentMaintenanceId: null,
      isEditMode: false,
      form: {
        id: undefined,
        caseNo: "",
        name: "",
        gender: "",
        age: "",
        diagnosisname: "",
        treatmenthospitalname: "",
        recordstate: "1",
        reporttime: "",
        deathTime: "",
        coordinatorName: "",
        bloodtype: "",
        rhFactor: "",
        specialMedicalHistory: "",
        incompleteReason: ""
      },
      activeTab: "culture",
      extracontentinfo: {},
 
      // 培养结果相关数据
      cultureList: [],
      cultureLoading: false,
      cultureDialogVisible: false,
      cultureDialogTitle: "",
      cultureSaveLoading: false,
      cultureForm: {
        id: undefined,
        cultureType: "",
        sampleTime: "",
        result: "阴性",
        attachments: []
      },
      cultureFileList: [],
      cultureRules: {
        cultureType: [
          { required: true, message: "请选择培养类型", trigger: "change" }
        ],
        sampleTime: [
          { required: true, message: "请选择采样时间", trigger: "change" }
        ],
        result: [
          { required: true, message: "请选择培养结果", trigger: "change" }
        ]
      },
      cultureTypeOptions: [
        { value: "1", label: "血培养" },
        { value: "2", label: "痰培养" },
        { value: "3", label: "尿培养" },
        { value: "4", label: "伤口分泌物" },
        { value: "5", label: "脑脊液培养" },
        { value: "6", label: "其他" }
      ],
 
      // 护理核查记录相关数据
      recordList: [],
      recordLoading: false,
      recordDialogVisible: false,
      recordDialogTitle: "",
      recordSaveLoading: false,
      recordForm: {
        id: undefined,
        recordTime: "",
        recorder: "",
        checkRecord: "",
        attachments: []
      },
      recordFileList: [],
      recordRules: {
        recordTime: [
          { required: true, message: "请选择核查时间", trigger: "change" }
        ],
        recorder: [
          { required: true, message: "请输入核查人", trigger: "blur" }
        ],
        checkRecord: [
          { required: true, message: "请输入核查记录", trigger: "blur" }
        ]
      },
 
      // 附件预览相关
      attachmentPreviewVisible: false,
      currentAttachmentList: [],
      attachmentPreviewTitle: "",
 
      // 文件预览相关
      filePreviewVisible: false,
      currentPreviewFile: null,
 
      // 附件相关配置
      attachmentLimit: 10,
      attachmentAccept: ".pdf,.jpg,.jpeg,.png,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt",
 
      // 评估数据存储
      assessmentData: {
        liverKidney: {},
        bloodRoutine: {},
        urineRoutine: {},
        cultureResults: [],
        nursingRecords: []
      }
    };
  },
  created() {
    this.loadMaintenanceData();
  },
  watch: {
    $route(to, from) {
      this.loadMaintenanceData();
    }
  },
  methods: {
    // 加载维护数据
    async loadMaintenanceData() {
      try {
        this.cultureLoading = true;
        this.recordLoading = true;
 
        const { id, infoid } = this.$route.query;
        const queryParams = {};
 
        if (id) {
          queryParams.infoid = infoid;
          this.currentMaintenanceId = id;
          this.isEditMode = true;
        } else if (infoid) {
          queryParams.infoid = infoid;
          this.currentMaintenanceId = null;
          this.isEditMode = false;
        } else {
          this.$message.error("缺少必要的路由参数");
          return;
        }
 
        queryParams.infoid = infoid;
        const response = await maintainList(queryParams);
        if (response.code === 200) {
          let maintenanceData = response.data[0];
 
          if (Array.isArray(maintenanceData)) {
            maintenanceData = maintenanceData[0] || {};
          }
          if (maintenanceData.extracontent) {
            this.extracontentinfo = JSON.parse(maintenanceData.extracontent);
            if (this.extracontentinfo.specialMedicalHistory) {
              this.form.specialMedicalHistory = this.extracontentinfo.specialMedicalHistory;
            }
          }
 
          if (maintenanceData.itemDesc) {
            try {
              const itemDescData = maintenanceData.itemDesc;
              this.assessmentData = { ...this.assessmentData, ...itemDescData };
 
              if (itemDescData.cultureResults) {
                this.cultureList = itemDescData.cultureResults;
              }
              if (itemDescData.nursingRecords) {
                this.recordList = itemDescData.nursingRecords;
              }
              if (itemDescData.liverKidney) {
                this.assessmentData.liverKidney = itemDescData.liverKidney;
              }
              if (itemDescData.bloodRoutine) {
                this.assessmentData.bloodRoutine = itemDescData.bloodRoutine;
              }
              if (itemDescData.urineRoutine) {
                this.assessmentData.urineRoutine = itemDescData.urineRoutine;
              }
            } catch (error) {
              console.error("解析itemDesc JSON失败:", error);
            }
          }
 
          this.form = { ...this.form, ...maintenanceData };
          this.$message.success("数据加载成功");
        } else {
          this.$message.error("数据加载失败:" + (response.msg || "未知错误"));
        }
      } catch (error) {
        console.error("加载维护数据失败:", error);
        this.$message.error("数据加载失败");
      } finally {
        this.cultureLoading = false;
        this.recordLoading = false;
      }
    },
 
    // 保存所有数据
    async handleSave() {
      try {
        const saveData = {
          ...this.form,
          itemDesc: {
            liverKidney: this.assessmentData.liverKidney,
            bloodRoutine: this.assessmentData.bloodRoutine,
            urineRoutine: this.assessmentData.urineRoutine,
            cultureResults: this.cultureList,
            nursingRecords: this.recordList
          }
        };
        this.extracontentinfo.specialMedicalHistory = this.form.specialMedicalHistory;
        let response;
        if (this.isEditMode && this.currentMaintenanceId) {
          saveData.id = this.currentMaintenanceId;
          response = await maintainedit(saveData);
        } else {
          response = await maintainAdd(saveData);
        }
 
        if (response.code === 200) {
          this.$message.success("保存成功");
          this.isEdit = false;
          this.donatebaseinfoEdit({
            id: this.$route.query.infoid,
            extracontent: JSON.stringify(this.extracontentinfo)
          });
          if (!this.isEditMode && response.data && response.data.id) {
            this.currentMaintenanceId = response.data.id;
            this.isEditMode = true;
          }
        } else {
          this.$message.error("保存失败:" + (response.msg || "未知错误"));
        }
      } catch (error) {
        console.error("保存数据失败:", error);
        this.$message.error("保存失败");
      }
    },
 
    // 切换编辑模式
    toggleEditMode() {
      this.isEdit = !this.isEdit;
      if (!this.isEdit) {
        this.handleSave();
      }
    },
 
    // 培养记录相关方法
    handleAddCulture() {
      this.cultureDialogTitle = "新增培养记录";
      this.cultureForm = {
        id: undefined,
        cultureType: "",
        sampleTime: "",
        result: "阴性",
        attachments: []
      };
      this.cultureFileList = [];
      this.cultureDialogVisible = true;
      this.$nextTick(() => {
        this.$refs.cultureForm && this.$refs.cultureForm.clearValidate();
      });
    },
 
    handleEditCulture(row) {
      this.cultureDialogTitle = "编辑培养记录";
      this.cultureForm = { ...row };
      this.cultureFileList = row.attachments ? row.attachments.map(item => ({
        uid: item.id || Math.random(),
        name: item.fileName,
        fileSize: item.fileSize,
        url: item.path || item.fileUrl,
        uploadTime: item.uploadTime,
        status: "success"
      })) : [];
      this.cultureDialogVisible = true;
      this.$nextTick(() => {
        this.$refs.cultureForm && this.$refs.cultureForm.clearValidate();
      });
    },
 
    handleSaveCulture() {
      this.$refs.cultureForm.validate(valid => {
        if (valid) {
          this.cultureSaveLoading = true;
 
          if (this.cultureForm.id) {
            const index = this.cultureList.findIndex(
              item => item.id === this.cultureForm.id
            );
            if (index !== -1) {
              this.cultureList.splice(index, 1, { ...this.cultureForm });
            }
          } else {
            this.cultureForm.id = Date.now();
            this.cultureList.push({ ...this.cultureForm });
          }
 
          this.$message.success(this.cultureForm.id ? "修改成功" : "新增成功");
          this.cultureDialogVisible = false;
          this.cultureSaveLoading = false;
        }
      });
    },
 
    handleDeleteCulture(row) {
      this.$confirm("确定要删除这条培养记录吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.cultureList = this.cultureList.filter(
            item => item.id !== row.id
          );
          this.$message.success("删除成功");
        })
        .catch(() => {});
    },
 
    // 护理记录相关方法
    handleAddRecord() {
      this.recordDialogTitle = "新增护理核查记录";
      this.recordForm = {
        id: undefined,
        recordTime: new Date()
          .toISOString()
          .replace("T", " ")
          .substring(0, 19),
        recorder: "当前用户",
        checkRecord: "",
        attachments: []
      };
      this.recordFileList = [];
      this.recordDialogVisible = true;
      this.$nextTick(() => {
        this.$refs.recordForm && this.$refs.recordForm.clearValidate();
      });
    },
 
    handleEditRecord(row) {
      this.recordDialogTitle = "编辑护理核查记录";
      this.recordForm = { ...row };
      this.recordFileList = row.attachments ? row.attachments.map(item => ({
        uid: item.id || Math.random(),
        name: item.fileName,
        fileSize: item.fileSize,
        url: item.path || item.fileUrl,
        uploadTime: item.uploadTime,
        status: "success"
      })) : [];
      this.recordDialogVisible = true;
      this.$nextTick(() => {
        this.$refs.recordForm && this.$refs.recordForm.clearValidate();
      });
    },
 
    handleSaveRecord() {
      this.$refs.recordForm.validate(valid => {
        if (valid) {
          this.recordSaveLoading = true;
 
          if (this.recordForm.id) {
            const index = this.recordList.findIndex(
              item => item.id === this.recordForm.id
            );
            if (index !== -1) {
              this.recordList.splice(index, 1, { ...this.recordForm });
            }
          } else {
            this.recordForm.id = Date.now();
            this.recordList.push({ ...this.recordForm });
          }
 
          this.$message.success(this.recordForm.id ? "修改成功" : "新增成功");
          this.recordDialogVisible = false;
          this.recordSaveLoading = false;
        }
      });
    },
 
    handleDeleteRecord(row) {
      this.$confirm("确定要删除这条护理核查记录吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.recordList = this.recordList.filter(item => item.id !== row.id);
          this.$message.success("删除成功");
        })
        .catch(() => {});
    },
 
    // 培养记录附件相关方法
    handleCultureAttachmentChange(fileList) {
      this.cultureFileList = fileList;
    },
 
    handleCultureUploadSuccess({ file, fileList, response }) {
      if (response.code === 200) {
        const attachmentObj = {
          fileName: file.name,
          path: response.fileUrl || file.url,
          fileUrl: response.fileUrl || file.url,
          fileType: this.getFileExtension(file.name),
          fileSize: file.size,
          uploadTime: dayjs().format("YYYY-MM-DD HH:mm:ss")
        };
 
        if (!Array.isArray(this.cultureForm.attachments)) {
          this.cultureForm.attachments = [];
        }
 
        this.cultureForm.attachments.push(attachmentObj);
        this.cultureFileList = fileList;
        this.$message.success("文件上传成功");
      }
    },
 
    handleCultureUploadError({ file, fileList, error }) {
      console.error("培养记录附件上传失败:", error);
      this.$message.error("文件上传失败,请重试");
    },
 
    handleCultureAttachmentRemove(file) {
      if (file.url) {
        const index = this.cultureForm.attachments.findIndex(
          item => item.path === file.url || item.fileUrl === file.url
        );
        if (index > -1) {
          this.cultureForm.attachments.splice(index, 1);
          this.$message.success("附件删除成功");
        }
      }
    },
 
    // 护理记录附件相关方法
    handleRecordAttachmentChange(fileList) {
      this.recordFileList = fileList;
    },
 
    handleRecordUploadSuccess({ file, fileList, response }) {
      if (response.code === 200) {
        const attachmentObj = {
          fileName: file.name,
          path: response.fileUrl || file.url,
          fileUrl: response.fileUrl || file.url,
          fileType: this.getFileExtension(file.name),
          fileSize: file.size,
          uploadTime: dayjs().format("YYYY-MM-DD HH:mm:ss")
        };
 
        if (!Array.isArray(this.recordForm.attachments)) {
          this.recordForm.attachments = [];
        }
 
        this.recordForm.attachments.push(attachmentObj);
        this.recordFileList = fileList;
        this.$message.success("文件上传成功");
      }
    },
 
    handleRecordUploadError({ file, fileList, error }) {
      console.error("护理记录附件上传失败:", error);
      this.$message.error("文件上传失败,请重试");
    },
 
    handleRecordAttachmentRemove(file) {
      if (file.url) {
        const index = this.recordForm.attachments.findIndex(
          item => item.path === file.url || item.fileUrl === file.url
        );
        if (index > -1) {
          this.recordForm.attachments.splice(index, 1);
          this.$message.success("附件删除成功");
        }
      }
    },
 
    handleViewCultureAttachments(row) {
      this.currentAttachmentList = row.attachments || [];
      this.attachmentPreviewTitle = `培养记录附件 - ${row.cultureType}`;
      this.attachmentPreviewVisible = true;
    },
 
    handleViewRecordAttachments(row) {
      this.currentAttachmentList = row.attachments || [];
      this.attachmentPreviewTitle = `护理核查记录附件 - ${row.recorder}`;
      this.attachmentPreviewVisible = true;
    },
 
    handleAttachmentPreviewClose() {
      this.currentAttachmentList = [];
      this.attachmentPreviewTitle = "";
    },
 
    handlePreviewAttachment(file) {
      this.currentPreviewFile = {
        fileName: file.fileName,
        fileUrl: file.path || file.fileUrl,
        fileType: this.getFileType(file.fileName)
      };
      this.filePreviewVisible = true;
    },
 
    handleDownloadAttachment(file) {
      const fileUrl = file.path || 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 = fileName.split(".").pop().toLowerCase();
      const imageTypes = ["jpg", "jpeg", "png", "gif", "bmp", "webp"];
      const pdfTypes = ["pdf"];
      const officeTypes = ["doc", "docx", "xls", "xlsx", "ppt", "pptx"];
      if (imageTypes.includes(extension)) return "image";
      if (pdfTypes.includes(extension)) return "pdf";
      if (officeTypes.includes(extension)) return "office";
      return "other";
    },
 
    /** 获取文件图标颜色 */
    getFileIconColor(fileName) {
      const type = this.getFileType(fileName);
      const colorMap = {
        image: "#67C23A",
        pdf: "#F56C6C",
        office: "#409EFF",
        other: "#909399"
      };
      return colorMap[type] || "#909399";
    },
 
    /** 获取文件标签类型 */
    getFileTagType(fileName) {
      const type = this.getFileType(fileName);
      const typeMap = {
        image: "success",
        pdf: "danger",
        office: "primary",
        other: "info"
      };
      return typeMap[type] || "info";
    },
 
    /** 获取文件类型文本 */
    getFileTypeText(fileName) {
      const type = this.getFileType(fileName);
      const textMap = {
        image: "图片",
        pdf: "PDF",
        office: "文档",
        other: "其他"
      };
      return textMap[type] || "未知";
    },
 
    /** 检查是否可预览 */
    isPreviewable(fileName) {
      const type = this.getFileType(fileName);
      return ["image", "pdf"].includes(type);
    },
 
    /** 获取文件扩展名 */
    getFileExtension(filename) {
      return filename.split(".").pop().toLowerCase();
    },
 
    /** 格式化文件大小 */
    formatFileSize(bytes) {
      if (!bytes || bytes === 0) return "0 B";
      const k = 1024;
      const sizes = ["B", "KB", "MB", "GB"];
      const i = Math.floor(Math.log(bytes) / Math.log(k));
      return parseFloat((bytes / 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;
      }
    },
 
    // 评估数据变更处理
    handleLiverKidneyDataChange(data) {
      this.assessmentData.liverKidney = data;
    },
 
    handleBloodRoutineDataChange(data) {
      this.assessmentData.bloodRoutine = data;
    },
 
    handleUrineRoutineDataChange(data) {
      this.assessmentData.urineRoutine = data;
    },
 
    handleTabClick(tab) {
      this.$nextTick(() => {
        let tableRef = null;
        if (tab.name === "liverKidney") {
          tableRef = this.$refs.liverKidney;
        } else if (tab.name === "bloodRoutine") {
          tableRef = this.$refs.bloodRoutine;
        } else if (tab.name === "urineRoutine") {
          tableRef = this.$refs.urineRoutine;
        }
 
        if (tableRef && tableRef.doLayout) {
          tableRef.doLayout();
        }
      });
    }
  }
};
</script>
 
<style scoped>
.maintenance-detail {
  padding: 20px;
}
 
.detail-card {
  margin-bottom: 20px;
}
 
.assessment-card {
  margin-bottom: 20px;
}
 
.record-card {
  margin-bottom: 20px;
}
 
.detail-title {
  font-size: 16px;
  font-weight: bold;
  margin-right: 20px;
}
 
.culture-card {
  margin-bottom: 20px;
}
 
.fixed-width .el-button {
  margin: 0 2px;
}
 
.file-name {
  font-size: 13px;
  margin-left: 8px;
}
</style>