|
@@ -0,0 +1,398 @@
|
|
1
|
+import { Component, OnInit, ViewChild } from "@angular/core";
|
|
2
|
+import { ActivatedRoute } from "@angular/router";
|
|
3
|
+import {
|
|
4
|
+ FormBuilder,
|
|
5
|
+ Validators,
|
|
6
|
+ FormGroup,
|
|
7
|
+ FormControl,
|
|
8
|
+} from "@angular/forms";
|
|
9
|
+
|
|
10
|
+import { MainService } from "../../services/main.service";
|
|
11
|
+import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
|
|
12
|
+import { ToolService } from "../../services/tool.service";
|
|
13
|
+import { NzMessageService } from "ng-zorro-antd";
|
|
14
|
+import { format } from "date-fns";
|
|
15
|
+@Component({
|
|
16
|
+ selector: "app-regular-off-duty",
|
|
17
|
+ templateUrl: "./regular-off-duty.component.html",
|
|
18
|
+ styleUrls: ["./regular-off-duty.component.less"],
|
|
19
|
+})
|
|
20
|
+export class RegularOffDutyComponent implements OnInit {
|
|
21
|
+ @ViewChild("osComponentRef1", {
|
|
22
|
+ read: OverlayScrollbarsComponent,
|
|
23
|
+ static: false,
|
|
24
|
+ })
|
|
25
|
+ osComponentRef1: OverlayScrollbarsComponent;
|
|
26
|
+ constructor(
|
|
27
|
+ private message: NzMessageService,
|
|
28
|
+ private fb: FormBuilder,
|
|
29
|
+ private mainService: MainService,
|
|
30
|
+ private route: ActivatedRoute,
|
|
31
|
+ private tool: ToolService
|
|
32
|
+ ) {}
|
|
33
|
+
|
|
34
|
+ userInfo: any = JSON.parse(localStorage.getItem("user")) || {}; //登录用户信息
|
|
35
|
+ hosId;
|
|
36
|
+ createUser = "";
|
|
37
|
+ classes = []; // 用户列表
|
|
38
|
+ listOfData: any[] = []; //表格数据
|
|
39
|
+ pageIndex: number = 1; //表格当前页码
|
|
40
|
+ pageSize: number = 10; //表格每页展示条数
|
|
41
|
+ listLength: number = 10; //表格总数据量
|
|
42
|
+ tableHeight: number; //表格动态高
|
|
43
|
+ modal: boolean = false; //新增/编辑模态框
|
|
44
|
+ validateForm: FormGroup; //新增/编辑表单
|
|
45
|
+ dataContent: any; //当前操作列
|
|
46
|
+
|
|
47
|
+ oneOption: any; //适用日期类型
|
|
48
|
+ btnLoading: boolean = false; //提交按钮loading状态
|
|
49
|
+
|
|
50
|
+ promptContent: string; //操作提示框提示信息
|
|
51
|
+ ifSuccess: boolean; //操作成功/失败
|
|
52
|
+ promptInfo: string; //操作结果提示信息
|
|
53
|
+ promptModalShow: boolean; //操作提示框是否展示
|
|
54
|
+ demoValue: number = 0;
|
|
55
|
+
|
|
56
|
+ ngOnInit() {
|
|
57
|
+ this.hosId = this.tool.getCurrentHospital().id;
|
|
58
|
+ this.getList();
|
|
59
|
+ this.coopBtns = this.tool.initCoopBtns(this.route);
|
|
60
|
+ this.initForm();
|
|
61
|
+ }
|
|
62
|
+ // 新增/编辑弹框
|
|
63
|
+ add: boolean; //true:新增;false:编辑
|
|
64
|
+ addModal() {
|
|
65
|
+ this.add = true; //新增
|
|
66
|
+ this.modal = true;
|
|
67
|
+ this.initForm();
|
|
68
|
+ }
|
|
69
|
+ changeForm(flag) {
|
|
70
|
+ if (flag) {
|
|
71
|
+ this.changeInp("no", "form");
|
|
72
|
+ }
|
|
73
|
+ }
|
|
74
|
+ // 边输边搜节流阀
|
|
75
|
+ isLoading = false;
|
|
76
|
+ changeInp(dept, type) {
|
|
77
|
+ if (!dept) {
|
|
78
|
+ return;
|
|
79
|
+ }
|
|
80
|
+ if (dept === "no") {
|
|
81
|
+ dept = "";
|
|
82
|
+ }
|
|
83
|
+ this.isLoading = true;
|
|
84
|
+ this.searchUsers(dept, type);
|
|
85
|
+ }
|
|
86
|
+ // 搜索班次
|
|
87
|
+ snum = 0;
|
|
88
|
+ searchUsers(dept, type) {
|
|
89
|
+ let data = {
|
|
90
|
+ scheduleClass: {
|
|
91
|
+ hospital: { id: this.hosId.toString() },
|
|
92
|
+ },
|
|
93
|
+ idx: 0,
|
|
94
|
+ sum: 20,
|
|
95
|
+ };
|
|
96
|
+ this.snum++;
|
|
97
|
+ this.mainService
|
|
98
|
+ .getFetchDataList("configuration", "scheduleClass", data)
|
|
99
|
+ .subscribe((data) => {
|
|
100
|
+ this.snum--;
|
|
101
|
+ if (data.status == 200) {
|
|
102
|
+ if (type === "form") {
|
|
103
|
+ if (this.snum === 0) {
|
|
104
|
+ this.isLoading = false;
|
|
105
|
+ }
|
|
106
|
+ this.classes = data.list;
|
|
107
|
+ }
|
|
108
|
+ }
|
|
109
|
+ });
|
|
110
|
+ }
|
|
111
|
+
|
|
112
|
+ // 初始化权限按钮
|
|
113
|
+ coopBtns: any = {};
|
|
114
|
+
|
|
115
|
+ // 表格数据
|
|
116
|
+ loading1 = false;
|
|
117
|
+ getList() {
|
|
118
|
+ let postData = {
|
|
119
|
+ idx: this.pageIndex - 1,
|
|
120
|
+ sum: this.pageSize,
|
|
121
|
+ messageJob: {
|
|
122
|
+ hospital: this.hosId,
|
|
123
|
+ },
|
|
124
|
+ };
|
|
125
|
+ this.loading1 = true;
|
|
126
|
+ this.mainService
|
|
127
|
+ .getFetchDataList("simple/data", "classesJob", postData)
|
|
128
|
+ .subscribe((data) => {
|
|
129
|
+ this.loading1 = false;
|
|
130
|
+ if (data.status == 200) {
|
|
131
|
+ this.listOfData = data.list;
|
|
132
|
+ this.listOfData.forEach((item) => {
|
|
133
|
+ if (item.timeStep == "week") {
|
|
134
|
+ let weeks = [
|
|
135
|
+ "周一",
|
|
136
|
+ "周二",
|
|
137
|
+ "周三",
|
|
138
|
+ "周四",
|
|
139
|
+ "周五",
|
|
140
|
+ "周六",
|
|
141
|
+ "周日",
|
|
142
|
+ ];
|
|
143
|
+ item.weekName = weeks[item.extra1 - 1];
|
|
144
|
+ }
|
|
145
|
+ item.usersName = item.classes.map((value) => value.name).join();
|
|
146
|
+ });
|
|
147
|
+ this.listLength = data.totalNum;
|
|
148
|
+ }
|
|
149
|
+ });
|
|
150
|
+ }
|
|
151
|
+ //关闭编辑弹框
|
|
152
|
+ hideAddModal() {
|
|
153
|
+ this.modal = false;
|
|
154
|
+ this.initForm();
|
|
155
|
+ }
|
|
156
|
+ // 初始化form表单
|
|
157
|
+ initForm() {
|
|
158
|
+ this.validateForm = this.fb.group({
|
|
159
|
+ title: [null, [Validators.required]], //标题
|
|
160
|
+ timeStep: ["day", [Validators.required]], //重复策略
|
|
161
|
+ executeTime: [null, [Validators.required]], //定时发送时间
|
|
162
|
+ active: [false, [Validators.required]], //是否启用
|
|
163
|
+ classIds: [null, [Validators.required]], //定时下班班次
|
|
164
|
+ });
|
|
165
|
+ }
|
|
166
|
+ //修改重复策略
|
|
167
|
+ months = [...Array(32).keys()].slice(1);
|
|
168
|
+ timeStepChange(e) {
|
|
169
|
+ switch (e) {
|
|
170
|
+ case "day":
|
|
171
|
+ this.validateForm.removeControl("doWeek");
|
|
172
|
+ this.validateForm.removeControl("doMonth");
|
|
173
|
+ this.validateForm.removeControl("doYear");
|
|
174
|
+ break;
|
|
175
|
+ case "week":
|
|
176
|
+ this.validateForm.addControl(
|
|
177
|
+ "doWeek",
|
|
178
|
+ new FormControl(null, Validators.required)
|
|
179
|
+ );
|
|
180
|
+ this.validateForm.removeControl("doMonth");
|
|
181
|
+ this.validateForm.removeControl("doYear");
|
|
182
|
+ break;
|
|
183
|
+ case "month":
|
|
184
|
+ this.validateForm.addControl(
|
|
185
|
+ "doMonth",
|
|
186
|
+ new FormControl(null, Validators.required)
|
|
187
|
+ );
|
|
188
|
+ this.validateForm.removeControl("doWeek");
|
|
189
|
+ this.validateForm.removeControl("doYear");
|
|
190
|
+ break;
|
|
191
|
+ case "year":
|
|
192
|
+ this.validateForm.addControl(
|
|
193
|
+ "doYear",
|
|
194
|
+ new FormControl(null, Validators.required)
|
|
195
|
+ );
|
|
196
|
+ this.validateForm.removeControl("doWeek");
|
|
197
|
+ this.validateForm.removeControl("doMonth");
|
|
198
|
+ break;
|
|
199
|
+ }
|
|
200
|
+ }
|
|
201
|
+
|
|
202
|
+ // 表单提交
|
|
203
|
+ submitForm(): void {
|
|
204
|
+ this.btnLoading = true;
|
|
205
|
+ for (const i in this.validateForm.controls) {
|
|
206
|
+ this.validateForm.controls[i].markAsDirty();
|
|
207
|
+ this.validateForm.controls[i].updateValueAndValidity();
|
|
208
|
+ }
|
|
209
|
+ if (this.validateForm.invalid) {
|
|
210
|
+ this.btnLoading = false;
|
|
211
|
+ return;
|
|
212
|
+ }
|
|
213
|
+ let postData: any = {};
|
|
214
|
+ if (this.add) {
|
|
215
|
+ postData = {
|
|
216
|
+ hospital: this.hosId,
|
|
217
|
+ title: this.validateForm.value.title,
|
|
218
|
+ executeTime: new Date(this.validateForm.value.executeTime).getTime(),
|
|
219
|
+ classesIds: this.validateForm.value.classIds.join(),
|
|
220
|
+ active: this.validateForm.value.active,
|
|
221
|
+ key: "regularOffDuty",
|
|
222
|
+ timeStep: this.validateForm.value.timeStep,
|
|
223
|
+ };
|
|
224
|
+ } else {
|
|
225
|
+ postData = {
|
|
226
|
+ title: this.validateForm.value.title,
|
|
227
|
+ executeTime: new Date(this.validateForm.value.executeTime).getTime(),
|
|
228
|
+ classesIds: this.validateForm.value.classIds.join(),
|
|
229
|
+ active: this.validateForm.value.active,
|
|
230
|
+ key: this.dataContent.key,
|
|
231
|
+ id: this.dataContent.id,
|
|
232
|
+ timeStep: this.validateForm.value.timeStep,
|
|
233
|
+ };
|
|
234
|
+ }
|
|
235
|
+ if (this.validateForm.value.timeStep == "day") {
|
|
236
|
+ delete postData.extra1;
|
|
237
|
+ } else if (this.validateForm.value.timeStep == "week") {
|
|
238
|
+ postData.extra1 = this.validateForm.value.doWeek;
|
|
239
|
+ } else if (this.validateForm.value.timeStep == "month") {
|
|
240
|
+ postData.extra1 = this.validateForm.value.doMonth;
|
|
241
|
+ } else if (this.validateForm.value.timeStep == "year") {
|
|
242
|
+ delete postData.extra1;
|
|
243
|
+ postData.executeTime = new Date(
|
|
244
|
+ format(new Date(this.validateForm.value.doYear), "yyyy-MM-dd") +
|
|
245
|
+ " " +
|
|
246
|
+ format(new Date(this.validateForm.value.executeTime), "HH:mm:ss")
|
|
247
|
+ ).getTime();
|
|
248
|
+ }
|
|
249
|
+ this.mainService
|
|
250
|
+ .simplePost(this.add ? "addData" : "updData", "classesJob", postData)
|
|
251
|
+ .subscribe((data) => {
|
|
252
|
+ this.btnLoading = false;
|
|
253
|
+ this.hideAddModal();
|
|
254
|
+ this.initForm();
|
|
255
|
+ if (data.status == 200) {
|
|
256
|
+ this.listLength++;
|
|
257
|
+ this.showPromptModal("修改", true, "");
|
|
258
|
+ } else {
|
|
259
|
+ this.showPromptModal("修改", false, data.msg);
|
|
260
|
+ }
|
|
261
|
+ });
|
|
262
|
+ }
|
|
263
|
+
|
|
264
|
+ // 编辑
|
|
265
|
+ maskFlag: any = false;
|
|
266
|
+ edit(data) {
|
|
267
|
+ this.add = false;
|
|
268
|
+ this.dataContent = data;
|
|
269
|
+ this.validateForm.controls.executeTime.setValue(new Date(data.executeTime)); //定时发送时间
|
|
270
|
+ this.validateForm.controls.title.setValue(data.title); //标题
|
|
271
|
+ this.validateForm.controls.active.setValue(data.active); //是否启用
|
|
272
|
+ this.timeStepChange(data.timeStep);
|
|
273
|
+ this.validateForm.controls.timeStep.setValue(data.timeStep); //重复策略
|
|
274
|
+ if (data.timeStep == "year") {
|
|
275
|
+ this.validateForm.controls.doYear.setValue(
|
|
276
|
+ format(data.executeTime, "yyyy-MM-dd HH:mm:ss")
|
|
277
|
+ );
|
|
278
|
+ } else if (data.timeStep == "month") {
|
|
279
|
+ this.validateForm.controls.doMonth.setValue(data.extra1);
|
|
280
|
+ } else if (data.timeStep == "week") {
|
|
281
|
+ this.validateForm.controls.doWeek.setValue(data.extra1);
|
|
282
|
+ }
|
|
283
|
+ // --------定时下班班次---
|
|
284
|
+ this.maskFlag = this.message.loading("正在加载中..", {
|
|
285
|
+ nzDuration: 0,
|
|
286
|
+ }).messageId;
|
|
287
|
+ this.mainService
|
|
288
|
+ .getFetchDataList("configuration", "scheduleClass", {
|
|
289
|
+ idx: 0,
|
|
290
|
+ sum: 20,
|
|
291
|
+ user: {
|
|
292
|
+ hosId: this.hosId,
|
|
293
|
+ },
|
|
294
|
+ })
|
|
295
|
+ .subscribe((result) => {
|
|
296
|
+ this.message.remove(this.maskFlag);
|
|
297
|
+ this.maskFlag = false;
|
|
298
|
+ this.modal = true;
|
|
299
|
+ if (result.status == 200) {
|
|
300
|
+ let add = data.classes.filter(
|
|
301
|
+ (item) => !result.list.some((ele) => ele.id == item.id)
|
|
302
|
+ );
|
|
303
|
+ this.classes = add.concat(result.list);
|
|
304
|
+ this.validateForm.controls.classIds.setValue(
|
|
305
|
+ data.classes.map((v) => v.id.toString())
|
|
306
|
+ ); //定时下班班次
|
|
307
|
+ }
|
|
308
|
+ });
|
|
309
|
+ // --------/定时下班班次---
|
|
310
|
+ }
|
|
311
|
+
|
|
312
|
+ // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
|
|
313
|
+ showPromptModal(con, success, promptInfo?) {
|
|
314
|
+ this.promptModalShow = false;
|
|
315
|
+ this.promptContent = con;
|
|
316
|
+ this.ifSuccess = success;
|
|
317
|
+ this.promptInfo = promptInfo;
|
|
318
|
+ setTimeout(() => {
|
|
319
|
+ this.promptModalShow = true;
|
|
320
|
+ }, 100);
|
|
321
|
+ this.getList();
|
|
322
|
+ }
|
|
323
|
+
|
|
324
|
+ // 是否启用
|
|
325
|
+ delModal: boolean = false; //删除模态框
|
|
326
|
+ tipsMsg1: string; //提示框信息
|
|
327
|
+ tipsMsg2: string; //操作后信息
|
|
328
|
+ confirmDelType: string; //确认的类型(启用/停用,删除)
|
|
329
|
+ confirmDelIsSwitch: boolean; //启用/停用
|
|
330
|
+ showDelModal(
|
|
331
|
+ dataContent,
|
|
332
|
+ tipsMsg1: string,
|
|
333
|
+ tipsMsg2: string,
|
|
334
|
+ type: string,
|
|
335
|
+ isSwitch?: boolean
|
|
336
|
+ ) {
|
|
337
|
+ this.confirmDelIsSwitch = isSwitch;
|
|
338
|
+ this.confirmDelType = type;
|
|
339
|
+ this.delModal = true;
|
|
340
|
+ this.dataContent = dataContent;
|
|
341
|
+ this.tipsMsg1 = tipsMsg1;
|
|
342
|
+ this.tipsMsg2 = tipsMsg2;
|
|
343
|
+ }
|
|
344
|
+ // 隐藏
|
|
345
|
+ hideDelModal() {
|
|
346
|
+ this.delModal = false;
|
|
347
|
+ }
|
|
348
|
+ // 确认
|
|
349
|
+ confirmDel() {
|
|
350
|
+ this.btnLoading = true;
|
|
351
|
+ if (this.confirmDelType === "del") {
|
|
352
|
+ //删除
|
|
353
|
+ this.mainService
|
|
354
|
+ .simplePost("rmvData", "classesJob", [this.dataContent.id])
|
|
355
|
+ .subscribe((data) => {
|
|
356
|
+ this.btnLoading = false;
|
|
357
|
+ this.delModal = false;
|
|
358
|
+ if (data.status == 200) {
|
|
359
|
+ if (
|
|
360
|
+ this.listOfData.length == 1 &&
|
|
361
|
+ this.pageIndex == Math.ceil(this.listLength / this.pageSize)
|
|
362
|
+ ) {
|
|
363
|
+ this.listLength--;
|
|
364
|
+ if (this.listLength === 0) {
|
|
365
|
+ this.pageIndex = 1;
|
|
366
|
+ } else {
|
|
367
|
+ this.pageIndex = Math.ceil(this.listLength / this.pageSize);
|
|
368
|
+ }
|
|
369
|
+ }
|
|
370
|
+ this.showPromptModal(this.tipsMsg2, true, "");
|
|
371
|
+ } else {
|
|
372
|
+ this.showPromptModal(this.tipsMsg2, false, data.msg);
|
|
373
|
+ }
|
|
374
|
+ });
|
|
375
|
+ } else if (this.confirmDelType === "switch") {
|
|
376
|
+ //启用/停用
|
|
377
|
+ let postData = {
|
|
378
|
+ id: this.dataContent.id,
|
|
379
|
+ title: this.dataContent.title,
|
|
380
|
+ executeTime: this.dataContent.executeTime,
|
|
381
|
+ classesIds: this.dataContent.classes.map((v) => v.id).join(),
|
|
382
|
+ active: this.dataContent.active ? false : true,
|
|
383
|
+ key: this.dataContent.key,
|
|
384
|
+ };
|
|
385
|
+ this.mainService
|
|
386
|
+ .simplePost("updData", "classesJob", postData)
|
|
387
|
+ .subscribe((data) => {
|
|
388
|
+ this.btnLoading = false;
|
|
389
|
+ this.delModal = false;
|
|
390
|
+ if (data.status == 200) {
|
|
391
|
+ this.showPromptModal(this.tipsMsg2, true, "");
|
|
392
|
+ } else {
|
|
393
|
+ this.showPromptModal(this.tipsMsg2, false, data.msg);
|
|
394
|
+ }
|
|
395
|
+ });
|
|
396
|
+ }
|
|
397
|
+ }
|
|
398
|
+}
|