Browse Source

院区管理增加父子院区

seimin 1 year ago
parent
commit
ace39bf2b8

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

@@ -1,6 +1,7 @@
1
 <div class="list-template">
1
 <div class="list-template">
2
   <div class="list-template__content">
2
   <div class="list-template__content">
3
     <div *ngIf="currentUserAccount == 'dsadmin'" class="list-template__top">
3
     <div *ngIf="currentUserAccount == 'dsadmin'" class="list-template__top">
4
+    <!-- <div class="list-template__top"> -->
4
       <div nz-col nzXl="18" class="list-template__searchBox"></div>
5
       <div nz-col nzXl="18" class="list-template__searchBox"></div>
5
       <div nz-col nzXl="6" class="list-template__btns">
6
       <div nz-col nzXl="6" class="list-template__btns">
6
         <button nz-button class="btn default" (click)="addModal()">新增</button>
7
         <button nz-button class="btn default" (click)="addModal()">新增</button>
@@ -79,6 +80,27 @@
79
               [nzSm]="6"
80
               [nzSm]="6"
80
               [nzXs]="24"
81
               [nzXs]="24"
81
               nzRequired
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
               nzFor="hospitalName"
104
               nzFor="hospitalName"
83
               >院区名称</nz-form-label
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
 import { MainService } from "../../services/main.service";
10
 import { MainService } from "../../services/main.service";
11
 import { ToolService } from "src/app/services/tool.service";
11
 import { ToolService } from "src/app/services/tool.service";
12
+import { Subject } from 'rxjs';
13
+import { debounceTime } from 'rxjs/operators';
12
 
14
 
13
 @Component({
15
 @Component({
14
   selector: "app-hospital-management",
16
   selector: "app-hospital-management",
@@ -24,6 +26,14 @@ export class HospitalManagementComponent implements OnInit {
24
   ) {}
26
   ) {}
25
 
27
 
26
   ngOnInit() {
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
     this.coopBtns = this.tool.initCoopBtns(this.route);
37
     this.coopBtns = this.tool.initCoopBtns(this.route);
28
     this.getList();
38
     this.getList();
29
     this.initForm();
39
     this.initForm();
@@ -51,6 +61,42 @@ export class HospitalManagementComponent implements OnInit {
51
 
61
 
52
   // 初始化增删改按钮
62
   // 初始化增删改按钮
53
   coopBtns: any = {};
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
   loading1 = false;
102
   loading1 = false;
@@ -72,6 +118,7 @@ export class HospitalManagementComponent implements OnInit {
72
   addModal() {
118
   addModal() {
73
     this.add = true;
119
     this.add = true;
74
     this.modal = true;
120
     this.modal = true;
121
+    this.validateForm.controls.parentHospital.setValue("");
75
     this.validateForm.controls.hospitalName.setValue("");
122
     this.validateForm.controls.hospitalName.setValue("");
76
     this.validateForm.controls.hospitalNum.setValue("");
123
     this.validateForm.controls.hospitalNum.setValue("");
77
   }
124
   }
@@ -123,6 +170,7 @@ export class HospitalManagementComponent implements OnInit {
123
   // 初始化新增form表单
170
   // 初始化新增form表单
124
   initForm() {
171
   initForm() {
125
     this.validateForm = this.fb.group({
172
     this.validateForm = this.fb.group({
173
+      parentHospital: [null],
126
       hospitalName: [null, [Validators.required]],
174
       hospitalName: [null, [Validators.required]],
127
       hospitalNum: [null, [Validators.required]],
175
       hospitalNum: [null, [Validators.required]],
128
     });
176
     });
@@ -137,12 +185,15 @@ export class HospitalManagementComponent implements OnInit {
137
     }
185
     }
138
     if (that.validateForm.invalid) return;
186
     if (that.validateForm.invalid) return;
139
     that.btnLoading = true;
187
     that.btnLoading = true;
140
-    let data = {
188
+    let data: any = {
141
       hospital: {
189
       hospital: {
142
         hosName: that.validateForm.value.hospitalName,
190
         hosName: that.validateForm.value.hospitalName,
143
         hosNo: that.validateForm.value.hospitalNum,
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
     if (!that.add) {
197
     if (!that.add) {
147
       data.hospital["id"] = that.coopId;
198
       data.hospital["id"] = that.coopId;
148
     }
199
     }
@@ -165,6 +216,14 @@ export class HospitalManagementComponent implements OnInit {
165
     this.add = false;
216
     this.add = false;
166
     this.modal = true;
217
     this.modal = true;
167
     this.coopId = data.id;
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
     this.validateForm.controls.hospitalName.setValue(data.hosName);
227
     this.validateForm.controls.hospitalName.setValue(data.hosName);
169
     this.validateForm.controls.hospitalNum.setValue(data.hosNo);
228
     this.validateForm.controls.hospitalNum.setValue(data.hosNo);
170
   }
229
   }