Explorar el Código

院区管理增加父子院区

seimin hace 1 año
padre
commit
ace39bf2b8

+ 22 - 0
src/app/views/hospital-management/hospital-management.component.html

@@ -1,6 +1,7 @@
1 1
 <div class="list-template">
2 2
   <div class="list-template__content">
3 3
     <div *ngIf="currentUserAccount == 'dsadmin'" class="list-template__top">
4
+    <!-- <div class="list-template__top"> -->
4 5
       <div nz-col nzXl="18" class="list-template__searchBox"></div>
5 6
       <div nz-col nzXl="6" class="list-template__btns">
6 7
         <button nz-button class="btn default" (click)="addModal()">新增</button>
@@ -79,6 +80,27 @@
79 80
               [nzSm]="6"
80 81
               [nzXs]="24"
81 82
               nzRequired
83
+              nzFor="parentHospital"
84
+              >父级院区</nz-form-label
85
+            >
86
+            <nz-form-control nzErrorTip="请选择父级院区!">
87
+              <nz-select formControlName="parentHospital" [nzDropdownMatchSelectWidth]="false" nzPlaceHolder="请选择父级院区" nzShowSearch nzAllowClear nzServerSearch (nzOnSearch)="changeInp($event)"
88
+              (nzOpenChange)="openHospitalSelect($event)">
89
+                <ng-container *ngFor="let option of parentHospitals">
90
+                  <nz-option *ngIf="!isLoading" [nzLabel]="option.hosName" [nzValue]="option.id"></nz-option>
91
+                </ng-container>
92
+                <nz-option *ngIf="isLoading" nzDisabled nzCustomContent>
93
+                  <i nz-icon nzType="loading" class="loading-icon"></i>
94
+                  搜索中...
95
+                </nz-option>
96
+              </nz-select>
97
+            </nz-form-control>
98
+          </nz-form-item>
99
+          <nz-form-item>
100
+            <nz-form-label
101
+              [nzSm]="6"
102
+              [nzXs]="24"
103
+              nzRequired
82 104
               nzFor="hospitalName"
83 105
               >院区名称</nz-form-label
84 106
             >

+ 60 - 1
src/app/views/hospital-management/hospital-management.component.ts

@@ -9,6 +9,8 @@ import { ActivatedRoute } from "@angular/router";
9 9
 
10 10
 import { MainService } from "../../services/main.service";
11 11
 import { ToolService } from "src/app/services/tool.service";
12
+import { Subject } from 'rxjs';
13
+import { debounceTime } from 'rxjs/operators';
12 14
 
13 15
 @Component({
14 16
   selector: "app-hospital-management",
@@ -24,6 +26,14 @@ export class HospitalManagementComponent implements OnInit {
24 26
   ) {}
25 27
 
26 28
   ngOnInit() {
29
+    this.searchParentHospitalSubject.pipe(debounceTime(500)).subscribe((v: any) => {
30
+      this.getAllParentHospital(v).subscribe((result) => {
31
+        this.isLoading = false;
32
+        if (result.status == 200) {
33
+          this.parentHospitals = result.list;
34
+        }
35
+      });
36
+    });
27 37
     this.coopBtns = this.tool.initCoopBtns(this.route);
28 38
     this.getList();
29 39
     this.initForm();
@@ -51,6 +61,42 @@ export class HospitalManagementComponent implements OnInit {
51 61
 
52 62
   // 初始化增删改按钮
53 63
   coopBtns: any = {};
64
+  //所有院区
65
+  parentHospitals: any = [];
66
+  searchParentHospitalSubject = new Subject();
67
+  //搜索父级院区
68
+  changeInp(e) {
69
+    this.isLoading = true;
70
+    this.searchParentHospitalSubject.next(e);
71
+  }
72
+  // 打开父级科室下拉框
73
+  isLoading = false;
74
+  openHospitalSelect(flag) {
75
+    if (flag) {
76
+      this.isLoading = true;
77
+      this.getAllParentHospital().subscribe((result) => {
78
+        this.isLoading = false;
79
+        if (result.status == 200) {
80
+          this.parentHospitals = result.list;
81
+        }
82
+      });
83
+    }
84
+  }
85
+  //获取所有的父级院区列表
86
+  getAllParentHospital(keyWord = "") {
87
+    let postData: any = {
88
+      idx: 0,
89
+      sum: 10,
90
+      hospital: {
91
+        keyWord: keyWord,
92
+      },
93
+    };
94
+    if (this.coopId) {
95
+      // 过滤这个院区及其子院区
96
+      postData.hospital.filterByDeptId = this.coopId;
97
+    }
98
+    return this.mainService.getFetchDataList("data", "hospital", postData);
99
+  }
54 100
 
55 101
   // 表格数据
56 102
   loading1 = false;
@@ -72,6 +118,7 @@ export class HospitalManagementComponent implements OnInit {
72 118
   addModal() {
73 119
     this.add = true;
74 120
     this.modal = true;
121
+    this.validateForm.controls.parentHospital.setValue("");
75 122
     this.validateForm.controls.hospitalName.setValue("");
76 123
     this.validateForm.controls.hospitalNum.setValue("");
77 124
   }
@@ -123,6 +170,7 @@ export class HospitalManagementComponent implements OnInit {
123 170
   // 初始化新增form表单
124 171
   initForm() {
125 172
     this.validateForm = this.fb.group({
173
+      parentHospital: [null],
126 174
       hospitalName: [null, [Validators.required]],
127 175
       hospitalNum: [null, [Validators.required]],
128 176
     });
@@ -137,12 +185,15 @@ export class HospitalManagementComponent implements OnInit {
137 185
     }
138 186
     if (that.validateForm.invalid) return;
139 187
     that.btnLoading = true;
140
-    let data = {
188
+    let data: any = {
141 189
       hospital: {
142 190
         hosName: that.validateForm.value.hospitalName,
143 191
         hosNo: that.validateForm.value.hospitalNum,
144 192
       },
145 193
     };
194
+    if (this.validateForm.value.parentHospital) {
195
+      data.hospital.parent = { id: this.validateForm.value.parentHospital };
196
+    }
146 197
     if (!that.add) {
147 198
       data.hospital["id"] = that.coopId;
148 199
     }
@@ -165,6 +216,14 @@ export class HospitalManagementComponent implements OnInit {
165 216
     this.add = false;
166 217
     this.modal = true;
167 218
     this.coopId = data.id;
219
+    if (data.parent) {
220
+      this.getAllParentHospital(data.parent.dept).subscribe((res) => {
221
+        if (res.status == 200) {
222
+          this.parentHospitals = res.list;
223
+          this.validateForm.controls.parentHospital.setValue(data.parent.id);
224
+        }
225
+      });
226
+    }
168 227
     this.validateForm.controls.hospitalName.setValue(data.hosName);
169 228
     this.validateForm.controls.hospitalNum.setValue(data.hosNo);
170 229
   }