|
@@ -0,0 +1,459 @@
|
|
1
|
+import { Component, OnInit } from "@angular/core";
|
|
2
|
+import { ActivatedRoute, Router } from "@angular/router";
|
|
3
|
+import { differenceInCalendarDays, endOfMonth, endOfYear, format, startOfMonth, startOfYear } from "date-fns";
|
|
4
|
+
|
|
5
|
+import { MainService } from "../../services/main.service";
|
|
6
|
+import { DateService } from "../../services/date.service";
|
|
7
|
+import { MyServiceService } from "../../services/my-service.service";
|
|
8
|
+import { ToolService } from "../../services/tool.service";
|
|
9
|
+
|
|
10
|
+@Component({
|
|
11
|
+ selector: "app-quilt-washing-trend-analysis",
|
|
12
|
+ templateUrl: "./quilt-washing-trend-analysis.component.html",
|
|
13
|
+ styleUrls: ["./quilt-washing-trend-analysis.component.less"],
|
|
14
|
+})
|
|
15
|
+export class QuiltWashingTrendAnalysisComponent implements OnInit {
|
|
16
|
+ constructor(
|
|
17
|
+ private route: ActivatedRoute,
|
|
18
|
+ private router: Router,
|
|
19
|
+ private mainService: MainService,
|
|
20
|
+ private dateService: DateService,
|
|
21
|
+ private myService: MyServiceService,
|
|
22
|
+ private tool: ToolService
|
|
23
|
+ ) {}
|
|
24
|
+
|
|
25
|
+ ngOnInit() {
|
|
26
|
+ this.coopBtns = this.tool.initCoopBtns(this.route);
|
|
27
|
+ this.getAllHos();
|
|
28
|
+ this.changeDateRange(this.defRange);
|
|
29
|
+ // this.search();
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ dateType: string = "day"; //选中时间维度
|
|
33
|
+ dateTypes: any = [
|
|
34
|
+ {
|
|
35
|
+ label: "按天统计",
|
|
36
|
+ value: "day",
|
|
37
|
+ },
|
|
38
|
+ {
|
|
39
|
+ label: "按月统计",
|
|
40
|
+ value: "month",
|
|
41
|
+ },
|
|
42
|
+ {
|
|
43
|
+ label: "按年统计",
|
|
44
|
+ value: "year",
|
|
45
|
+ },
|
|
46
|
+ ]; //时间维度
|
|
47
|
+ defRange = "1"; //默认上周
|
|
48
|
+ defRanges = [
|
|
49
|
+ {
|
|
50
|
+ label: "上周",
|
|
51
|
+ id: 1,
|
|
52
|
+ },
|
|
53
|
+ {
|
|
54
|
+ label: "上月",
|
|
55
|
+ id: 2,
|
|
56
|
+ },
|
|
57
|
+ {
|
|
58
|
+ label: "上年",
|
|
59
|
+ id: 3,
|
|
60
|
+ },
|
|
61
|
+ ]; //时间默认区间
|
|
62
|
+
|
|
63
|
+ listOfData: any[] = []; //表格数据
|
|
64
|
+ pageIndex: number = 1; //表格当前页码
|
|
65
|
+ pageSize: number = 10; //表格每页展示条数
|
|
66
|
+ listLength: number = 10; //表格总数据量
|
|
67
|
+
|
|
68
|
+ alldepart: any = []; //当前院区所属科室
|
|
69
|
+ dateRange: any = []; //发起时间区间 天
|
|
70
|
+ monthRangeStart: any; //发起时间 月 起
|
|
71
|
+ monthRangeEnd: any; //发起时间 月 止
|
|
72
|
+ yearRangeStart: any; //发起时间 年 起
|
|
73
|
+ yearRangeEnd: any; //发起时间 年 止
|
|
74
|
+
|
|
75
|
+ promptContent: string; //操作提示框提示信息
|
|
76
|
+ ifSuccess: boolean; //操作成功/失败
|
|
77
|
+ promptInfo: string; //操作结果提示信息
|
|
78
|
+ promptModalShow: boolean; //操作提示框是否展示
|
|
79
|
+
|
|
80
|
+ // 初始化增删改按钮
|
|
81
|
+ coopBtns: any = {};
|
|
82
|
+ searchData: any = {}; // 综合统计页面带过来的参数
|
|
83
|
+ getSearchData() {
|
|
84
|
+ let that = this;
|
|
85
|
+ let sub = that.myService.getMsg().subscribe((msg) => {
|
|
86
|
+ // 从综合报表跳转过来
|
|
87
|
+ that.searchData = msg;
|
|
88
|
+ console.log(that.searchData);
|
|
89
|
+ console.log(66);
|
|
90
|
+ sub.unsubscribe(); //取消订阅,否则订阅函数会累加执行
|
|
91
|
+ that.hospital = that.searchData["hosId"];
|
|
92
|
+ that.changeDate(that.searchData["range"]);
|
|
93
|
+ that.defRange = that.searchData["defRange"];
|
|
94
|
+ that.search();
|
|
95
|
+ });
|
|
96
|
+ that.changeDateRange(that.defRange);
|
|
97
|
+ that.search();
|
|
98
|
+ }
|
|
99
|
+ // 搜索
|
|
100
|
+ search(num?: number) {
|
|
101
|
+ if (this.hospital) {
|
|
102
|
+ this.searchData["hosId"] = this.hospital;
|
|
103
|
+ }
|
|
104
|
+ if (this.startDate) {
|
|
105
|
+ this.searchData["dateRange"] = {
|
|
106
|
+ start: this.startDate + " " + "00:00:00",
|
|
107
|
+ end: this.endDate + " " + "23:59:59",
|
|
108
|
+ };
|
|
109
|
+ }
|
|
110
|
+ if (num !== undefined) {
|
|
111
|
+ this.getList(num, this.sortCurrentKey, this.sortCurrentValue);
|
|
112
|
+ } else {
|
|
113
|
+ this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
|
|
114
|
+ }
|
|
115
|
+ }
|
|
116
|
+ // 导出
|
|
117
|
+ loading2 = false;
|
|
118
|
+ export() {
|
|
119
|
+ let that = this;
|
|
120
|
+ let postData: any = {
|
|
121
|
+ startTime: this.startDate + " " + "00:00:00",
|
|
122
|
+ endTime: this.endDate + " " + "23:59:59",
|
|
123
|
+ hosId: that.hospital,
|
|
124
|
+ type: this.dateType,
|
|
125
|
+ };
|
|
126
|
+ if (this.sortCurrentKey && this.sortCurrentValue) {
|
|
127
|
+ postData.sort =
|
|
128
|
+ this.sortCurrentValue === "ascend"
|
|
129
|
+ ? this.sortCurrentKey
|
|
130
|
+ : `${this.sortCurrentKey} desc`;
|
|
131
|
+ }
|
|
132
|
+ this.loading2 = true;
|
|
133
|
+ that.mainService.exportReport("clothesHos", postData).subscribe(
|
|
134
|
+ (data) => {
|
|
135
|
+ this.loading2 = false;
|
|
136
|
+ this.showPromptModal("导出", true, "");
|
|
137
|
+ var file = new Blob([data], {
|
|
138
|
+ type: "application/vnd.ms-excel",
|
|
139
|
+ });
|
|
140
|
+ //trick to download store a file having its URL
|
|
141
|
+ var fileURL = URL.createObjectURL(file);
|
|
142
|
+ var a = document.createElement("a");
|
|
143
|
+ a.href = fileURL;
|
|
144
|
+ a.target = "_blank";
|
|
145
|
+ a.download = "全员统计.xls";
|
|
146
|
+ document.body.appendChild(a);
|
|
147
|
+ a.click();
|
|
148
|
+ },
|
|
149
|
+ (err) => {
|
|
150
|
+ this.loading2 = false;
|
|
151
|
+ this.showPromptModal("导出", false, "");
|
|
152
|
+ }
|
|
153
|
+ );
|
|
154
|
+ }
|
|
155
|
+ // 重置
|
|
156
|
+ reset() {
|
|
157
|
+ this.changeDateType("day");
|
|
158
|
+ this.changeDateRange("1");
|
|
159
|
+ this.sortCurrentKey = "";
|
|
160
|
+ this.sortCurrentValue = "";
|
|
161
|
+ this.sortCurrent = {
|
|
162
|
+ deptNum: null,
|
|
163
|
+ clothesTypeNum: null,
|
|
164
|
+ getOrder: null,
|
|
165
|
+ sendOrder: null,
|
|
166
|
+ sendClothesNum: null,
|
|
167
|
+ price: null,
|
|
168
|
+ };
|
|
169
|
+ this.search();
|
|
170
|
+ }
|
|
171
|
+ // 表格数据
|
|
172
|
+ loading1 = false;
|
|
173
|
+ getList(num?: number, field?: string, sort?: string) {
|
|
174
|
+ this.pageIndex = num;
|
|
175
|
+ let postData: any = {
|
|
176
|
+ idx: this.pageIndex - 1,
|
|
177
|
+ sum: this.pageSize,
|
|
178
|
+ startTime: this.searchData.dateRange.start,
|
|
179
|
+ endTime: this.searchData.dateRange.end,
|
|
180
|
+ hosId: this.searchData.hosId,
|
|
181
|
+ type: this.dateType,
|
|
182
|
+ };
|
|
183
|
+ if (field && sort) {
|
|
184
|
+ postData.sort = sort === "ascend" ? field : `${field} desc`;
|
|
185
|
+ }
|
|
186
|
+ this.loading1 = true;
|
|
187
|
+ this.mainService
|
|
188
|
+ .postCustom("report/clothes", "hospital", postData)
|
|
189
|
+ .subscribe((result) => {
|
|
190
|
+ this.loading1 = false;
|
|
191
|
+ this.listOfData = result.list || [];
|
|
192
|
+ this.listLength = result.totalNum;
|
|
193
|
+ });
|
|
194
|
+ }
|
|
195
|
+ // 获取院区
|
|
196
|
+ hospital: string; //选中院区
|
|
197
|
+ getAllHos() {
|
|
198
|
+ this.hospital = this.tool.getCurrentHospital().id + "";
|
|
199
|
+ }
|
|
200
|
+
|
|
201
|
+ // 修改时间展示维度
|
|
202
|
+ changeDateType(res) {
|
|
203
|
+ console.log(res, this.dateType);
|
|
204
|
+ this.dateType = res;
|
|
205
|
+ this.searchData["type"] = res;
|
|
206
|
+ console.log(this.searchData);
|
|
207
|
+ switch (res) {
|
|
208
|
+ case "day":
|
|
209
|
+ this.defRanges = [
|
|
210
|
+ {
|
|
211
|
+ label: "上周",
|
|
212
|
+ id: 1,
|
|
213
|
+ },
|
|
214
|
+ {
|
|
215
|
+ label: "上月",
|
|
216
|
+ id: 2,
|
|
217
|
+ },
|
|
218
|
+ {
|
|
219
|
+ label: "上年",
|
|
220
|
+ id: 3,
|
|
221
|
+ },
|
|
222
|
+ ]; //时间默认区间
|
|
223
|
+ this.defRange = "1"; //默认上周
|
|
224
|
+ this.changeDateRange("1");
|
|
225
|
+ break;
|
|
226
|
+ case "month":
|
|
227
|
+ this.defRanges = [
|
|
228
|
+ {
|
|
229
|
+ label: "上月",
|
|
230
|
+ id: 2,
|
|
231
|
+ },
|
|
232
|
+ {
|
|
233
|
+ label: "上年",
|
|
234
|
+ id: 3,
|
|
235
|
+ },
|
|
236
|
+ ]; //时间默认区间
|
|
237
|
+ this.defRange = "2"; //上月
|
|
238
|
+ this.changeDateRange("2");
|
|
239
|
+ break;
|
|
240
|
+ case "year":
|
|
241
|
+ this.defRanges = [
|
|
242
|
+ {
|
|
243
|
+ label: "上年",
|
|
244
|
+ id: 3,
|
|
245
|
+ },
|
|
246
|
+ ]; //时间默认区间
|
|
247
|
+ this.defRange = "3"; //默认上周
|
|
248
|
+ this.changeDateRange("3");
|
|
249
|
+ break;
|
|
250
|
+ }
|
|
251
|
+ }
|
|
252
|
+
|
|
253
|
+ // 禁选日期
|
|
254
|
+ disabledDate = (current: Date): boolean => {
|
|
255
|
+ // Can not select days before today and today
|
|
256
|
+ return differenceInCalendarDays(current, this.today) > 0;
|
|
257
|
+ };
|
|
258
|
+
|
|
259
|
+ // 禁选月份开始
|
|
260
|
+ disabledMonthStart = (current: Date): boolean => {
|
|
261
|
+ // Can not select days before today and today
|
|
262
|
+ let cur = differenceInCalendarDays(current, endOfMonth(this.today)) > 0;
|
|
263
|
+ let staEnd = differenceInCalendarDays(current, this.monthRangeEnd) > 0;
|
|
264
|
+ return cur || staEnd;
|
|
265
|
+ };
|
|
266
|
+ // 禁选月份结束
|
|
267
|
+ disabledMonthEnd = (current: Date): boolean => {
|
|
268
|
+ // Can not select days before today and today
|
|
269
|
+ let cur = differenceInCalendarDays(current, endOfMonth(this.today)) > 0;
|
|
270
|
+ let staEnd = differenceInCalendarDays(this.monthRangeStart, current) > 0;
|
|
271
|
+ return cur || staEnd;
|
|
272
|
+ };
|
|
273
|
+
|
|
274
|
+ // 禁选年份开始
|
|
275
|
+ disabledYearStart = (current: Date): boolean => {
|
|
276
|
+ // Can not select days before today and today
|
|
277
|
+ let cur = differenceInCalendarDays(current, endOfYear(this.today)) > 0;
|
|
278
|
+ let staEnd = differenceInCalendarDays(current, this.yearRangeEnd) > 0;
|
|
279
|
+ return cur || staEnd;
|
|
280
|
+ };
|
|
281
|
+
|
|
282
|
+ // 禁选年份结束
|
|
283
|
+ disabledYearEnd = (current: Date): boolean => {
|
|
284
|
+ // Can not select days before today and today
|
|
285
|
+ let cur = differenceInCalendarDays(current, endOfYear(this.today)) > 0;
|
|
286
|
+ let staEnd = differenceInCalendarDays(this.yearRangeStart, current) > 0;
|
|
287
|
+ return cur || staEnd;
|
|
288
|
+ };
|
|
289
|
+
|
|
290
|
+ // 日期选择 日
|
|
291
|
+ startDate: string; //发起时间开始
|
|
292
|
+ endDate: string; //发起时间结束
|
|
293
|
+ changeDate(result?): void {
|
|
294
|
+ console.log(this.dateRange);
|
|
295
|
+ console.log(result);
|
|
296
|
+ this.dateRange = result;
|
|
297
|
+ if (!this.quick) {
|
|
298
|
+ // 不是快捷选择
|
|
299
|
+ this.defRange = null;
|
|
300
|
+ }
|
|
301
|
+ if (!result || !result.length) {
|
|
302
|
+ this.startDate = this.endDate = "";
|
|
303
|
+ return;
|
|
304
|
+ }
|
|
305
|
+ this.startDate =
|
|
306
|
+ result[0].getFullYear() +
|
|
307
|
+ "-" +
|
|
308
|
+ (result[0].getMonth() + 1) +
|
|
309
|
+ "-" +
|
|
310
|
+ result[0].getDate();
|
|
311
|
+ this.endDate =
|
|
312
|
+ result[1].getFullYear() +
|
|
313
|
+ "-" +
|
|
314
|
+ (result[1].getMonth() + 1) +
|
|
315
|
+ "-" +
|
|
316
|
+ result[1].getDate();
|
|
317
|
+ }
|
|
318
|
+
|
|
319
|
+ // 月份选择
|
|
320
|
+ changeMonthStart(result?) {
|
|
321
|
+ console.log(result);
|
|
322
|
+ this.monthRangeStart = result;
|
|
323
|
+ if (!this.quick) {
|
|
324
|
+ // 不是快捷选择
|
|
325
|
+ this.defRange = null;
|
|
326
|
+ }
|
|
327
|
+ if (!result) {
|
|
328
|
+ this.startDate = this.endDate = "";
|
|
329
|
+ return;
|
|
330
|
+ }
|
|
331
|
+ this.startDate = format(startOfMonth(result), 'yyyy-MM-dd');
|
|
332
|
+ // this.endDate = result.getFullYear() + '-' + (result.getMonth() + 1) + '-01';
|
|
333
|
+ }
|
|
334
|
+ changeMonthEnd(result?) {
|
|
335
|
+ console.log(result);
|
|
336
|
+ this.monthRangeEnd = result;
|
|
337
|
+ if (!this.quick) {
|
|
338
|
+ // 不是快捷选择
|
|
339
|
+ this.defRange = null;
|
|
340
|
+ }
|
|
341
|
+ if (!result) {
|
|
342
|
+ this.startDate = this.endDate = "";
|
|
343
|
+ return;
|
|
344
|
+ }
|
|
345
|
+ // this.startDate = result.getFullYear() + '-' + (result.getMonth() + 1) + '-01';
|
|
346
|
+ this.endDate = format(endOfMonth(result), 'yyyy-MM-dd');
|
|
347
|
+ }
|
|
348
|
+ // 年份选择
|
|
349
|
+ changeYearStart(result?) {
|
|
350
|
+ console.log(result);
|
|
351
|
+ this.yearRangeStart = result;
|
|
352
|
+ if (!this.quick) {
|
|
353
|
+ // 不是快捷选择
|
|
354
|
+ this.defRange = null;
|
|
355
|
+ }
|
|
356
|
+ if (!result) {
|
|
357
|
+ this.startDate = this.endDate = "";
|
|
358
|
+ return;
|
|
359
|
+ }
|
|
360
|
+ this.startDate = format(startOfYear(result), 'yyyy-MM-dd');
|
|
361
|
+ // this.endDate = result.getFullYear() + '-01-01';
|
|
362
|
+ }
|
|
363
|
+ changeYearEnd(result?) {
|
|
364
|
+ console.log(result);
|
|
365
|
+ this.yearRangeEnd = result;
|
|
366
|
+ if (!this.quick) {
|
|
367
|
+ // 不是快捷选择
|
|
368
|
+ this.defRange = null;
|
|
369
|
+ }
|
|
370
|
+ if (!result) {
|
|
371
|
+ this.startDate = this.endDate = "";
|
|
372
|
+ return;
|
|
373
|
+ }
|
|
374
|
+ this.endDate = format(endOfYear(result), 'yyyy-MM-dd');
|
|
375
|
+ }
|
|
376
|
+
|
|
377
|
+ // 日期选择 快速修改时间区间
|
|
378
|
+ today = new Date();
|
|
379
|
+ quick: boolean = false;
|
|
380
|
+ changeDateRange(res) {
|
|
381
|
+ console.log(res);
|
|
382
|
+ this.quick = true;
|
|
383
|
+ switch (res) {
|
|
384
|
+ case "1":
|
|
385
|
+ // 上周
|
|
386
|
+ let lastweekstartdate = this.dateService.date().lastWeekStartDate;
|
|
387
|
+ let lastweekenddate = this.dateService.date().lastWeekEndDate;
|
|
388
|
+ console.log(lastweekstartdate, lastweekenddate);
|
|
389
|
+ this.changeDate([lastweekstartdate, lastweekenddate]);
|
|
390
|
+ break;
|
|
391
|
+ case "2":
|
|
392
|
+ // 上月
|
|
393
|
+ let lastmonthstartdate = this.dateService.date().lastMonthStartDate;
|
|
394
|
+ let lastmonthenddate = this.dateService.date().lastMonthEndDate;
|
|
395
|
+ console.log(lastmonthstartdate, lastmonthenddate);
|
|
396
|
+ this.changeDate([lastmonthstartdate, lastmonthenddate]);
|
|
397
|
+ this.changeMonthStart(lastmonthstartdate);
|
|
398
|
+ this.changeMonthEnd(lastmonthenddate);
|
|
399
|
+ break;
|
|
400
|
+ case "3":
|
|
401
|
+ // 上年
|
|
402
|
+ let lastyearstartdate = this.dateService.date().lastYearStartDate;
|
|
403
|
+ let lastyearenddate = this.dateService.date().lastYearEndDate;
|
|
404
|
+ console.log(lastyearstartdate, lastyearenddate);
|
|
405
|
+ this.changeDate([lastyearstartdate, lastyearenddate]);
|
|
406
|
+ this.changeMonthStart(lastyearstartdate);
|
|
407
|
+ this.changeMonthEnd(lastyearenddate);
|
|
408
|
+ this.changeYearStart(lastyearstartdate);
|
|
409
|
+ this.changeYearEnd(lastyearenddate);
|
|
410
|
+ break;
|
|
411
|
+ }
|
|
412
|
+ this.quick = false;
|
|
413
|
+ this.search();
|
|
414
|
+ }
|
|
415
|
+
|
|
416
|
+ // 更多
|
|
417
|
+ toMore(type) {
|
|
418
|
+ let sendData = this.searchData;
|
|
419
|
+ console.log(sendData);
|
|
420
|
+ this.myService.sendMsg(sendData);
|
|
421
|
+ this.router.navigateByUrl("/main/" + type);
|
|
422
|
+ }
|
|
423
|
+
|
|
424
|
+ // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
|
|
425
|
+ showPromptModal(con, success, promptInfo?) {
|
|
426
|
+ this.promptModalShow = false;
|
|
427
|
+ this.promptContent = con;
|
|
428
|
+ this.ifSuccess = success;
|
|
429
|
+ this.promptInfo = promptInfo;
|
|
430
|
+ setTimeout(() => {
|
|
431
|
+ this.promptModalShow = true;
|
|
432
|
+ }, 100);
|
|
433
|
+ }
|
|
434
|
+
|
|
435
|
+ // 边输入边搜索节流阀
|
|
436
|
+ isLoading: boolean = false;
|
|
437
|
+ searchTimer(fun, e, those) {
|
|
438
|
+ let that = this;
|
|
439
|
+ that.isLoading = true;
|
|
440
|
+ fun(e, those);
|
|
441
|
+ }
|
|
442
|
+ // 列表排序
|
|
443
|
+ sortCurrent = {
|
|
444
|
+ deptNum: null,
|
|
445
|
+ clothesTypeNum: null,
|
|
446
|
+ getOrder: null,
|
|
447
|
+ sendOrder: null,
|
|
448
|
+ sendClothesNum: null,
|
|
449
|
+ price: null,
|
|
450
|
+ };
|
|
451
|
+ sortCurrentKey: string = "";
|
|
452
|
+ sortCurrentValue: string | null = "";
|
|
453
|
+ sort(e) {
|
|
454
|
+ const { key, value } = e;
|
|
455
|
+ this.sortCurrentKey = key;
|
|
456
|
+ this.sortCurrentValue = value;
|
|
457
|
+ this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
|
|
458
|
+ }
|
|
459
|
+}
|