WXL
2026-05-08 6623e51d0b1edb191ca50201c0130cb5ed1beda8
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
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
<template>
  <div class="followup-list">
    <!-- 查询条件 -->
    <el-card class="search-card">
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        label-width="100px"
      >
        <el-form-item label="器官受体者姓名" prop="recipientname">
          <el-input
            v-model="queryParams.recipientname"
            placeholder="请输入器官受体者姓名"
            clearable
            style="width: 200px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="移植医院" prop="hospitalname">
          <el-input
            v-model="queryParams.hospitalname"
            placeholder="请输入移植医院名称"
            clearable
            style="width: 200px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="随访者" prop="followupno">
          <el-input
            v-model="queryParams.followupno"
            placeholder="请输入随访者"
            clearable
            style="width: 180px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="捐献结果" prop="donateresult">
          <el-select
            v-model="queryParams.donateresult"
            placeholder="请选择捐献结果"
            clearable
            style="width: 180px"
          >
            <el-option label="成功" value="1" />
            <el-option label="失败" value="0" />
            <el-option label="进行中" value="2" />
          </el-select>
        </el-form-item>
        <el-form-item label="随访时间" prop="followupTimeRange">
          <el-date-picker
            v-model="queryParams.followupTimeRange"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            style="width: 240px"
          />
        </el-form-item>
        <el-form-item label="创建时间" prop="createTimeRange">
          <el-date-picker
            v-model="queryParams.createTimeRange"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            style="width: 240px"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
 
    <!-- 操作按钮 -->
    <el-card class="tool-card">
      <el-row :gutter="10">
        <el-col :span="16">
          <el-button
            type="primary"
            icon="el-icon-plus"
            @click="handleCreate"
            v-hasPermi="['system:followup:add']"
            >新增随访</el-button
          >
          <el-button
            type="success"
            icon="el-icon-edit"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['system:followup:edit']"
            >修改</el-button
          >
          <el-button
            type="danger"
            icon="el-icon-delete"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['system:followup:remove']"
            >删除</el-button
          >
          <el-button
            type="warning"
            icon="el-icon-download"
            @click="handleExport"
            v-hasPermi="['system:followup:export']"
            >导出</el-button
          >
        </el-col>
        <el-col :span="8" style="text-align: right">
          <el-tooltip content="刷新" placement="top">
            <el-button icon="el-icon-refresh" circle @click="getList" />
          </el-tooltip>
        </el-col>
      </el-row>
    </el-card>
 
    <!-- 数据表格 -->
    <el-card>
      <el-table
        v-loading="loading"
        :data="followupList"
        @selection-change="handleSelectionChange"
        border
        :default-sort="{ prop: 'followuptime', order: 'descending' }"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column
          label="随访序号"
          align="center"
          prop="seqno"
          width="100"
        >
          <template slot-scope="scope">
            <span>第{{ scope.row.seqno || 1 }}次</span>
          </template>
        </el-table-column>
        <el-table-column
          label="随访时间"
          align="center"
          prop="followuptime"
          width="120"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.followuptime, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="器官受体者姓名"
          align="center"
          prop="recipientname"
          width="120"
        />
        <el-table-column
          label="移植医院"
          align="center"
          prop="hospitalname"
          width="150"
          show-overflow-tooltip
        />
        <el-table-column
          label="移植科室"
          align="center"
          prop="hospitaldept"
          width="120"
        />
        <el-table-column
          label="随访医生"
          align="center"
          prop="doctorname"
          width="120"
        />
        <el-table-column
          label="医生电话"
          align="center"
          prop="doctorphone"
          width="120"
        />
        <el-table-column
          label="捐献结果"
          align="center"
          prop="donateresult"
          width="100"
        >
          <template slot-scope="scope">
            <el-tag :type="resultTypeFilter(scope.row.donateresult)">
              {{ resultTextFilter(scope.row.donateresult) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="随访者"
          align="center"
          prop="followupno"
          width="100"
        />
        <el-table-column
          label="随访描述"
          align="center"
          prop="followupdescribe"
          min-width="200"
          show-overflow-tooltip
        />
        <el-table-column
          label="创建时间"
          align="center"
          prop="createTime"
          width="120"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          width="150"
          fixed="right"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleView(scope.row)"
              v-hasPermi="['system:followup:query']"
              >详情</el-button
            >
            <!-- <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['system:followup:edit']"
              >修改</el-button
            > -->
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['system:followup:remove']"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
 
      <!-- 分页组件 -->
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
 
    <!-- 选择案例对话框 - 参照捐献案例列表页的完整功能 -->
    <el-dialog
      title="选择捐献案例"
      :visible.sync="selectCaseOpen"
      width="1200px"
      append-to-body
      :close-on-click-modal="false"
    >
      <!-- 搜索表单 -->
      <el-form
        :model="caseQueryParams"
        ref="caseQueryForm"
        :inline="true"
        label-width="88px"
      >
        <el-form-item label="捐献者姓名" prop="name">
          <el-input
            v-model="caseQueryParams.name"
            placeholder="请输入姓名"
            clearable
            size="small"
            @keyup.enter.native="searchCaseList"
          />
        </el-form-item>
 
        <el-form-item label="治疗医院" prop="treatmenthospitalname">
          <el-input
            v-model="caseQueryParams.treatmenthospitalname"
            placeholder="请输入治疗医院"
            clearable
            size="small"
            style="width: 150px"
          />
        </el-form-item>
 
        <el-form-item label="上报时间">
          <el-date-picker
            style="width: 100%"
            v-model="caseSelectTime"
            type="monthrange"
            range-separator="至"
            start-placeholder="开始月份"
            end-placeholder="结束月份"
            value-format="yyyy-MM-dd"
            @change="handleCaseTimeSelect"
            size="small"
          />
        </el-form-item>
 
        <el-row>
          <el-col :span="4">
            <el-form-item>
              <el-button
                type="primary"
                icon="el-icon-search"
                size="mini"
                @click="searchCaseList"
              >
                搜索
              </el-button>
              <el-button
                icon="el-icon-refresh"
                size="mini"
                @click="resetCaseSearch"
              >
                重置
              </el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
 
      <!-- 案例表格 -->
      <el-table
        v-loading="caseLoading"
        :data="availableCaseList"
        @row-click="handleCaseRowClick"
        highlight-current-row
        style="width: 100%; margin-top: 20px;"
      >
        <el-table-column
          label="案例时间"
          align="center"
          prop="donatetime"
          width="100"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.donatetime, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="案例编号"
          align="center"
          prop="caseNo"
          width="200"
        />
        <el-table-column
          label="捐献者姓名"
          align="center"
          prop="name"
          width="100"
        />
        <el-table-column label="性别" align="center" prop="sex" width="100">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.sys_user_sex"
              :value="parseInt(scope.row.sex)"
            />
          </template>
        </el-table-column>
        <el-table-column label="年龄" align="center" prop="age" width="100">
          <template slot-scope="scope">
            {{
              `${
                scope.row.age && scope.row.age !== 0
                  ? `${scope.row.age}${scope.row.ageunit || ""}`
                  : ""
              } ${
                scope.row.age2 && scope.row.age2 !== 0
                  ? `${scope.row.age2}${scope.row.ageunit2}`
                  : ""
              }`.trim()
            }}
          </template>
        </el-table-column>
        <el-table-column
          label="治疗医院"
          align="center"
          prop="treatmenthospitalname"
          show-overflow-tooltip
        />
        <el-table-column
          label="GCS评分"
          align="center"
          prop="gcsScore"
          width="100"
        />
        <el-table-column
          label="血型"
          align="center"
          prop="bloodtype"
          width="100"
        >
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.sys_BloodType"
              :value="scope.row.bloodtype"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="捐献类别"
          align="center"
          prop="donationcategory"
        >
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.sys_DonationCategory"
              :value="scope.row.donationcategory"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="报告人"
          align="center"
          prop="reportername"
        />
        <el-table-column
          label="捐献进度"
          align="center"
          prop="workflow"
        >
          <template slot-scope="scope">
            <div v-if="!scope.row.terminationCase">
              <dict-tag
                :options="dict.type.sys_donornode"
                :value="scope.row.workflow"
              />
            </div>
            <div v-else>
              <el-button type="danger" plain>任务终止</el-button>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="是否已有随访" width="100" align="center">
          <template slot-scope="scope">
            <el-tag
              :type="hasFollowup(scope.row) ? 'danger' : 'success'"
              size="small"
            >
              {{ hasFollowup(scope.row) ? "已有随访" : "可选择" }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作"  align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="mini"
              @click.stop="selectCase(scope.row)"
              :disabled="hasFollowup(scope.row) || scope.row.terminationCase"
            >
              选择
            </el-button>
          </template>
        </el-table-column>
      </el-table>
 
      <!-- 分页 -->
      <pagination
        v-show="caseTotal > 0"
        :total="caseTotal"
        :page.sync="caseQueryParams.pageNum"
        :limit.sync="caseQueryParams.pageSize"
        @pagination="searchCaseList"
        style="padding: 10px 0; background: #fff; border-top: 1px solid #ebeef5;"
      />
 
      <div slot="footer" class="dialog-footer">
        <el-button @click="selectCaseOpen = false">取消</el-button>
        <el-button
          type="primary"
          @click="confirmCaseSelection"
          v-if="selectedCaseRow"
        >
          确认选择
        </el-button>
      </div>
    </el-dialog>
 
    <!-- 新增/修改对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="800px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="关联案例" prop="infoid">
          <el-input
            v-model="form.infoid"
            placeholder="请选择案例"
            :disabled="true"
            style="width: 300px"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="openCaseDialog"
              v-if="!form.id"
              >选择案例</el-button
            >
          </el-input>
          <div v-if="selectedCase" style="margin-top: 8px; color: #666;">
            <span>案例编号: {{ selectedCase.caseNo }}</span>
            <span style="margin-left: 20px;"
              >捐献者: {{ selectedCase.name }}</span
            >
            <span style="margin-left: 20px; display: block; margin-top: 5px;">
              治疗医院: {{ selectedCase.treatmenthospitalname }}
            </span>
            <span style="margin-left: 20px; display: block; margin-top: 5px;">
              诊断: {{ selectedCase.diagnosisname }}
            </span>
            <span style="margin-left: 20px; display: block; margin-top: 5px;">
              血型:
              <dict-tag
                :options="dict.type.sys_BloodType"
                :value="selectedCase.bloodtype"
              />
            </span>
          </div>
        </el-form-item>
 
        <el-row>
          <el-col :span="12">
            <el-form-item label="器官受体者姓名" prop="recipientname">
              <el-input
                v-model="form.recipientname"
                placeholder="请输入器官受体者姓名"
                maxlength="50"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="受体电话" prop="recipientphone">
              <el-input
                v-model="form.recipientphone"
                placeholder="请输入器官受体者电话"
                maxlength="20"
              />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row>
          <el-col :span="12">
            <el-form-item label="移植医院名称" prop="hospitalname">
              <el-input
                v-model="form.hospitalname"
                placeholder="请输入移植医院名称"
                maxlength="100"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="移植科室" prop="hospitaldept">
              <el-input
                v-model="form.hospitaldept"
                placeholder="请输入移植医院科室"
                maxlength="50"
              />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row>
          <el-col :span="12">
            <el-form-item label="随访医生姓名" prop="doctorname">
              <el-input
                v-model="form.doctorname"
                placeholder="请输入接受随访医生姓名"
                maxlength="50"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="医生电话" prop="doctorphone">
              <el-input
                v-model="form.doctorphone"
                placeholder="请输入接受随访医生电话"
                maxlength="20"
              />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row>
          <el-col :span="12">
            <el-form-item label="捐献结果" prop="donateresult">
              <el-select
                v-model="form.donateresult"
                placeholder="请选择捐献结果"
                style="width: 100%"
              >
                <el-option label="成功" value="1" />
                <el-option label="失败" value="0" />
                <el-option label="进行中" value="2" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="随访时间" prop="followuptime">
              <el-date-picker
                v-model="form.followuptime"
                type="datetime"
                placeholder="选择随访时间"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-form-item label="随访序号" prop="seqno">
          <el-input-number
            v-model="form.seqno"
            :min="1"
            :max="20"
            placeholder="请输入随访序号"
            style="width: 200px"
          />
          <span style="margin-left: 10px; color: #999;"
            >(第{{ form.seqno || 1 }}次随访)</span
          >
        </el-form-item>
 
        <el-form-item label="随访者" prop="followupno">
          <el-input
            v-model="form.followupno"
            placeholder="请输入随访者"
            maxlength="50"
            style="width: 300px"
          />
        </el-form-item>
 
        <el-form-item label="医生描述" prop="doctordescribe">
          <el-input
            v-model="form.doctordescribe"
            type="textarea"
            placeholder="请输入医生描述"
            maxlength="500"
            :rows="3"
            show-word-limit
          />
        </el-form-item>
 
        <el-form-item label="随访描述" prop="followupdescribe">
          <el-input
            v-model="form.followupdescribe"
            type="textarea"
            placeholder="请输入随访描述"
            maxlength="1000"
            :rows="4"
            show-word-limit
          />
        </el-form-item>
 
        <el-form-item label="受体者描述" prop="recipientdescribe">
          <el-input
            v-model="form.recipientdescribe"
            type="textarea"
            placeholder="请输入器官受体者描述"
            maxlength="500"
            :rows="3"
            show-word-limit
          />
        </el-form-item>
 
        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="form.remark"
            type="textarea"
            placeholder="请输入备注"
            maxlength="500"
            :rows="3"
            show-word-limit
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import {
  listFollowup,
  getFollowup,
  addFollowup,
  updateFollowup,
  delFollowup,
  exportFollowup
} from "@/api/businessApi/followup";
import { listDonatebaseinfo } from "@/api/project/donatebaseinfo";
import Pagination from "@/components/Pagination";
 
export default {
  name: "Followup",
  components: { Pagination },
  dicts: [
    "sys_user_sex",
    "sys_BloodType",
    "sys_DonationCategory",
    "sys_donornode"
  ],
  data() {
    return {
      // 遮罩层
      loading: true,
      caseLoading: false,
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      caseTotal: 0,
      // 随访表格数据
      followupList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示选择案例弹出层
      selectCaseOpen: false,
      // 时间选择
      caseSelectTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        recipientname: undefined,
        hospitalname: undefined,
        followupno: undefined,
        donateresult: undefined,
        followupTimeRange: [],
        createTimeRange: []
      },
      // 案例查询参数
      caseQueryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        treatmenthospitalname: undefined,
        starttime: undefined,
        endtime: undefined
      },
      // 可选择的案例列表
      availableCaseList: [],
      // 当前选中的案例
      selectedCase: null,
      selectedCaseRow: null,
      // 已有随访的案例ID缓存
      existingFollowupCases: new Set(),
      // 表单参数
      form: {
        id: undefined,
        infoid: undefined,
        organid: undefined,
        recipientname: "",
        recipientphone: "",
        recipientdescribe: "",
        hospitalname: "",
        hospitaldept: "",
        hospitalno: "",
        doctorname: "",
        doctorphone: "",
        doctordescribe: "",
        donateresult: "",
        followuptime: undefined,
        followupno: "",
        followupdescribe: "",
        seqno: 1,
        remark: ""
      },
      // 表单校验
      rules: {
        infoid: [
          { required: true, message: "请选择关联案例", trigger: "blur" }
        ],
        recipientname: [
          {
            required: true,
            message: "器官受体者姓名不能为空",
            trigger: "blur"
          },
          { max: 50, message: "长度不能超过50个字符", trigger: "blur" }
        ],
        hospitalname: [
          { required: true, message: "移植医院名称不能为空", trigger: "blur" },
          { max: 100, message: "长度不能超过100个字符", trigger: "blur" }
        ],
        followuptime: [
          { required: true, message: "随访时间不能为空", trigger: "change" }
        ],
        followupno: [
          { required: true, message: "随访者不能为空", trigger: "blur" },
          { max: 50, message: "长度不能超过50个字符", trigger: "blur" }
        ],
        donateresult: [
          { required: true, message: "捐献结果不能为空", trigger: "change" }
        ],
        seqno: [
          { required: true, message: "随访序号不能为空", trigger: "blur" },
          {
            type: "number",
            min: 1,
            max: 20,
            message: "随访序号范围为1-20",
            trigger: "blur"
          }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 结果类型过滤器
    resultTypeFilter(result) {
      const resultMap = {
        "1": "success", // 成功
        "0": "danger", // 失败
        "2": "primary" // 进行中
      };
      return resultMap[result] || "info";
    },
    resultTextFilter(result) {
      const resultMap = {
        "1": "成功",
        "0": "失败",
        "2": "进行中"
      };
      return resultMap[result] || "未知";
    },
    // 查询随访列表
    async getList() {
      this.loading = true;
      try {
        const requestParams = this.buildRequestParams();
        const response = await listFollowup(requestParams);
 
        if (response.code === 200) {
          this.handleResponseData(response);
          // 加载随访数据后,提取已有的案例ID
          this.extractExistingCaseIds();
        } else {
          this.$message.error("获取数据失败:" + (response.msg || "未知错误"));
          this.followupList = [];
          this.total = 0;
        }
      } catch (error) {
        console.error("获取随访列表失败:", error);
        this.$message.error("获取数据失败");
        this.followupList = [];
        this.total = 0;
      } finally {
        this.loading = false;
      }
    },
    // 构建请求参数
    buildRequestParams() {
      const params = {
        pageNum: this.queryParams.pageNum,
        pageSize: this.queryParams.pageSize
      };
 
      if (this.queryParams.recipientname) {
        params.recipientname = this.queryParams.recipientname;
      }
      if (this.queryParams.hospitalname) {
        params.hospitalname = this.queryParams.hospitalname;
      }
      if (this.queryParams.followupno) {
        params.followupno = this.queryParams.followupno;
      }
      if (
        this.queryParams.donateresult !== undefined &&
        this.queryParams.donateresult !== ""
      ) {
        params.donateresult = this.queryParams.donateresult;
      }
 
      if (
        this.queryParams.followupTimeRange &&
        this.queryParams.followupTimeRange.length === 2
      ) {
        params.startFollowupTime = this.queryParams.followupTimeRange[0];
        params.endFollowupTime = this.queryParams.followupTimeRange[1];
      }
 
      if (
        this.queryParams.createTimeRange &&
        this.queryParams.createTimeRange.length === 2
      ) {
        params.startCreateTime = this.queryParams.createTimeRange[0];
        params.endCreateTime = this.queryParams.createTimeRange[1];
      }
 
      return params;
    },
    // 处理接口响应数据
    handleResponseData(response) {
      if (response.data) {
        if (Array.isArray(response.data)) {
          this.followupList = response.data;
          this.total = response.data.length;
        } else if (response.data.rows) {
          this.followupList = response.data.rows;
          this.total = response.data.total;
        } else if (Array.isArray(response.data.list)) {
          this.followupList = response.data.list;
          this.total = response.data.total || response.data.list.length;
        } else {
          this.followupList = response.data;
          this.total = response.total || response.data.length;
        }
      } else {
        if (Array.isArray(response.rows)) {
          this.followupList = response.rows;
          this.total = response.total;
        } else if (Array.isArray(response.list)) {
          this.followupList = response.list;
          this.total = response.total;
        } else {
          this.followupList = [];
          this.total = 0;
        }
      }
 
      if (!Array.isArray(this.followupList)) {
        this.followupList = [];
      }
    },
    // 提取已有随访的案例ID
    extractExistingCaseIds() {
      this.existingFollowupCases.clear();
      this.followupList.forEach(followup => {
        if (followup.infoid) {
          this.existingFollowupCases.add(followup.infoid);
        }
      });
    },
    // 搜索按钮操作
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置按钮操作
    resetQuery() {
      this.$refs.queryForm.resetFields();
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    // 查看详情
    async handleView(row) {
      this.$router.push({
        path: "/follow/followupVisitinfo",
        query: { id: row.id, infoid: row.infoid }
      });
    },
    // 新增按钮操作
    handleCreate() {
      this.reset();
      this.open = true;
      this.title = "新增受者随访";
    },
    // 修改按钮操作
    async handleUpdate(row) {
      const id = row.id || this.ids[0];
      if (!id) {
        this.$message.warning("请先选择要操作的数据");
        return;
      }
 
      try {
        this.loading = true;
        const response = await getFollowup(id);
        if (response.code === 200) {
          this.form = response.data;
          this.open = true;
          this.title = "修改受者随访";
 
          // 如果是修改,尝试加载案例信息
          if (this.form.infoid) {
            this.loadSelectedCaseInfo(this.form.infoid);
          }
        } else {
          this.$message.error("获取数据失败:" + response.msg);
        }
      } catch (error) {
        console.error("获取随访详情失败:", error);
        this.$message.error("获取数据失败");
      } finally {
        this.loading = false;
      }
    },
    // 加载选中的案例信息
    async loadSelectedCaseInfo(infoid) {
      try {
        const response = await listDonatebaseinfo({
          pageNum: 1,
          pageSize: 1,
          id: infoid
        });
 
        if (
          response.code === 200 &&
          response.data &&
          response.data.length > 0
        ) {
          this.selectedCase = response.data[0];
        }
      } catch (error) {
        console.error("加载案例信息失败:", error);
      }
    },
    // 删除按钮操作
    async handleDelete(row) {
      const ids = row.id ? [row.id] : this.ids;
      if (ids.length === 0) {
        this.$message.warning("请先选择要删除的数据");
        return;
      }
 
      try {
        await this.$confirm("是否确认删除选中的数据项?", "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        });
 
        const response = await delFollowup(ids);
        if (response.code === 200) {
          this.$message.success("删除成功");
          this.getList();
        } else {
          this.$message.error("删除失败:" + response.msg);
        }
      } catch (error) {
        if (error !== "cancel") {
          console.error("删除失败:", error);
        }
      }
    },
    // 导出按钮操作
    async handleExport() {
      try {
        await this.$confirm("是否确认导出所有随访数据?", "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        });
 
        this.exportLoading = true;
        const exportParams = this.buildRequestParams();
 
        const response = await exportFollowup(exportParams);
        if (response.code === 200) {
          this.download(response.msg || "随访数据.xlsx");
        } else {
          this.$message.error("导出失败:" + response.msg);
        }
      } catch (error) {
        if (error !== "cancel") {
          console.error("导出失败:", error);
          this.$message.error("导出失败");
        }
      } finally {
        this.exportLoading = false;
      }
    },
    // 文件下载处理
    download(fileName) {
      // 这里实现文件下载逻辑
      console.log("下载文件:", fileName);
      // 根据您的项目实际文件下载方式实现
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        infoid: undefined,
        organid: undefined,
        recipientname: "",
        recipientphone: "",
        recipientdescribe: "",
        hospitalname: "",
        hospitaldept: "",
        hospitalno: "",
        doctorname: "",
        doctorphone: "",
        doctordescribe: "",
        donateresult: "",
        followuptime: undefined,
        followupno: "",
        followupdescribe: "",
        seqno: 1,
        remark: ""
      };
      this.selectedCase = null;
      this.selectedCaseRow = null;
      this.resetForm("form");
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 提交表单
    submitForm() {
      this.$refs["form"].validate(async valid => {
        if (valid) {
          let response;
          if (this.form.id) {
            // 修改
            response = await updateFollowup(this.form);
          } else {
            // 新增
            response = await addFollowup(this.form);
          }
 
          if (response.code === 200) {
            this.$message.success("操作成功");
            this.open = false;
            this.getList();
          } else {
            this.$message.error(response.msg || "操作失败");
          }
        }
      });
    },
    // 打开选择案例对话框
    openCaseDialog() {
      this.selectCaseOpen = true;
      this.caseQueryParams.pageNum = 1;
      this.resetCaseSearch();
      this.searchCaseList();
    },
    // 搜索案例列表
    async searchCaseList() {
      this.caseLoading = true;
      try {
        const params = {
          pageNum: this.caseQueryParams.pageNum,
          pageSize: this.caseQueryParams.pageSize
        };
 
        if (this.caseQueryParams.name) {
          params.name = this.caseQueryParams.name;
        }
        if (this.caseQueryParams.treatmenthospitalname) {
          params.treatmenthospitalname = this.caseQueryParams.treatmenthospitalname;
        }
        if (this.caseQueryParams.starttime) {
          params.starttime = this.caseQueryParams.starttime;
        }
        if (this.caseQueryParams.endtime) {
          params.endtime = this.caseQueryParams.endtime;
        }
 
        const response = await listDonatebaseinfo(params);
        if (response.code === 200) {
          this.availableCaseList = response.data || [];
          this.caseTotal = response.total || this.availableCaseList.length;
        } else {
          this.$message.error("获取案例列表失败");
          this.availableCaseList = [];
          this.caseTotal = 0;
        }
      } catch (error) {
        console.error("搜索案例失败:", error);
        this.$message.error("获取案例列表失败");
        this.availableCaseList = [];
        this.caseTotal = 0;
      } finally {
        this.caseLoading = false;
      }
    },
    // 重置案例搜索
    resetCaseSearch() {
      this.caseQueryParams = {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        treatmenthospitalname: undefined,
        starttime: undefined,
        endtime: undefined
      };
      this.caseSelectTime = [];
      this.handleCaseTimeSelect();
    },
    // 处理案例时间选择
    handleCaseTimeSelect(timeRange) {
      if (!timeRange) {
        this.caseQueryParams.starttime = undefined;
        this.caseQueryParams.endtime = undefined;
        return;
      }
 
      const [start, end] = timeRange;
      this.caseQueryParams.starttime = `${start} 00:00:00`;
 
      const monthNum = Number(end.slice(5, 7));
      const nextMonth = monthNum < 9 ? `0${monthNum + 1}` : monthNum + 1;
      this.caseQueryParams.endtime = `${end.slice(
        0,
        5
      )}${nextMonth}-01 00:00:00`;
    },
    // 检查案例是否已有随访记录
    hasFollowup(row) {
      return this.existingFollowupCases.has(row.id);
    },
    // 案例行点击事件
    handleCaseRowClick(row) {
      this.selectedCaseRow = row;
    },
    // 选择案例
    selectCase(row) {
      this.selectedCaseRow = row;
    },
    // 确认选择案例
    confirmCaseSelection() {
      if (this.selectedCaseRow) {
        this.selectedCase = this.selectedCaseRow;
        this.form.infoid = this.selectedCaseRow.id;
        this.form.organid = this.selectedCaseRow.organid;
        this.selectCaseOpen = false;
 
        // 如果选择案例成功,自动填充一些默认值
        this.form.seqno = this.calculateNextSeqNo();
        this.form.followupno = this.$store.state.user.name || "";
      } else {
        this.$message.warning("请先选择一个案例");
      }
    },
    // 计算下一个随访序号
    calculateNextSeqNo() {
      if (this.selectedCase) {
        const caseFollowups = this.followupList.filter(
          followup => followup.infoid === this.selectedCase.id
        );
        if (caseFollowups.length === 0) {
          return 1;
        }
        const maxSeqNo = Math.max(
          ...caseFollowups.map(item => Number(item.seqno) || 1)
        );
        return maxSeqNo + 1;
      }
      return 1;
    },
    // 时间格式化
    parseTime(time, pattern) {
      if (!time) return "";
      const date = new Date(time);
      if (pattern) {
        if (pattern === "{y}-{m}-{d}") {
          return `${date.getFullYear()}-${(date.getMonth() + 1)
            .toString()
            .padStart(2, "0")}-${date
            .getDate()
            .toString()
            .padStart(2, "0")}`;
        }
      }
      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")}:${date
        .getSeconds()
        .toString()
        .padStart(2, "0")}`;
    }
  }
};
</script>
 
<style scoped>
.followup-list {
  padding: 20px;
}
 
.search-card {
  margin-bottom: 20px;
}
 
.tool-card {
  margin-bottom: 20px;
}
 
.fixed-width .el-button {
  margin: 0 5px;
}
 
.case-select-container {
  max-height: 600px;
  overflow-y: auto;
}
 
.dialog-footer {
  text-align: right;
}
 
/* 鼠标悬停行样式 */
.el-table__row:hover {
  cursor: pointer;
  background-color: #f5f7fa;
}
</style>