11
WXL
2024-08-14 0ac2d43fce4d74f6eea5a51a2e16af4e6a536c7c
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
<!-- 器官分配 -->
<template>
  <div class="app-container">
    <!-- 搜索条件 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="70px"
    >
      <el-row :gutter="8">
        <el-col :span="6">
          <el-form-item label="捐献进度" prop="recordstate">
            <el-select
              v-model="queryParams.workflow"
              placeholder="请选择捐献进度"
              clearable
              size="small"
            >
              <el-option
                v-for="dict in dict.type.sys_donornode"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
 
        <el-col :span="6">
          <el-form-item label="姓名" prop="name">
            <el-input
              v-model="queryParams.name"
              placeholder="请输入姓名"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
 
        <el-col :span="6">
          <el-form-item
            align="left"
            label="医疗机构"
            prop="treatmenthospitalno"
          >
            <org-selecter
              ref="orgSelecter"
              :org-type="'3'"
              v-model="queryParams.treatmenthospitalno"
            />
          </el-form-item>
        </el-col>
 
        <el-col :span="6">
          <el-form-item label="捐献地市">
            <el-select v-model="queryParams.city" placeholder="请选择地市">
              <el-option
                v-for="item in provinceData"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="8">
        <el-col :span="6">
          <el-form-item label="报告人">
            <el-select
              v-model="queryParams.reporterno"
              placeholder="请选择报告人"
            >
              <el-option
                v-for="item in reportlist"
                :key="item.index"
                :label="item.reportername"
                :value="item.reporterno"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
 
        <el-col :span="12">
          <el-form-item label="案例时间">
            <el-date-picker
              style="width: 100%"
              v-model="selecttime"
              type="monthrange"
              range-separator="至"
              start-placeholder="开始月份"
              end-placeholder="结束月份"
              value-format="yyyy-MM-dd"
              @change="getTimeList"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
 
        <el-col :span="6">
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="getBaseInfoList"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
 
    <el-row :gutter="20">
      <el-col :span="24">
        <el-card shadow="never">
          <!-- 捐献案例列表 -->
          <el-table v-loading="loading" border :data="donationCaseTableData">
            <el-table-column
              label="案例时间"
              align="center"
              prop="donatetime"
              width="150"
            >
              <template slot-scope="scope">
                <span>{{
                  parseTime(scope.row.donatetime, "{y}-{m}-{d}")
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="姓名"
              align="center"
              prop="name"
              width="120"
            />
            <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"
            />
            <el-table-column
              label="报告人"
              align="center"
              prop="reportername"
              width="120"
            />
            <el-table-column
              label="案例归属"
              align="center"
              width="200px"
              prop="deptname"
            />
            <el-table-column
              label="医疗机构"
              align="center"
              prop="treatmenthospitalname"
            />
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
              width="200"
              fixed="right"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="selectDonotor(scope.row)"
                  >捐献详情</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <!-- hide-on-single-page -->
          <pagination
            v-show="total > 0"
            small
            layout="prev, pager, next"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getBaseInfoList"
          />
        </el-card>
      </el-col>
      <!-- <el-col :span="16">
        <el-card shadow="never">
          <el-form ref="infoForm" :model="organalForm" label-width="80px">
            <el-row>
              <el-col :span="12">
                <el-form-item label="捐献编号" prop="donorno">
                  <el-input v-model="curdonorno" disabled placeholder="请选择捐献案例" />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="姓名" prop="donorname">
                  <el-input v-model="curdonorname" disabled placeholder="请选择捐献案例" />
                </el-form-item> </el-col><el-col :span="6">
                <el-form-item label="年龄" align="center" prop="age">
                  <el-input v-model="curage" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="选择器官">
              <el-checkbox-group v-model="organalForm.organname">
                <el-checkbox v-for="dict in dict.type.sys_Organ" :key="dict.value" :label="dict.value"
                  @change="changeorganState(dict.value)">
                  {{ dict.label }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            <el-form-item label="器官分配">
              <el-table v-loading="loading" border :data="organalTableData">
                <el-table-column label="器官名称" align="center" width="90" prop="organname" />
                <el-table-column label="器官编号" align="center" width="80" prop="organno" />
                <el-table-column label="分配状态" align="center" width="90" prop="organstate">
                  <template slot-scope="scope">
                    <dict-tag :options="dict.type.sys_organstate" :value="scope.row.organstate" />
                  </template>
                </el-table-column>
                <el-table-column label="移植医院" align="center" prop="transplanthospitalname">
                </el-table-column>
                <el-table-column label="操作" width="200" align="center" class-name="small-padding fixed-width">
                  <template slot-scope="scope">
                    <el-button size="mini" v-if="scope.row.id == null" type="text" icon="el-icon-copy-document"
                      @click="distributionDialog(scope.row)">分配</el-button>
                    <el-button size="mini" v-else type="text" icon="el-icon-copy-document"
                      @click="distributionDialog(scope.row)">修改</el-button>
                    <el-button size="mini" v-if="scope.row.organstate != 99" type="text" icon="el-icon-copy-document"
                      @click="redistribution(scope.row)">重新分配</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col> -->
    </el-row>
 
    <!-- 添加或修改器官分配对话框 -->
    <el-dialog
      :title="distributionFormTitle"
      :visible.sync="showDistributionForm"
      :close-on-click-modal="false"
      width="1000px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="160px">
        <el-row>
          <el-col :span="16">
            <el-form-item label="捐献编号" prop="donorno">
              <el-input
                v-model="distributionForm.donorno"
                placeholder="请输入捐献者编号"
                disabled
              />
            </el-form-item> </el-col
          ><el-col :span="8">
            <el-form-item label="分配状态" prop="organstate">
              <el-select v-model="form.organstate" placeholder="请选择器官状态">
                <el-option
                  v-for="dict in dict.type.sys_organstate"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="捐献姓名" prop="curdonorname">
              <el-input
                v-model="curdonorname"
                placeholder="捐献者姓名"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="器官名称" prop="organnumber">
              <el-select
                ref="organNameSelect"
                v-model="form.organnumber"
                placeholder="请选择器官编号"
                clearable
                size="small"
                disabled
              >
                <el-option
                  v-for="dict in dict.type.sys_Organ"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item> </el-col
          ><el-col :span="8">
            <el-form-item label="系统编号" prop="ageunit">
              <el-input v-model="form.ageunit" placeholder="请输入系统编号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row
          ><el-col :span="8">
            <el-form-item label="接收时间" prop="applicanttime">
              <el-date-picker
                clearable
                size="small"
                style="width: 100%"
                v-model="form.applicanttime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择接收时间"
              >
              </el-date-picker>
            </el-form-item> </el-col
          ><el-col :span="16">
            <el-form-item label="移植医院" prop="treatmenthospitalno">
              <org-selecter
                ref="tranHosSelect"
                :org-type="'4'"
                v-model="form.transplanthospitalno"
                style="width: 100%"
              />
            </el-form-item> </el-col></el-row
        ><el-row>
          <el-col :span="8">
            <el-form-item label="受体姓氏" prop="name">
              <el-input v-model="form.name" placeholder="姓氏" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="证件类型" prop="idcardtype">
              <el-select
                v-model="form.idcardtype"
                placeholder="请选择移植人证件类型"
              >
                <el-option
                  v-for="dict in dict.type.sys_IDType"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item> </el-col
          ><el-col :span="8">
            <el-form-item label="证件号码" prop="idcardno">
              <el-input
                v-model="form.idcardno"
                placeholder="请输入移植人证件号码"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </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>
//这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
//例如:import 《组件名称》 from '《组件路径》';
import {
  listDonatebaseinfo
  // exportProvincemessage,
} from "@/api/project/donatebaseinfo";
import OrgSelecter from "@/views/project/components/orgselect";
 
import {
  listDonateorgan,
  addDonateorgan,
  delDonateorgan,
  getDonateorgan,
  updateDonateorgan
} from "@/api/project/donateorgan";
import {
  listOrganallocation,
  getOrganallocation,
  addOrganallocation,
  delOrganallocation,
  updateOrganallocation
} from "@/api/project/organallocation";
import Li_area_select from "@/components/Address";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {
    Li_area_select,
    OrgSelecter
  },
  name: "Organallocation",
 
  dicts: [
    "sys_Organ",
    "sys_organstate",
    "sys_user_sex",
    "sys_IDType",
    "sys_AgeUnit",
    "sys_donornode"
  ],
  data() {
    //这里存放数据
    return {
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
 
      selecttime: "",
      reportervalue: "",
      reportlist: [],
      provinceData: [
        { label: "全部", value: "" },
        { label: "杭州市", value: "1" },
        { label: "宁波市", value: "2" },
        { label: "温州市", value: "3" },
        { label: "嘉兴市", value: "4" },
        { label: "湖州市", value: "5" },
        { label: "绍兴市", value: "6" },
        { label: "金华市", value: "7" },
        { label: "衢州市", value: "8" },
        { label: "舟山市", value: "9" },
        { label: "台州市", value: "A" },
        { label: "丽水市", value: "B" }
      ],
      searchAddress: {
        sheng: "",
        shi: "",
        qu: "",
        organizationname: null
      },
 
      //搜索参数
      queryParams: {
        pageNum: 1,
        recordstate: "10",
        donorno: "",
        name: "",
        pageSize: 10,
        name: null,
        donorno: null,
        starttime: null,
        endtime: null,
        endReporttime: null,
        reportervalue: null,
        city: null
      },
 
      //当前选中捐献案例编号
      curdonorno: "",
      //当前捐献者id
      curInfoid: "",
      // 医疗结构
      treatmenthospitalno: "",
      //当前选中捐献案例姓名
      curdonorname: "",
      //当前选中捐献案例年龄
      curage: "",
 
      //捐献案例列表数据
      tempRecordState: null,
      donationCaseTableData: [],
      //选择器官表单
      organalForm: {
        //器官列表
        organname: []
      },
      //器官分配列表
      organalTableData: [],
      //
      distributionFormTitle: "器官分配",
      //
      showDistributionForm: false,
 
      defultAddress: {
        sheng: "浙江省",
        shi: "",
        qu: ""
      },
      form: {},
      rules: {
        applicanttime: [
          { required: true, message: "请输入接收时间", trigger: "blur" }
        ]
      },
      // 遮罩层
      loading: true,
      title: "",
      selectedRow: null
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  activated() {
    this.selecttime = "";
    this.reportervalue = "";
    this.reportlist = [];
    this.queryParams.donorno = "";
    this.queryParams.recordstate = "";
    this.queryParams.name = "";
    this.queryParams.treatmenthospitalno = "";
    if (this.$route.params.starttime != null && this.$route.params.endtime) {
      this.selecttime = [
        this.$moment(this.$route.params.starttime).format("YYYY-MM-DD"),
        this.$moment(this.$route.params.endtime).format("YYYY-MM-DD")
      ];
    }
    if (this.$route.params.reporterno != "") {
      this.reporterno = this.$route.params.reporterno;
    }
    if (this.$route.params.tempRecordState != "") {
      this.queryParams.recordstate = this.$route.params.tempRecordState;
    }
    if (this.$route.params.reporterno != "") {
      this.reportervalue = this.$route.params.reporterno;
    }
    if (!this.$route.params.shen != "") {
      this.searchAddress.sheng = this.$route.params.shen;
      if (!this.$route.params.shi != "") {
        this.searchAddress.shi = this.$route.params.shi;
      }
      if (!this.$route.params.qu) {
        this.searchAddress.qu = this.$route.params.qu;
      }
    }
    if (this.$route.params.city != "") {
      this.queryParams.city = this.$route.params.city;
    }
    this.getTimeList();
    this.getBaseInfoList();
  },
  mounted() {
    this.LoadReportList();
    this.tempRecordState = this.$route.params.tempRecordState;
    console.log("传来的值", this.tempRecordState);
  },
  //方法集合
  methods: {
    LoadReportList() {
      listDonatebaseinfo().then(res => {
        console.log("潜在捐献表", res);
        let list = res.rows;
        let reportlist = [];
        list.forEach(element => {
          reportlist.push({
            reporterno: element.reporterno,
            reportername: element.reportername
          });
        });
        console.log("dwada", reportlist);
        if (reportlist != 0) {
          reportlist = this.resetArr(reportlist);
          this.reportlist = reportlist;
        }
      });
    },
    resetArr(Arr) {
      var hash = {};
      Arr = Arr.reduce(function(arr, current) {
        hash[current.reporterno]
          ? ""
          : (hash[current.reporterno] = true && arr.push(current));
        return arr;
      }, []);
      return Arr;
    },
    getTimeList(e) {
      if (this.selecttime != 0) {
        this.endtime = this.selecttime[1];
        this.starttime = this.selecttime[0];
        // if (this.endtime == this.starttime) {
        let num = Number(this.endtime.slice(5, 7));
        if (num < 9) {
          let mon = Number(this.endtime.slice(6, 7));
          this.endtime =
            this.endtime.slice(0, 5) +
            "0" +
            (mon + 1) +
            "-" +
            "01" +
            " " +
            "00" +
            ":" +
            "00" +
            ":" +
            "00";
        }
        // this.endtime=this.endtime.slice(0,5)年
        else if (num >= 10) {
          this.endtime =
            this.endtime.slice(0, 5) +
            (num + 1) +
            "-" +
            "01" +
            " " +
            "00" +
            ":" +
            "00" +
            ":" +
            "00";
        } else {
          this.endtime =
            this.endtime.slice(0, 5) +
            "10" +
            "-" +
            "01" +
            " " +
            "00" +
            ":" +
            "00" +
            ":" +
            "00";
          console.log("1212121", this.endtime);
        }
        this.starttime = this.starttime + " " + "00" + ":" + "00" + ":" + "00";
        //}
      } else {
        this.starttime = "1998-01-01 00:00:00";
        this.endtime = "2998-01-01 00:00:00";
      }
    },
 
    //重新分配
    redistribution(data) {
      console.log("重新分配", data);
      //弹窗
      this.showDistributionForm = true;
      this.reset();
 
      getDonateorgan(data.id).then(res => {
        let obj = res.data;
        obj.organstate = 99;
        updateDonateorgan(obj).then(res => {
          // if(res.code === 200){
          this.form.organstate = data.organstate;
          this.form.organno = data.organno;
          this.form.organnumber = data.organno;
 
          let loactionSearcParam = {
            organid: data.id
          };
 
          listOrganallocation(loactionSearcParam).then(res => {
            if (res.rows != 0) {
              let list = res.rows[0];
              // this.form.ageunit = list.ageunit;
              this.form.applicanttime = list.applicanttime;
              // this.form.treatmenthospitalno = list.treatmenthospitalno;
              // this.form.transplanthospitalname = list.transplanthospitalname
            }
          });
          console.log("Organallocation", this.form);
        });
      });
    },
 
    /** 查询捐献基础列表 */
    getBaseInfoList(e) {
      this.loading = true;
      sessionStorage.removeItem("organallocation");
      sessionStorage.setItem(
        "organallocation",
        JSON.stringify(this.queryParams)
      );
      if (this.queryParams.recordstate == "") {
        this.queryParams.recordstate = null;
      }
      if (e != null && e != undefined && !isNaN(e)) {
        this.queryParams.recordstate = e;
      }
 
      this.queryParams.reportervalue = this.reportervalue;
      console.log(JSON.stringify(this.queryParams));
      // this.queryParams.city='001'
      //console.log(JSON.stringify(this.queryParams));
      if (this.starttime != "") {
        this.queryParams.starttime = this.starttime;
      }
      if (this.endtime != "") {
        this.queryParams.endtime = this.endtime;
      }
 
      this.$nextTick(() => {
        // this.queryParams.residenceprovince = this.$refs.areaSelect.getSheng();
        // this.queryParams.residencecity = this.$refs.areaSelect.getShi();
        // this.queryParams.residencetown = this.$refs.areaSelect.getQu();
        listDonatebaseinfo(this.queryParams).then(response => {
          this.donationCaseTableData = response.rows;
          console.log(this.donationCaseTableData, "Donation");
          this.total = response.total;
          this.loading = false;
        });
      });
    },
 
    /** 重置按钮操作 */
    resetQuery() {
      this.reportervalue = "";
 
      this.queryParams = {
        doname: null,
        pageNum: 1,
        pageSize: 10,
        name: null,
        idcardno: null,
        residenceprovince: null,
        residencecity: null,
        residencetown: null,
        // "2"
        recordstate: null,
        treatmenthospitalname: null,
        donorno: null,
        acquisitiontissueno: null,
        reportername: null,
        reporttime: null,
        city: null,
        treatmenthospitalno: null
      };
      this.selecttime = [];
      this.getTimeList();
      this.searchAddress = {
        sheng: "",
        shi: "",
        qu: "",
        organizationname: null
      };
      //this.$refs.areaSelect.clean();
 
      this.getBaseInfoList();
    },
 
    //监听器官多选框事件
    changeSelectOrgan() {
      this.organalTableData = [];
      for (let i = 0; i < this.dict.type.sys_Organ.length; i++) {
        for (let k = 0; k < this.organalForm.organname.length; k++) {
          if (
            this.organalForm.organname[k] == this.dict.type.sys_Organ[i].value
          ) {
            this.organalTableData.push({
              organname: this.dict.type.sys_Organ[i].label,
              organno: this.dict.type.sys_Organ[i].value,
              id: null
            });
          }
        }
      }
    },
    //修改和分配
    distributionDialog(data) {
      console.log("修改和分配数据", data);
      this.reset();
      this.form = data;
      if (
        this.curdonorname == "" ||
        this.curdonorno == "" ||
        this.infoid == ""
      ) {
        this.$modal.msgWarning("请先选择一个捐献案例,再进行录入器官分配!");
        return;
      }
      if (data.id != null) {
        //搜索器官分配记录
        let loactionSearcParam = {
          organid: data.id
        };
        this.showDistributionForm = true;
        listOrganallocation(loactionSearcParam).then(response => {
          if (response.rows.length == 1) {
            let resData = response.rows[0];
            resData.organstate = data.organstate;
            resData.transplanthospitalno = data.transplanthospitalno;
            this.form = { ...resData };
            // this.form.organnumber = data.organno;
 
            this.showDistributionForm = true;
            this.$forceUpdate();
          }
        });
      } else {
        this.form.organnumber = data.organno;
        // this.distributionForm.organname = data.organname;
        // this.distributionForm.organno = data.organno;
        this.showDistributionForm = true;
      }
    },
    // 取消按钮
    cancel() {
      this.showDistributionForm = false;
    },
    //点击捐献案例列表触发方法
    selectDonotor(row, column, event) {
      this.$router.push({
        path: "/organ/donationdetails/",
        query: {
          id: row.id,
          organType: "edit"
        }
      });
      // this.selectedRow = row;
      // this.curdonorno = row.donorno;
      // this.curdonorname = row.name;
      // this.curage = row.age;
      // this.curInfoid = row.id;
      // this.distributionForm.donorno = row.donorno;
      // this.GetDonortedList();
    },
    //获取病人已捐献的器官列表
    GetDonortedList() {
      this.loading = true;
      let oraganqueryParam = {
        infoid: this.curInfoid
      };
      // donorno: this.curdonorno,
      listDonateorgan(oraganqueryParam).then(response => {
        this.loading = false;
        if (response.code == 200) {
          this.organalTableData = [];
          this.organalForm.organname = [];
          for (let i = 0; i < response.rows.length; i++) {
            this.organalForm.organname.push(response.rows[i].organno);
            this.organalTableData.push({
              id: response.rows[i].id,
              organno: response.rows[i].organno,
              organname: response.rows[i].organname,
              transplanthospitalno: response.rows[i].transplanthospitalno,
              transplanthospitalname: response.rows[i].transplanthospitalname,
              organstate: response.rows[i].organstate
            });
          }
        } else {
          this.$modal.msgError("获取捐献器官失败:" + response.msg);
        }
      });
    },
    //提交表单
 
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            //更新捐献器官表
            this.form.allocationstatus = this.form.organstate;
            updateOrganallocation(this.form).then(response => {});
            //获取器官信息
            getDonateorgan(this.form.organid).then(response2 => {
              let organData = response2.data;
              (organData.organname = this.$refs.organNameSelect.selectedLabel),
                (organData.organstate = this.form.allocationstatus);
              organData.transplantdoct = this.form.transplantdoct;
 
              organData.transplanthospitalno = this.form.transplanthospitalno;
              try {
                organData.transplanthospitalname = this.$refs.tranHosSelect.getOptionByValue(
                  organData.transplanthospitalno
                ).organizationname;
              } catch {
                organData.transplanthospitalname =
                  organData.transplanthospitalno;
              }
              //更新捐献器官表
              updateDonateorgan(organData).then(response3 => {
                this.$modal.msgSuccess("修改器官信息成功");
                this.GetDonortedList();
                this.showDistributionForm = false;
              });
            });
          } else {
            //保存时先保存到捐献器官表
            //新增到器官管理表
            this.loading = false;
            let organaManageForm = {
              donorno: this.curdonorno,
              donorname: this.curdonorname,
              organname: this.$refs.organNameSelect.selectedLabel,
              organno: this.form.organnumber,
              infoid: this.curInfoid,
              organstate: this.form.organstate,
              transplanthospitalno: this.form.transplanthospitalno,
              transplanthospitalname: null,
              transplantdoct: this.form.transplantdoct
            };
            try {
              organaManageForm.transplanthospitalname = this.$refs.tranHosSelect.getOptionByValue(
                organaManageForm.transplanthospitalno
              ).organizationname;
            } catch {
              organaManageForm.transplanthospitalname =
                organaManageForm.transplanthospitalno;
            }
 
            addDonateorgan(organaManageForm).then(response => {
              this.loading = false;
              if (response.code === 200) {
                //查询获取新增的器官表id
                let organSearchParam = {
                  infoid: this.curInfoid,
                  // donorno: this.curdonorno,
                  organno: this.form.organnumber
                  //donorname: this.curdonorname,
                  //organname: this.$refs.organNameSelect.label,
                };
 
                listDonateorgan(organSearchParam).then(response2 => {
                  if (response2.code == 200 && response2.rows.length > 0) {
                    for (let i = 0; i < response2.rows.length; i++) {
                      if (response2.rows[i].organstate == "2") {
                        this.form.organid = response2.rows[i].id;
                        // this.form.residenceprovincename = this.defultAddress.sheng;
                        // this.form.residencecityname = this.defultAddress.shi;
                        // this.form.residencetownname = this.defultAddress.qu;
 
                        addOrganallocation(this.form).then(response => {
                          this.$modal.msgSuccess("捐献器官分配信息保存成功!");
                        });
                      }
                    }
                  }
                  this.GetDonortedList();
                  this.showDistributionForm = false;
                });
              }
            });
          }
        }
      });
    },
 
    //重置表单
    resetForm() {
      this.distributionForm = {
        id: null,
        organid: null,
        organnumber: null,
        applicantuserid: null,
        applicantusername: null,
        applicanttime: null,
        checkuserid: null,
        checkusername: null,
        checktime: null,
        checksuggestion: null,
        allocationstatus: null,
        name: null,
        sex: null,
        idcardtype: null,
        idcardno: null,
        age: null,
        ageunit: null,
        birthday: null,
        phone: null,
        residenceaddress: null,
        residenceprovince: null,
        residenceprovincename: null,
        residencecity: null,
        residencecityname: null,
        residencetown: null,
        residencetownname: null,
        residencecommunity: null,
        residencecommunityname: null,
        residencecountycode: null,
        residencecountyname: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        //移植医院
        transplanthospitalno: null,
        transplanthospitalname: null
      };
      this.distributionForm.donorno = this.curdonorno;
    },
    reset() {
      this.form = {
        id: null,
        organid: null,
        organnumber: null,
        applicantuserid: null,
        applicantusername: null,
        applicanttime: null,
        checkuserid: null,
        checkusername: null,
        checktime: null,
        checksuggestion: null,
        allocationstatus: 2,
        name: null,
        sex: null,
        idcardtype: null,
        idcardno: null,
        age: null,
        ageunit: null,
        birthday: null,
        phone: null,
        residenceaddress: null,
        residenceprovince: null,
        residenceprovincename: null,
        residencecity: null,
        residencecityname: null,
        residencetown: null,
        residencetownname: null,
        residencecommunity: null,
        residencecommunityname: null,
        residencecountycode: null,
        residencecountyname: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        transplanthospitalno: null,
        organstate: null
      };
      this.resetForm("form");
    },
    //修改器官捐献记录
    changeorganState(value) {
      //organalTableData
      let organIndex = this.organalTableData.findIndex(
        item => item.organno == value
      );
      //判断当前选中值是否在数组中
      if (organIndex == -1) {
        //获取器官名称
        let temporganname = "";
        for (let i = 0; i < this.dict.type.sys_Organ.length; i++) {
          if (value == this.dict.type.sys_Organ[i].value) {
            temporganname = this.dict.type.sys_Organ[i].label;
            break;
          }
        }
        if (temporganname != "") {
          this.organalTableData.push({
            organname: temporganname,
            organno: value,
            id: null,
            transplanthospitalname: null,
            transplanthospitalno: null,
            organstate: "2"
          });
        }
      } else {
        this.$confirm("是否确认删除器官分配记录", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            if (organIndex != -1) {
              let tempOrgan = this.organalTableData[organIndex];
              if (tempOrgan.organstate != 1 && tempOrgan.id > 0) {
                this.$modal.msgWarning("只有未分配器官可进行删除!");
                this.organalForm.organname.push(value);
                return;
              }
              if (tempOrgan.id > 0) {
                //查找器官表记录,判断器官状态
                this.loading = true;
                delDonateorgan(tempOrgan.id).then(delLocationRes => {
                  //调用删除器官记录api
                  // delDonateorgan(searchedOrganData.id).then(
                  //   (delOrganRes) => {
                  //   }
                  // );
                  this.loading = false;
                  this.$modal.msgSuccess("删除成功");
                  this.selectDonotor(this.selectedRow);
                });
              } else {
                this.organalTableData.splice(deleteIndex, 1);
                this.selectDonotor(this.selectedRow);
              }
            }
          })
          .catch(() => {
            this.selectDonotor(this.selectedRow);
          });
      }
    }
  },
  //生命周期 - 创建完成(可以访问当前this实例)
  created() {
    if (sessionStorage.getItem("organallocation")) {
      this.queryParams = JSON.parse(sessionStorage.getItem("organallocation"));
      console.log(this.queryParams, "queryParams");
    }
    this.getBaseInfoList();
    this.resetForm();
  }
  //生命周期 - 挂载完成(可以访问DOM元素)
  // mounted() {},
  // beforeCreate() {}, //生命周期 - 创建之前
  // beforeMount() {}, //生命周期 - 挂载之前
  // beforeUpdate() {}, //生命周期 - 更新之前
  // updated() {}, //生命周期 - 更新之后
  // beforeDestroy() {}, //生命周期 - 销毁之前
  // destroyed() {}, //生命周期 - 销毁完成
  // activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
};
</script>
<style lang="scss" scoped>
//@import url(); 引入公共css类
</style>