WXL
14 小时以前 888f941ae16c850c0f1a844ec9436058840920bd
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
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
<template>
  <view class="case-report-container">
    <!-- 表单内容 -->
    <scroll-view scroll-y class="form-scroll" :show-scrollbar="false">
      <view class="form-content">
        <view class="page-header">
          <text class="page-title">{{
            isEditMode ? "修改案例" : "上报案例"
          }}</text>
        </view>
        <!-- 基本信息卡片 -->
        <view class="form-section">
          <view class="section-header">
            <view class="section-icon">📋</view>
            <text class="section-title">捐献案例基本信息</text>
          </view>
 
          <view class="form-grid">
            <!-- 修改后:治疗医院输入框 -->
            <view class="form-item">
              <text class="item-label required">治疗医院</text>
              <u-input
                v-model="form.treatmenthospitalname"
                placeholder="请输入治疗医院名称"
                maxlength="100"
                class="custom-input"
              />
            </view>
 
            <!-- 新增:上报医院 -->
            <view class="form-item">
              <text class="item-label">上报医院</text>
              <u-input
                v-model="form.toHospital"
                placeholder="请输入上报医院"
                maxlength="100"
                class="custom-input"
              />
            </view>
 
            <!-- 新增:部门名称 -->
            <view class="form-item">
              <text class="item-label">部门名称</text>
              <u-input
                v-model="form.deptName"
                placeholder="请输入部门名称"
                maxlength="50"
                class="custom-input"
              />
            </view>
 
            <view class="form-item">
              <text class="item-label required">患者姓名</text>
              <u-input
                type="text"
                v-model="form.name"
                placeholder="请输入姓名"
                maxlength="20"
                class="custom-input"
              />
            </view>
          </view>
        </view>
 
        <!-- 个人信息卡片 -->
        <view class="form-section">
          <view class="section-header">
            <view class="section-icon">👤</view>
            <text class="section-title">捐献人信息</text>
          </view>
 
          <view class="form-grid">
            <!-- 改造后的民族选择 -->
            <view class="form-item">
              <text class="item-label">民族</text>
              <picker
                mode="selector"
                :range="nationLabels"
                :value="nationIndex"
                @change="onNationChange"
              >
                <view class="picker">
                  <text>{{ currentNation }}</text>
                  <text class="icon-arrow">›</text>
                </view>
              </picker>
            </view>
 
            <view class="form-item">
              <text class="item-label">国籍</text>
              <u-input
                type="text"
                v-model="form.nationality"
                placeholder="请输入国籍"
                class="custom-input"
              />
            </view>
 
            <!-- 改造后的证件类型选择 -->
            <view class="form-item">
              <text class="item-label">证件类型</text>
              <picker
                mode="selector"
                :range="idCardTypeLabels"
                :value="idCardTypeIndex"
                @change="onIdCardTypeChange"
              >
                <view class="picker">
                  <text>{{ currentIdCardType }}</text>
                  <text class="icon-arrow">›</text>
                </view>
              </picker>
            </view>
 
            <view class="form-item">
              <text class="item-label required">证件号码</text>
              <u-input
                type="idcard"
                v-model="form.idcardno"
                placeholder="请输入证件号码"
                maxlength="18"
                class="custom-input"
                @blur="validateIdCard"
              />
              <text class="error-text" v-if="idCardError">{{
                idCardError
              }}</text>
            </view>
 
            <!-- 改造后的性别选择 -->
            <view class="form-item">
              <text class="item-label">性别</text>
              <view class="radio-options">
                <view
                  v-for="gender in genderOptions"
                  :key="gender.value"
                  class="option-item"
                  :class="{ active: form.sex === gender.value }"
                  @click="form.sex = gender.value"
                >
                  <text class="radio-dot"></text>
                  <text class="option-label">{{ gender.label }}</text>
                </view>
              </view>
            </view>
 
            <!-- 改造后的出生日期选择 -->
            <view class="form-item">
              <text class="item-label">出生日期</text>
              <picker
                mode="date"
                :value="form.birthday"
                @change="onBirthdayChange"
              >
                <view class="picker">
                  <text>{{ form.birthday || "选择出生日期" }}</text>
                  <text class="icon-arrow">›</text>
                </view>
              </picker>
            </view>
 
            <view class="form-item">
              <text class="item-label">年龄</text>
              <u-input
                v-model="ageDisplay"
                placeholder="自动计算"
                disabled
                :disabledColor="disabledColor"
                border="none"
              />
            </view>
          </view>
        </view>
 
        <!-- 医疗信息卡片 -->
        <view class="form-section">
          <view class="section-header">
            <view class="section-icon">🏥</view>
            <text class="section-title">医疗信息</text>
          </view>
 
          <view class="form-grid">
            <view class="form-item">
              <text class="item-label">住院号</text>
              <u-input
                v-model="form.inpatientno"
                placeholder="请输入住院号"
                border="none"
              />
            </view>
            <view class="form-item">
              <text class="item-label">GCS评分</text>
              <u-input
                v-model="form.gcsScore"
                placeholder="请输入GCS评分"
                border="none"
              />
            </view>
 
            <view class="form-item full-width">
              <text class="item-label required">疾病诊断</text>
              <u-textarea
                v-model="form.diagnosisname"
                placeholder="请输入疾病诊断名称"
                count
                maxlength="200"
                :customStyle="textareaStyle(!form.diagnosisname)"
              />
            </view>
            <view class="form-item">
              <text class="item-label">是否需要转运</text>
              <view class="radio-group horizontal">
                <view
                  v-for="bloodType in isTransportOptions"
                  :key="bloodType.value"
                  class="radio-item"
                  @click="form.isTransport = bloodType.value"
                >
                  <view
                    class="radio-dot"
                    :class="{ active: form.isTransport === bloodType.value }"
                  ></view>
                  <text class="radio-label">{{ bloodType.label }}</text>
                </view>
              </view>
            </view>
            <view class="form-item">
              <text class="item-label">血型</text>
              <view class="radio-group horizontal">
                <view
                  v-for="bloodType in bloodTypeOptions"
                  :key="bloodType.value"
                  class="radio-item"
                  @click="form.bloodType = bloodType.value"
                >
                  <view
                    class="radio-dot"
                    :class="{ active: form.bloodType === bloodType.value }"
                  ></view>
                  <text class="radio-label">{{ bloodType.label }}</text>
                </view>
              </view>
            </view>
            <view class="form-item">
              <text class="item-label">传染病</text>
              <view class="radio-group horizontal">
                <view
                  v-for="bloodType in infectiousDiseaselist"
                  :key="bloodType.value"
                  class="radio-item"
                  @click="form.infectious = bloodType.value"
                >
                  <view
                    class="radio-dot"
                    :class="{ active: form.infectious == bloodType.value }"
                  ></view>
                  <text class="radio-label">{{ bloodType.label }}</text>
                </view>
              </view>
            </view>
            <view class="form-item">
              <text class="item-label">其他</text>
              <u-input
                v-model="form.infectiousOther"
                placeholder="请输入其他传染病"
                border="none"
              />
            </view>
 
            <view class="form-item">
              <text class="item-label">Rh(D)</text>
              <view class="radio-group horizontal">
                <view
                  v-for="rh in rhOptions"
                  :key="rh.value"
                  class="radio-item"
                  @click="form.rhYin = rh.value"
                >
                  <view
                    class="radio-dot"
                    :class="{ active: form.rhYin === rh.value }"
                  ></view>
                  <text class="radio-label">{{ rh.label }}</text>
                </view>
              </view>
            </view>
          </view>
        </view>
 
        <!-- 联系信息卡片 -->
        <view class="form-section">
          <view class="section-header">
            <view class="section-icon">📞</view>
            <text class="section-title">联系信息</text>
          </view>
 
          <view class="form-grid">
            <view class="form-item">
              <text class="item-label">信息员</text>
              <u-input
                v-model="form.infoname"
                placeholder="请输入信息员"
                border="none"
              />
            </view>
 
            <view class="form-item">
              <text class="item-label">联系电话</text>
              <u-input
                v-model="form.infophone"
                placeholder="请输入联系电话"
                type="number"
                border="none"
              />
            </view>
 
            <!-- <view class="form-item">
              <text class="item-label">报告人</text>
              <u-input
                v-model="form.reporterno"
                placeholder="请选择报告人"
                readonly
                border="none"
                @click="showReporterPicker = true"
              >
                <template #suffix>
                  <u-icon name="arrow-down" color="#86868b"></u-icon>
                </template>
              </u-input>
            </view> -->
 
            <view class="form-item">
              <text class="item-label">报告时间</text>
              <u-input
                v-model="currentTime"
                disabled
                :disabledColor="disabledColor"
                border="none"
              />
            </view>
          </view>
        </view>
 
        <!-- 操作按钮 -->
        <view class="action-buttons">
          <u-button class="btn secondary" @click="handleCancel">取消</u-button>
          <u-button class="btn secondary" @click="resetForm">重置表单</u-button>
          <u-button
            class="btn primary"
            :disabled="!isFormValid || loading"
            @click="handleSubmit"
          >
            {{ loading ? "提交中..." : isEditMode ? "保存修改" : "提交上报" }}
          </u-button>
        </view>
        <attachment-upload
          ref="attachment"
          :files="attachments"
          :readonly="isReadonly"
          :maxCount="5"
          @update:files="handleFilesUpdate"
          @upload-base="handleBaseUpload"
          @preview="handlePreview"
        />
      </view>
    </scroll-view>
 
    <!-- 科室选择器 -->
    <u-picker
      :show="selectShow"
      :columns="pickerColumns"
      keyName="label"
      @confirm="onConfirm"
      @cancel="selectShow = false"
      title="请选择科室"
      ref="uPicker"
    ></u-picker>
 
    <!-- 医疗机构选择器 -->
    <u-picker
      :show="showHospitalPicker"
      :columns="[hospitalOptions]"
      keyName="label"
      @confirm="onHospitalConfirm"
      @cancel="showHospitalPicker = false"
      title="请选择医疗机构"
    ></u-picker>
 
    <!-- 民族选择器 -->
    <u-picker
      :show="showNationPicker"
      :columns="[nationOptions]"
      keyName="label"
      @confirm="onNationConfirm"
      @cancel="showNationPicker = false"
      title="请选择民族"
    ></u-picker>
 
    <!-- 证件类型选择器 -->
    <!-- <u-picker
      :show="showIdCardTypePicker"
      :columns="[idCardTypeOptions]"
      keyName="label"
      @confirm="onIdCardTypeConfirm"
      @cancel="showIdCardTypePicker = false"
      title="请选择证件类型"
    ></u-picker> -->
 
    <!-- 日期选择器 -->
    <u-datetime-picker
      :show="showDatePicker"
      v-model="birthdayValue"
      mode="date"
      @confirm="onDateConfirm"
      @cancel="showDatePicker = false"
      title="选择出生日期"
    ></u-datetime-picker>
 
    <!-- 报告人选择器 -->
    <u-picker
      :show="showReporterPicker"
      :columns="[reporterOptions]"
      keyName="label"
      @confirm="onReporterConfirm"
      @cancel="showReporterPicker = false"
      title="请选择报告人"
    ></u-picker>
 
    <!-- 加载状态 -->
    <u-loading-icon :show="loading" text="提交中..."></u-loading-icon>
  </view>
</template>
 
<script setup>
import { ref, computed, onMounted } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import attachmentUpload from "@/components/attachment";
import { useUserStore } from "@/stores/user";
import { useDict } from "@/utils/dict";
 
const dict = ref({});
const userStore = useUserStore();
const isEditMode = ref(false);
const currentId = ref(null);
// 表单数据
const form = ref({
  caseNo: "",
  treatmenthospitalname: "",
  treatmentdeptname: "",
  name: "",
  nation: "",
  nationality: "中国",
  idcardtype: "",
  idcardno: "",
  sex: "",
  birthday: "",
  age: "",
  ageunit: "", // 新增:年龄单位
  inpatientno: "",
  diagnosisname: "",
  bloodType: "",
  rhYin: "",
  infoname: "",
  infophone: "",
  reportername: userStore.name || "",
  reporterno: userStore.userId || "",
  reporterphone: "", // 报告者联系电话
  reporttime: "",
  contactperson: "", // 新增:联系人(协调员)
  education: "", // 新增:学历
  illnessoverview: "", // 新增:病情概况
  infectious: "", // 传染病情况
  infectiousOther: "", // 传染病其他
  isTransport: "1", // 新增:是否需要转运,默认1不需要
  nativeplace: "", // 新增:籍贯
  occupation: "", // 新增:职业
  patientstate: "", // 新增:病人状况
  phone: "", // 新增:联系电话
  registeraddress: "", // 新增:户籍地址
  registerprovince: "", // 新增:户籍地址省编号
  registerprovincename: "", // 新增:户籍地址省名称
  registercityname: "", // 新增:市名称
  registertownname: "", // 新增:所属街道(镇)名称
  registercommunityname: "", // 新增:社区(村)名称
  residenceaddress: "", // 新增:现住地址
  residenceprovince: "", // 新增:现住地址省代码
  residenceprovincename: "", // 新增:现住地址省名称
  residencecountycode: "", // 新增:所属区域编号
  residencecountyname: "", // 新增:所属区域名称
  residencetownname: "", // 新增:所属街道(镇)名称
  residencecommunity: "", // 新增:社区(村)编号
  residencecommunityname: "", // 新增:社区(村)名称
  remark: "", // 新增:备注
  reportStatus: "1", // 新增:上报状态,默认1已上报
  terminationCase: 0, // 新增:是否终止案例,默认0开启
  annexfilesList: [], // 附件文件地址集合
});
 
// 选择器状态
const attachments = ref([]);
const infectiousDiseaselist = ref([]);
const nationLabel = ref([]);
 
const isReadonly = ref(false);
const id = ref(null);
const selectShow = ref(false);
const showHospitalPicker = ref(false);
const showNationPicker = ref(false);
const showIdCardTypePicker = ref(false);
const showDatePicker = ref(false);
const showReporterPicker = ref(false);
const birthdayValue = ref(0);
 
// 字典数据选项
const hospitalOptions = ref([
  { label: "青岛镜湖医院", value: "qdhospital1" },
  { label: "青岛科大医院", value: "qdhospital2" },
  { label: "青岛大学附属医院", value: "qdhospital3" },
  { label: "青岛市立医院", value: "qdhospital4" },
]);
 
const pickerColumns = ref([
  [
    { label: "神经外科", value: "neurosurgery" },
    { label: "心血管内科", value: "cardiology" },
    { label: "重症医学科", value: "icu" },
    { label: "急诊科", value: "emergency" },
    { label: "神经内科", value: "neurology" },
    { label: "呼吸内科", value: "respiratory" },
    { label: "消化内科", value: "gastroenterology" },
    { label: "肾内科", value: "nephrology" },
  ],
]);
 
const nationOptions = ref([
  { label: "汉族", value: "han" },
  { label: "回族", value: "hui" },
  { label: "满族", value: "man" },
  { label: "蒙古族", value: "menggu" },
]);
 
const idCardTypeOptions = ref([
  { label: "居民身份证", value: "idcard" },
  { label: "护照", value: "passport" },
  { label: "军官证", value: "officer" },
]);
 
const genderOptions = ref([
  { label: "男", value: "1" },
  { label: "女", value: "2" },
]);
 
const bloodTypeOptions = ref([
  { label: "A型", value: "A型" },
  { label: "B型", value: "B型" },
  { label: "O型", value: "O型" },
  { label: "AB型", value: "AB型" },
]);
const isTransportOptions = ref([
  { label: "需要", value: "2" },
  { label: "不需要", value: "1" },
]);
const rhOptions = ref([
  { label: "阳性", value: "1" },
  { label: "阴性", value: "0" },
]);
 
const reporterOptions = ref([
  { label: "张医生", value: "doctor1" },
  { label: "李医生", value: "doctor2" },
]);
 
// 状态管理
const loading = ref(false);
const currentTime = ref("");
const disabledColor = ref("#f5f5f7");
 
// 计算属性
const isFormValid = computed(() => {
  return (
    form.value.name &&
    form.value.idcardno &&
    form.value.diagnosisname &&
    form.value.toHospital
  );
});
// 选择器索引
const hospitalIndex = ref(-1);
const deptIndex = ref(-1);
const nationIndex = ref(-1);
const idCardTypeIndex = ref(-1);
 
// 计算属性 - 标签数组
const hospitalLabels = computed(() =>
  hospitalOptions.value.map((item) => item.label),
);
const ageDisplay = computed(() => {
  if (!form.value.age || !form.value.ageunit) {
    return "自动计算";
  }
  return `${form.value.age}${form.value.ageunit}`;
});
const deptLabels = computed(() => {
  return pickerColumns.value[0].map((item) => item.label);
});
const nationLabels = computed(() =>
  nationLabel.value.map((item) => item.label),
);
const idCardTypeLabels = computed(() =>
  idCardTypeOptions.value.map((item) => item.label),
);
 
// 计算属性 - 当前选中显示文本
const currentHospital = computed(() => {
  return hospitalIndex.value >= 0
    ? hospitalLabels.value[hospitalIndex.value]
    : "请选择医疗机构";
});
 
const currentDept = computed(() => {
  return deptIndex.value >= 0
    ? deptLabels.value[deptIndex.value]
    : "请选择科室";
});
 
const currentNation = computed(() => {
  return nationIndex.value >= 0
    ? nationLabels.value[nationIndex.value]
    : "请选择民族";
});
 
const currentIdCardType = computed(() => {
  return idCardTypeIndex.value >= 0
    ? idCardTypeLabels.value[idCardTypeIndex.value]
    : "请选择证件类型";
});
 
const onNationChange = (e) => {
  const index = parseInt(e.detail.value);
  nationIndex.value = index;
  form.value.nation = nationOptions.value[index].label;
  console.log(form.value.nation, "form.value.nation");
};
 
const onIdCardTypeChange = (e) => {
  const index = parseInt(e.detail.value);
  idCardTypeIndex.value = index;
  form.value.idcardtype = idCardTypeOptions.value[index].value;
  console.log(form.value.idcardtype, "form.value.idcardtype");
};
 
const onBirthdayChange = (e) => {
  form.value.birthday = e.detail.value;
  calculateAge();
};
const onDateConfirm = (e) => {
  const date = new Date(e.value);
 
  // 格式化日期为 YYYY-MM-DD
  form.value.birthday = `${date.getFullYear()}-${(date.getMonth() + 1)
    .toString()
    .padStart(2, "0")}-${date.getDate().toString().padStart(2, "0")}`;
 
  calculateAge();
  showDatePicker.value = false;
};
 
// 身份证验证
const idCardError = ref("");
const validateIdCard = () => {
  if (!form.value.idcardno) {
    idCardError.value = "请输入证件号码";
    return false;
  }
 
  if (form.value.idcardno.length !== 18) {
    idCardError.value = "请输入18位身份证号码";
    return false;
  }
 
  idCardError.value = "";
  return true;
};
// 样式方法
const inputStyle = (isError) => {
  return isError
    ? "border: 2rpx solid #ff4757; border-radius: 12rpx;"
    : "border: 2rpx solid #e5e5e7; border-radius: 12rpx;";
};
 
const textareaStyle = (isError) => {
  return isError
    ? "border: 2rpx solid #ff4757; border-radius: 12rpx; min-height: 120rpx; padding: 20rpx 24rpx;"
    : "border: 2rpx solid #e5e5e7; border-radius: 12rpx; min-height: 120rpx; padding: 20rpx 24rpx;";
};
 
// 生命周期
onMounted(() => {
  // updateCurrentTime();
  // generateDonorNo();
  setInterval(updateCurrentTime, 1000);
});
 
onLoad(async (options) => {
  id.value = options.id;
  if (options.id) {
    currentId.value = options.id;
    isEditMode.value = true;
    await loadCaseData(options.id);
  } else {
    isEditMode.value = false;
    generateDonorNo();
  }
  // 获取字典数据
  dict.value = await useDict(
    "sys_IDType",
    "sys_user_sex",
    "sys_Nation",
    "sys_BloodType",
    "sys_Infectious",
    "sys_AgeUnit", // 新增年龄单位
    "sys_education", // 新增学历
    "sys_occupation", // 新增职业
  );
  initOptions();
  updateCurrentTime();
});
// 初始化选项数据的方法
const initOptions = () => {
  infectiousDiseaselist.value = dict.value.sys_Infectious || [];
  idCardTypeOptions.value = dict.value.sys_IDType || [];
  nationLabel.value = dict.value.sys_Nation || [];
};
// 方法定义
const updateCurrentTime = () => {
  const now = new Date();
  // 先获取格式化的字符串,然后替换分隔符和调整顺序
  const localString = now.toLocaleString("zh-CN", {
    year: "numeric",
    month: "2-digit",
    day: "2-digit",
    hour: "2-digit",
    minute: "2-digit",
    second: "2-digit",
    hour12: false,
  });
  // 将 "yyyy/mm/dd hh:mm:ss" 转换为 "yyyy-mm-dd hh:mm:ss"
  currentTime.value = localString.replace(/\//g, "-");
  form.value.reporttime = currentTime.value;
};
 
const generateDonorNo = () => {
  const date = new Date();
  const timestamp = date.getTime().toString().slice(-6);
  // form.value.caseNo = `DON${date.getFullYear()}${(date.getMonth() + 1)
  //   .toString()
  //   .padStart(2, "0")}${timestamp}`;
};
 
const calculateAge = () => {
  if (!form.value.birthday) {
    form.value.age = "";
    form.value.ageunit = "";
    return;
  }
 
  const birthDate = new Date(form.value.birthday);
  const today = new Date();
 
  // 检查日期有效性
  if (isNaN(birthDate.getTime())) {
    form.value.age = "";
    form.value.ageunit = "";
    return;
  }
 
  // 计算总天数差
  const timeDiff = today.getTime() - birthDate.getTime();
  const daysDiff = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
 
  if (daysDiff < 0) {
    // 未来日期处理
    form.value.age = "";
    form.value.ageunit = "";
    return;
  }
 
  // 计算年、月、日
  const years = today.getFullYear() - birthDate.getFullYear();
  const months = today.getMonth() - birthDate.getMonth();
  const days = today.getDate() - birthDate.getDate();
 
  let ageValue, ageUnit;
 
  if (years >= 1) {
    // 大于等于1年:显示年
    let actualYears = years;
 
    // 处理月份和日期的边界情况
    if (months < 0 || (months === 0 && days < 0)) {
      actualYears = years - 1;
    }
 
    ageValue = actualYears.toString();
    ageUnit = "岁";
  } else if (daysDiff >= 30) {
    // 大于等于30天:显示月
    let totalMonths = years * 12 + months;
    if (days < 0) {
      totalMonths--;
    }
    ageValue = Math.max(1, totalMonths).toString(); // 确保至少1个月
    ageUnit = "个月";
  } else {
    // 小于30天:显示天
    ageValue = Math.max(1, daysDiff).toString(); // 确保至少1天
    ageUnit = "天";
  }
 
  form.value.age = ageValue;
  form.value.ageunit = ageUnit;
};
 
// 处理基础附件上传
const handleBaseUpload = (file) => {
  console.log("基础附件上传成功:", file);
  attachments.value.push(file);
};
 
// 处理其他附件上传
const handleFilesUpdate = (files) => {
  console.log(files, "files");
 
  attachments.value = files.map((file) => ({
    ...file,
    // 确保只存储半路径
    // url: file.url.startsWith("http")
    //   ? file.url.replace(baseUrlHt, "")
    //   : file.url,
  }));
};
 
// 预览文件 - 修改为使用完整URL
const handlePreview = (file) => {
  const fullUrl = file.url.startsWith("http")
    ? file.url
    : baseUrlHt + (file.url.startsWith("/") ? "" : "/") + file.url;
 
  if (file.type.includes("image")) {
    uni.previewImage({
      urls: attachments.value
        .filter((f) => f.type.includes("image"))
        .map((f) =>
          f.url.startsWith("http")
            ? f.url
            : baseUrlHt + (f.url.startsWith("/") ? "" : "/") + f.url,
        ),
      current: fullUrl,
    });
  } else if (file.type.includes("pdf")) {
    uni.downloadFile({
      url: fullUrl,
      success: (res) => {
        uni.openDocument({
          filePath: res.tempFilePath,
          fileType: "pdf",
          showMenu: true,
        });
      },
      fail: (err) => {
        console.error("打开文档失败:", err);
        uni.showToast({ title: "打开文件失败", icon: "none" });
      },
    });
  } else {
    uni.showToast({ title: "暂不支持此文件类型预览", icon: "none" });
  }
};
// 选择器确认事件
const onConfirm = (e) => {
  if (e.value && e.value[0]) {
    form.value.treatmentdeptname = e.value[0].label;
  }
  selectShow.value = false;
};
 
const onHospitalConfirm = (e) => {
  console.log(e, "民族");
 
  if (e.value && e.value[0]) {
    form.value.treatmenthospitalname = e.value[0].label;
  }
  showHospitalPicker.value = false;
};
 
const onNationConfirm = (e) => {
  if (e.value && e.value[0]) {
    form.value.nation = e.value[0].label;
  }
  showNationPicker.value = false;
};
 
const onIdCardTypeConfirm = (e) => {
  if (e.value && e.value[0]) {
    form.value.idcardtype = e.value[0].value;
  }
  showIdCardTypePicker.value = false;
};
 
// const onDateConfirm = (e) => {
//   const date = new Date(e.value);
//   form.value.birthday = `${date.getFullYear()}-${(date.getMonth() + 1)
//     .toString()
//     .padStart(2, "0")}-${date.getDate().toString().padStart(2, "0")}`;
//   calculateAge();
//   showDatePicker.value = false;
// };
 
const onReporterConfirm = (e) => {
  if (e.value && e.value[0]) {
    form.value.reporterno = e.value[0].label;
  }
  showReporterPicker.value = false;
};
 
const goBack = () => {
  uni.navigateBack();
};
 
const resetForm = () => {
  uni.showModal({
    title: "确认重置",
    content: "确定要清空所有已填写的内容吗?",
    success: (res) => {
      if (res.confirm) {
        Object.keys(form.value).forEach((key) => {
          if (!["id", "caseNo"].includes(key)) {
            form.value[key] = "";
          }
        });
 
        // 重置选择器索引
        hospitalIndex.value = -1;
        deptIndex.value = -1;
        nationIndex.value = -1;
        idCardTypeIndex.value = -1;
        attachments.value = [];
        form.value.nationality = "中国";
        form.value.isTransport = "1";
        form.value.terminationCase = 0;
        form.value.reportStatus = "1";
 
        if (!isEditMode.value) {
          generateDonorNo();
        }
 
        uni.showToast({ title: "表单已重置", icon: "success" });
      }
    },
  });
};
 
const handleSubmit = async () => {
  if (!isFormValid.value) {
    uni.showToast({
      title: "请填写姓名、证件号码和疾病诊断",
      icon: "none",
    });
    return;
  }
 
  try {
    uni.showLoading({ title: isEditMode.value ? "修改中..." : "提交中..." });
    // 准备提交数据
    const submitData = {
      ...form.value,
      age: parseInt(form.value.age) || 0,
      annexfilesList: attachments.value.map((file) => ({
        path: file.url,
        fileName: file.name,
        type: file.type,
      })),
      phone: form.value.infophone,
      isTransport: form.value.isTransport || "1",
      terminationCase: form.value.terminationCase || 0,
      reportStatus: form.value.reportStatus || "1",
    };
 
    let res;
    if (isEditMode.value) {
      // 修改接口
      res = await uni.$uapi.post(
        "/project/donatebaseinforeport/edit",
        submitData,
      );
    } else {
      // 新增接口
      res = await uni.$uapi.post(
        "/project/donatebaseinforeport/add",
        submitData,
      );
    }
 
    uni.hideLoading();
 
    if (res.code === 200) {
      uni.showToast({
        title: isEditMode.value ? "修改成功" : "上报成功",
        icon: "success",
      });
 
      // 清空本地存储的草稿
      removeDraft();
 
      setTimeout(() => {
        uni.navigateBack();
      }, 1500);
    } else {
      throw new Error(res.msg || "操作失败");
    }
  } catch (error) {
    console.error("操作失败:", error);
    uni.showToast({
      title: error.message || (isEditMode.value ? "修改失败" : "上报失败"),
      icon: "none",
    });
  } finally {
    loading.value = false;
  }
};
const removeDraft = () => {
  localStorage.removeItem("caseReportDraft");
};
// 取消处理
const handleCancel = () => {
  uni.navigateBack();
};
 
const loadCaseData = async (id) => {
  try {
    loading.value = true;
    const res = await uni.$uapi.get(
      `/project/donatebaseinforeport/getInfo/${id}`,
    );
 
    if (res.code) {
      form.value = res.data;
 
      // 处理选择器索引
      // updatePickerIndexes();
 
      console.log(2, "res");
      // 处理附件
      if (res.data.annexfilesList) {
        attachments.value = res.data.annexfilesList;
        attachments.value.forEach((item) => {
          item.url = item.path;
          item.name = item.fileName;
        });
      }
      console.log(3, "res");
 
      uni.showToast({
        title: "数据加载成功",
        icon: "success",
      });
    } else {
      throw new Error(res.msg || "数据加载失败");
    }
  } catch (error) {
    console.error("加载案例数据失败:", error);
    uni.showToast({
      title: "数据加载失败,请重试",
      icon: "none",
    });
  } finally {
    loading.value = false;
  }
};
 
</script>
<style lang="scss" scoped>
.case-report-container {
  min-height: 100vh;
  background: linear-gradient(135deg, #f8fdff 0%, #e8f7f6 100%);
}
 
.form-scroll {
  height: 100vh;
}
 
.form-content {
  padding: 30rpx;
}
 
.form-section {
  background: #fff;
  border-radius: 20rpx;
  padding: 30rpx;
  margin-bottom: 30rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
}
 
.section-header {
  display: flex;
  // align-items: center;
  margin-bottom: 30rpx;
  padding-bottom: 20rpx;
  border-bottom: 2rpx solid #f0f0f0;
}
 
.section-icon {
  font-size: 32rpx;
  margin-right: 16rpx;
}
 
.section-title {
  font-size: 32rpx;
  font-weight: 600;
  color: #1d1d1f;
}
 
.form-grid {
  display: flex;
  flex-direction: column;
  gap: 24rpx;
}
 
.form-item {
  display: flex;
  flex-direction: column;
 
  &.full-width {
    grid-column: 1 / -1;
  }
}
 
.item-label {
  font-size: 28rpx;
  color: #1d1d1f;
  font-weight: 500;
  margin-bottom: 12rpx;
 
  &.required::after {
    content: "*";
    color: #ff4757;
    margin-left: 4rpx;
  }
}
 
// 自定义u-input样式
:deep(.u-input) {
  border: 2rpx solid #e5e5e7 !important;
  border-radius: 12rpx !important;
  padding: 20rpx 24rpx !important;
  background: #fff !important;
}
 
:deep(.u-textarea) {
  border: 2rpx solid #e5e5e7 !important;
  border-radius: 12rpx !important;
  padding: 20rpx 24rpx !important;
  background: #fff !important;
}
 
.radio-group {
  display: flex;
  gap: 40rpx;
 
  &.horizontal {
    flex-wrap: wrap;
    gap: 20rpx;
  }
}
 
.radio-item {
  display: flex;
  align-items: center;
  gap: 16rpx;
}
 
.radio-dot {
  width: 32rpx;
  height: 32rpx;
  border: 2rpx solid #e5e5e7;
  border-radius: 50%;
  position: relative;
 
  &.active {
    border-color: #0f95b0;
 
    &::after {
      content: "";
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 16rpx;
      height: 16rpx;
      background: #0f95b0;
      border-radius: 50%;
    }
  }
}
 
.radio-label {
  font-size: 28rpx;
  color: #1d1d1f;
}
 
.action-buttons {
  display: flex;
  gap: 20rpx;
  margin-top: 40rpx;
  // background: #fff;
  // padding: 20rpx 0;
  // position: fixed;
  // bottom: 0;
  // left: 0;
  // right: 0;
  // padding: 20rpx 30rpx;
  // padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  // box-shadow: 0 -2rpx 20rpx rgba(0, 0, 0, 0.08);
  // z-index: 9;
}
 
.btn {
  flex: 1;
  height: 80rpx;
  border-radius: 16rpx;
  font-size: 32rpx;
  font-weight: 500;
 
  &.secondary {
    background: #f5f5f7 !important;
    color: #1d1d1f !important;
  }
 
  &.primary {
    background: linear-gradient(135deg, #0f95b0, #89c4c1) !important;
    color: #fff !important;
 
    &:disabled {
      background: #c0c0c0 !important;
      opacity: 0.6;
    }
  }
}
.case-report-container {
  min-height: 100vh;
  background: linear-gradient(135deg, #f8fdff 0%, #e8f7f6 100%);
}
 
.form-scroll {
  height: 100vh;
}
 
.form-content {
  padding: 30rpx;
}
 
.form-section {
  background: #fff;
  border-radius: 20rpx;
  padding: 30rpx;
  margin-bottom: 30rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
}
 
.section-header {
  display: flex;
  align-items: center;
  margin-bottom: 30rpx;
  padding-bottom: 20rpx;
  border-bottom: 2rpx solid #f0f0f0;
}
 
.section-icon {
  font-size: 32rpx;
  margin-right: 16rpx;
}
 
.section-title {
  font-size: 32rpx;
  font-weight: 600;
  color: #1d1d1f;
}
 
.form-grid {
  display: flex;
  flex-direction: column;
  gap: 24rpx;
}
 
.form-item {
  display: flex;
  flex-direction: column;
}
 
.item-label {
  font-size: 28rpx;
  color: #1d1d1f;
  font-weight: 500;
  margin-bottom: 12rpx;
 
  &.required::after {
    content: "*";
    color: #ff4757;
    margin-left: 4rpx;
  }
}
 
/* 改造后的选择器样式 */
.picker {
  height: 88rpx;
  background: #f5f5f7;
  border-radius: 12rpx;
  padding: 0 24rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 2rpx solid #e5e5e7;
 
  text {
    font-size: 28rpx;
    color: #1d1d1f;
 
    &.icon-arrow {
      font-size: 32rpx;
      color: #86868b;
      transform: rotate(90deg);
    }
  }
}
 
.page-header {
  padding: 30rpx 0;
  text-align: center;
  margin-bottom: 20rpx;
}
 
.page-title {
  font-size: 36rpx;
  font-weight: 600;
  color: #1d1d1f;
}
 
/* 在原有样式基础上添加 */
.form-section {
  position: relative;
}
 
.edit-badge {
  position: absolute;
  top: 30rpx;
  right: 30rpx;
  background: #ff6b35;
  color: white;
  padding: 8rpx 16rpx;
  border-radius: 20rpx;
  font-size: 24rpx;
}
 
/* 加载状态样式 */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}
 
/* 响应式调整 */
@media (max-width: 768px) {
  .form-content {
    padding: 20rpx;
  }
 
  .form-section {
    padding: 20rpx;
  }
}
 
/* 改造后的单选按钮样式 */
.radio-options {
  display: flex;
  gap: 40rpx;
}
 
.option-item {
  display: flex;
  align-items: center;
  gap: 16rpx;
 
  .radio-dot {
    width: 32rpx;
    height: 32rpx;
    border: 2rpx solid #e5e5e7;
    border-radius: 50%;
    position: relative;
  }
 
  .option-label {
    font-size: 28rpx;
    color: #1d1d1f;
  }
 
  &.active {
    .radio-dot {
      border-color: #0f95b0;
 
      &::after {
        content: "";
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 16rpx;
        height: 16rpx;
        background: #0f95b0;
        border-radius: 50%;
      }
    }
 
    .option-label {
      color: #0f95b0;
    }
  }
}
 
.error-text {
  font-size: 24rpx;
  color: #ff4757;
  margin-top: 8rpx;
}
 
/* 原有样式调整 */
:deep(.u-input) {
  border: 2rpx solid #e5e5e7 !important;
  border-radius: 12rpx !important;
  padding: 20rpx 24rpx !important;
  background: #fff !important;
}
 
.btn {
  flex: 1;
  height: 80rpx;
  border-radius: 16rpx;
  font-size: 32rpx;
  font-weight: 500;
 
  &.secondary {
    background: #f5f5f7 !important;
    color: #1d1d1f !important;
  }
 
  &.primary {
    background: linear-gradient(135deg, #0f95b0, #89c4c1) !important;
    color: #fff !important;
 
    &:disabled {
      background: #c0c0c0 !important;
      opacity: 0.6;
    }
  }
}
</style>