|
@@ -0,0 +1,415 @@
|
|
1
|
+import { Component, OnInit, ViewChild } from "@angular/core";
|
|
2
|
+import { ActivatedRoute } from "@angular/router";
|
|
3
|
+import { FormBuilder, Validators, FormGroup } from "@angular/forms";
|
|
4
|
+import { NzMessageService } from "ng-zorro-antd/message";
|
|
5
|
+
|
|
6
|
+import { MainService } from "../../services/main.service";
|
|
7
|
+import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
|
|
8
|
+import { ToolService } from "../../services/tool.service";
|
|
9
|
+import { GenerateFloorComponent } from "src/app/share/generate-floor/generate-floor.component";
|
|
10
|
+
|
|
11
|
+@Component({
|
|
12
|
+ selector: "app-building-floor",
|
|
13
|
+ templateUrl: "./building-floor.component.html",
|
|
14
|
+ styleUrls: ["./building-floor.component.less"],
|
|
15
|
+})
|
|
16
|
+export class BuildingFloorComponent implements OnInit {
|
|
17
|
+ tableHeight;
|
|
18
|
+
|
|
19
|
+ constructor(
|
|
20
|
+ private fb: FormBuilder,
|
|
21
|
+ private route: ActivatedRoute,
|
|
22
|
+ private mainService: MainService,
|
|
23
|
+ private msg: NzMessageService,
|
|
24
|
+ private tool: ToolService
|
|
25
|
+ ) {}
|
|
26
|
+ @ViewChild("osComponentRef1", {
|
|
27
|
+ read: OverlayScrollbarsComponent,
|
|
28
|
+ static: false,
|
|
29
|
+ })
|
|
30
|
+ osComponentRef1: OverlayScrollbarsComponent;
|
|
31
|
+ @ViewChild(GenerateFloorComponent, { static: false })
|
|
32
|
+ generate1: GenerateFloorComponent;
|
|
33
|
+ ngOnInit() {
|
|
34
|
+ this.coopBtns = this.tool.initCoopBtns(this.route);
|
|
35
|
+ console.log(this.coopBtns);
|
|
36
|
+ this.initForm();
|
|
37
|
+ this.initFormFloor();
|
|
38
|
+ this.getHospitalList();
|
|
39
|
+ this.getBuildingList();
|
|
40
|
+ this.tableHeight = document.body.clientHeight - 267;
|
|
41
|
+ }
|
|
42
|
+ isAllDisplayDataChecked = false;
|
|
43
|
+ isIndeterminate = false;
|
|
44
|
+ listOfDisplayData: any[] = [];
|
|
45
|
+ allFloorList: any[] = []; //当前选中的楼栋包含的所有楼层
|
|
46
|
+ mapOfCheckedId: { [key: string]: boolean } = {};
|
|
47
|
+ checkedBuilding: any = {}; //选中楼栋
|
|
48
|
+ buildingList: Array<any> = []; //楼栋信息
|
|
49
|
+ hospitalList: Array<any> = []; //院区列表
|
|
50
|
+ hosId: any; //当前选择的院区id
|
|
51
|
+
|
|
52
|
+ promptContent: string; //操作提示框提示信息
|
|
53
|
+ ifSuccess: boolean; //操作成功/失败
|
|
54
|
+ promptInfo: string; //操作结果提示信息
|
|
55
|
+ promptModalShow: boolean; //是否展示提示框
|
|
56
|
+
|
|
57
|
+ btnLoading: boolean = false; //确认按钮loading状态
|
|
58
|
+ saveLoading: boolean = false; //批量打印按钮loading状态
|
|
59
|
+
|
|
60
|
+ // 初始化增删改按钮
|
|
61
|
+ coopBtns: any = {};
|
|
62
|
+
|
|
63
|
+ // 分组列表
|
|
64
|
+ loading1 = false;
|
|
65
|
+ getBuildingList() {
|
|
66
|
+ let postData = {
|
|
67
|
+ idx: 0,
|
|
68
|
+ sum: 9999,
|
|
69
|
+ building: { hosId: this.hosId },
|
|
70
|
+ };
|
|
71
|
+ this.loading1 = true;
|
|
72
|
+ this.mainService
|
|
73
|
+ .getFetchDataList("simple/data", "building", postData)
|
|
74
|
+ .subscribe((result) => {
|
|
75
|
+ this.loading1 = false;
|
|
76
|
+ if (result.status == 200) {
|
|
77
|
+ this.buildingList = result.list;
|
|
78
|
+ if (Object.keys(this.checkedBuilding).length) {
|
|
79
|
+ result.list.forEach((item) => {
|
|
80
|
+ if (item.id == this.checkedBuilding.id) {
|
|
81
|
+ this.checkGroup(item);
|
|
82
|
+ }
|
|
83
|
+ });
|
|
84
|
+ } else {
|
|
85
|
+ this.checkGroup(result.list[0]);
|
|
86
|
+ }
|
|
87
|
+ }
|
|
88
|
+ });
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+ // 获取选中楼栋下楼层列表
|
|
92
|
+ loading2 = false;
|
|
93
|
+ allUsers = [];
|
|
94
|
+ getAllFloor() {
|
|
95
|
+ // 初始化的时候搜索一次,然后前端过滤
|
|
96
|
+ let postData = {
|
|
97
|
+ idx: 0,
|
|
98
|
+ sum: 9999,
|
|
99
|
+ floor: { hosId: this.hosId, buildId: this.checkedBuilding.id },
|
|
100
|
+ };
|
|
101
|
+ this.loading2 = true;
|
|
102
|
+ this.mainService
|
|
103
|
+ .getFetchDataList("simple/data", "floor", postData)
|
|
104
|
+ .subscribe((result) => {
|
|
105
|
+ this.loading2 = false;
|
|
106
|
+ if (result.status == 200) {
|
|
107
|
+ this.allFloorList = result.list;
|
|
108
|
+ this.allUsers = JSON.parse(JSON.stringify(result.list));
|
|
109
|
+ this.refreshStatus(true);
|
|
110
|
+ }
|
|
111
|
+ });
|
|
112
|
+ }
|
|
113
|
+
|
|
114
|
+ // 院区列表
|
|
115
|
+ getHospitalList() {
|
|
116
|
+ this.hosId = this.tool.getCurrentHospital().id;
|
|
117
|
+ this.hospitalList = [this.tool.getCurrentHospital()];
|
|
118
|
+ }
|
|
119
|
+ // 选中分组
|
|
120
|
+ positionY = 0; //记录其他建单Y轴滚动距离
|
|
121
|
+ checkGroup(data) {
|
|
122
|
+ this.positionY = this.osComponentRef1.osInstance().scroll().position.y; //内容滚动的距离
|
|
123
|
+ this.checkedBuilding = data;
|
|
124
|
+ this.mapOfCheckedId = {};
|
|
125
|
+ this.getAllFloor();
|
|
126
|
+ }
|
|
127
|
+ selectedUser(data) {
|
|
128
|
+ this.mapOfCheckedId[data.id] = !this.mapOfCheckedId[data.id];
|
|
129
|
+ this.refreshStatus();
|
|
130
|
+ }
|
|
131
|
+ // 选中列表中当前分组用户
|
|
132
|
+ usersArr = [];
|
|
133
|
+ refreshStatus(first?): void {
|
|
134
|
+ let arr = [];
|
|
135
|
+ for (var m in this.mapOfCheckedId) {
|
|
136
|
+ if (this.mapOfCheckedId[m]) {
|
|
137
|
+ arr.push({ id: m });
|
|
138
|
+ }
|
|
139
|
+ }
|
|
140
|
+ this.usersArr = arr;
|
|
141
|
+ }
|
|
142
|
+
|
|
143
|
+ // 新增/编辑楼栋模态框
|
|
144
|
+ coopModal: boolean = false; //模态框是否展示
|
|
145
|
+ add: boolean = true; //true:新增;false:编辑
|
|
146
|
+ showCoopModal(type) {
|
|
147
|
+ this.coopModal = true;
|
|
148
|
+ this.add = type == "add";
|
|
149
|
+ if (type == "edit") {
|
|
150
|
+ this.validateForm.controls.buildingName.setValue(
|
|
151
|
+ this.checkedBuilding["buildingName"]
|
|
152
|
+ );
|
|
153
|
+ } else {
|
|
154
|
+ this.validateForm.controls.buildingName.setValue(null);
|
|
155
|
+ }
|
|
156
|
+ }
|
|
157
|
+ // 新增/编辑楼层模态框
|
|
158
|
+ floorModal: boolean = false; //模态框是否展示
|
|
159
|
+ addFloor: boolean = true; //true:新增;false:编辑
|
|
160
|
+ floorDataEdit; //正在编辑的楼层
|
|
161
|
+ showFloorModal(e, type, data?) {
|
|
162
|
+ this.floorModal = true;
|
|
163
|
+ this.addFloor = type == "add";
|
|
164
|
+ if (type == "edit") {
|
|
165
|
+ this.floorDataEdit = data;
|
|
166
|
+ this.validateFloorForm.controls.buildId.setValue(data.buildId);
|
|
167
|
+ this.validateFloorForm.controls.floorName.setValue(data.floorName);
|
|
168
|
+ } else {
|
|
169
|
+ this.validateFloorForm.controls.buildId.setValue(this.checkedBuilding.id);
|
|
170
|
+ this.validateFloorForm.controls.floorName.setValue(null);
|
|
171
|
+ }
|
|
172
|
+ e.stopPropagation();
|
|
173
|
+ }
|
|
174
|
+ // 隐藏楼栋模态框
|
|
175
|
+ hideCoopModal() {
|
|
176
|
+ this.coopModal = false;
|
|
177
|
+ }
|
|
178
|
+ // 隐藏楼层模态框
|
|
179
|
+ hideFloorModal() {
|
|
180
|
+ this.floorModal = false;
|
|
181
|
+ }
|
|
182
|
+
|
|
183
|
+ // 初始化新增form表单
|
|
184
|
+ initForm() {
|
|
185
|
+ this.validateForm = this.fb.group({
|
|
186
|
+ buildingName: [null, [Validators.required]],
|
|
187
|
+ });
|
|
188
|
+ }
|
|
189
|
+ // 初始化新增form表单floor
|
|
190
|
+ validateFloorForm: FormGroup;
|
|
191
|
+ initFormFloor() {
|
|
192
|
+ this.validateFloorForm = this.fb.group({
|
|
193
|
+ buildId: [null, [Validators.required]],
|
|
194
|
+ floorName: [null, [Validators.required]],
|
|
195
|
+ });
|
|
196
|
+ }
|
|
197
|
+
|
|
198
|
+ // 新增/编辑楼栋提交
|
|
199
|
+ validateForm: FormGroup;
|
|
200
|
+ submitForm(): void {
|
|
201
|
+ for (const i in this.validateForm.controls) {
|
|
202
|
+ this.validateForm.controls[i].markAsDirty();
|
|
203
|
+ this.validateForm.controls[i].updateValueAndValidity();
|
|
204
|
+ }
|
|
205
|
+ if (this.validateForm.invalid) return;
|
|
206
|
+ this.btnLoading = true;
|
|
207
|
+ let postData;
|
|
208
|
+ if (this.add) {
|
|
209
|
+ let arr = this.buildingList.filter(
|
|
210
|
+ (item) => item.buildingName == this.validateForm.value.buildingName
|
|
211
|
+ );
|
|
212
|
+ //有重复名称
|
|
213
|
+ if (arr.length > 0) {
|
|
214
|
+ this.btnLoading = false;
|
|
215
|
+ this.showPromptModal(
|
|
216
|
+ "新增",
|
|
217
|
+ false,
|
|
218
|
+ `存在重复的楼栋名称【${this.validateForm.value.buildingName}】请修改后再保存!`
|
|
219
|
+ );
|
|
220
|
+ return;
|
|
221
|
+ }
|
|
222
|
+ postData = {
|
|
223
|
+ buildingName: this.validateForm.value.buildingName,
|
|
224
|
+ deleted: false,
|
|
225
|
+ hosId: this.hosId,
|
|
226
|
+ };
|
|
227
|
+ } else {
|
|
228
|
+ postData = {
|
|
229
|
+ buildingName: this.validateForm.value.buildingName,
|
|
230
|
+ deleted: false,
|
|
231
|
+ hosId: this.hosId,
|
|
232
|
+ id: this.checkedBuilding.id,
|
|
233
|
+ };
|
|
234
|
+ }
|
|
235
|
+ this.mainService
|
|
236
|
+ .simplePost("addData", "building", postData)
|
|
237
|
+ .subscribe((result) => {
|
|
238
|
+ this.hideCoopModal();
|
|
239
|
+ this.btnLoading = false;
|
|
240
|
+ if (result["status"] == 200) {
|
|
241
|
+ this.showPromptModal(this.add ? "新增" : "编辑", true, "");
|
|
242
|
+ } else {
|
|
243
|
+ this.showPromptModal(
|
|
244
|
+ this.add ? "新增" : "编辑",
|
|
245
|
+ false,
|
|
246
|
+ result["msg"]
|
|
247
|
+ );
|
|
248
|
+ }
|
|
249
|
+ });
|
|
250
|
+ }
|
|
251
|
+ // 新增/编辑楼层提交
|
|
252
|
+ submitFormFloor(): void {
|
|
253
|
+ for (const i in this.validateFloorForm.controls) {
|
|
254
|
+ this.validateFloorForm.controls[i].markAsDirty();
|
|
255
|
+ this.validateFloorForm.controls[i].updateValueAndValidity();
|
|
256
|
+ }
|
|
257
|
+ if (this.validateFloorForm.invalid) return;
|
|
258
|
+ this.btnLoading = true;
|
|
259
|
+ let postData;
|
|
260
|
+ if (this.addFloor) {
|
|
261
|
+ let arr = this.allFloorList.filter(
|
|
262
|
+ (item) => item.floorName == this.validateFloorForm.value.floorName
|
|
263
|
+ );
|
|
264
|
+ //有重复名称
|
|
265
|
+ if (arr.length > 0) {
|
|
266
|
+ this.btnLoading = false;
|
|
267
|
+ this.showPromptModal(
|
|
268
|
+ "新增",
|
|
269
|
+ false,
|
|
270
|
+ `同一个楼栋存在重复的楼层名称【${this.validateFloorForm.value.floorName}】请修改后再保存!`
|
|
271
|
+ );
|
|
272
|
+ return;
|
|
273
|
+ }
|
|
274
|
+ postData = {
|
|
275
|
+ buildId: this.validateFloorForm.value.buildId,
|
|
276
|
+ floorName: this.validateFloorForm.value.floorName,
|
|
277
|
+ deleted: false,
|
|
278
|
+ hosId: this.hosId,
|
|
279
|
+ };
|
|
280
|
+ } else {
|
|
281
|
+ postData = {
|
|
282
|
+ buildId: this.validateFloorForm.value.buildId,
|
|
283
|
+ floorName: this.validateFloorForm.value.floorName,
|
|
284
|
+ deleted: false,
|
|
285
|
+ hosId: this.hosId,
|
|
286
|
+ id: this.floorDataEdit.id,
|
|
287
|
+ };
|
|
288
|
+ }
|
|
289
|
+ this.addFloorHandler(postData, false);
|
|
290
|
+ }
|
|
291
|
+ //新增楼层
|
|
292
|
+ addFloorHandler(postData, flag) {
|
|
293
|
+ this.mainService
|
|
294
|
+ .simplePost(flag ? "addListData" : "addData", "floor", postData)
|
|
295
|
+ .subscribe((result) => {
|
|
296
|
+ this.hideFloorModal();
|
|
297
|
+ this.btnLoading = false;
|
|
298
|
+ if (result["status"] == 200) {
|
|
299
|
+ this.showPromptModal(this.addFloor ? "新增" : "编辑", true, "");
|
|
300
|
+ } else {
|
|
301
|
+ this.showPromptModal(
|
|
302
|
+ this.addFloor ? "新增" : "编辑",
|
|
303
|
+ false,
|
|
304
|
+ result["msg"]
|
|
305
|
+ );
|
|
306
|
+ }
|
|
307
|
+ });
|
|
308
|
+ }
|
|
309
|
+
|
|
310
|
+ //删除楼栋
|
|
311
|
+ delModal: boolean = false;
|
|
312
|
+ showDelModal() {
|
|
313
|
+ this.delModal = true;
|
|
314
|
+ }
|
|
315
|
+ hideDelModal() {
|
|
316
|
+ this.delModal = false;
|
|
317
|
+ }
|
|
318
|
+ // 确认删除
|
|
319
|
+ confirmDel() {
|
|
320
|
+ this.btnLoading = true;
|
|
321
|
+ let postData = [this.checkedBuilding["id"]];
|
|
322
|
+ this.mainService.delBuildingList(postData).subscribe((result) => {
|
|
323
|
+ this.hideDelModal();
|
|
324
|
+ this.btnLoading = false;
|
|
325
|
+ if (result["status"] == 200 && !result["data"][0].msg) {
|
|
326
|
+ this.showPromptModal("删除", true, "");
|
|
327
|
+ } else {
|
|
328
|
+ this.showPromptModal("删除", false, result["data"][0].msg);
|
|
329
|
+ }
|
|
330
|
+ });
|
|
331
|
+ }
|
|
332
|
+ /**
|
|
333
|
+ * 删除楼层
|
|
334
|
+ * @param e 事件对象
|
|
335
|
+ * @param data 有值就是单个删除,无值就是批量删除
|
|
336
|
+ */
|
|
337
|
+ delFloorModal: boolean = false;
|
|
338
|
+ isDelSingle: boolean = false; //是否单个删除
|
|
339
|
+ showDelFloorModal(e, data?) {
|
|
340
|
+ if (data) {
|
|
341
|
+ this.isDelSingle = true;
|
|
342
|
+ this.floorDataEdit = data;
|
|
343
|
+ } else {
|
|
344
|
+ this.isDelSingle = false;
|
|
345
|
+ }
|
|
346
|
+ this.delFloorModal = true;
|
|
347
|
+ e.stopPropagation();
|
|
348
|
+ }
|
|
349
|
+ hideDelFloorModal() {
|
|
350
|
+ this.delFloorModal = false;
|
|
351
|
+ }
|
|
352
|
+ // 确认删除
|
|
353
|
+ confirmFloorDel() {
|
|
354
|
+ this.btnLoading = true;
|
|
355
|
+ let ids = Object.keys(this.mapOfCheckedId); //批量删除选中的楼层
|
|
356
|
+ let postData = this.isDelSingle ? [this.floorDataEdit.id] : ids;
|
|
357
|
+ this.mainService.delFloorList(postData).subscribe((result) => {
|
|
358
|
+ this.hideDelFloorModal();
|
|
359
|
+ this.btnLoading = false;
|
|
360
|
+ if (result["status"] == 200 && !result["data"][0].msg) {
|
|
361
|
+ this.showPromptModal("删除", true, "");
|
|
362
|
+ } else {
|
|
363
|
+ this.showPromptModal("删除", false, result["data"][0].msg);
|
|
364
|
+ }
|
|
365
|
+ });
|
|
366
|
+ }
|
|
367
|
+
|
|
368
|
+ // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
|
|
369
|
+ showPromptModal(con, success, promptInfo) {
|
|
370
|
+ this.promptModalShow = false;
|
|
371
|
+ this.promptContent = con;
|
|
372
|
+ this.ifSuccess = success;
|
|
373
|
+ this.promptInfo = promptInfo;
|
|
374
|
+ this.osComponentRef1.osInstance().scroll({ x: 0, y: this.positionY });
|
|
375
|
+ setTimeout(() => {
|
|
376
|
+ this.promptModalShow = true;
|
|
377
|
+ this.getBuildingList();
|
|
378
|
+ }, 100);
|
|
379
|
+ }
|
|
380
|
+ // 生成楼层
|
|
381
|
+ generateModal: boolean = false;
|
|
382
|
+ generate() {
|
|
383
|
+ this.generateModal = true;
|
|
384
|
+ }
|
|
385
|
+ // 隐藏楼层模态框
|
|
386
|
+ hideGenerateModal() {
|
|
387
|
+ this.generateModal = false;
|
|
388
|
+ }
|
|
389
|
+ // 确认生成
|
|
390
|
+ confirmGenerate(e) {
|
|
391
|
+ console.log(e);
|
|
392
|
+ let arr = []; //生成的楼层
|
|
393
|
+ for (let i = e[1]; i <= e[2]; i++) {
|
|
394
|
+ arr.push({
|
|
395
|
+ buildId: e[0].id,
|
|
396
|
+ floorName: i + "",
|
|
397
|
+ deleted: false,
|
|
398
|
+ hosId: this.hosId,
|
|
399
|
+ });
|
|
400
|
+ }
|
|
401
|
+ // 去重
|
|
402
|
+ this.allFloorList.forEach((item1) => {
|
|
403
|
+ arr = arr.filter(
|
|
404
|
+ (item2) =>
|
|
405
|
+ !(
|
|
406
|
+ item1.buildId == item2.buildId && item1.floorName == item2.floorName
|
|
407
|
+ )
|
|
408
|
+ );
|
|
409
|
+ });
|
|
410
|
+ this.btnLoading = true;
|
|
411
|
+ this.generate1.delModal = false;
|
|
412
|
+ this.hideGenerateModal();
|
|
413
|
+ this.addFloorHandler(arr, true);
|
|
414
|
+ }
|
|
415
|
+}
|