seimin 1 месяц назад
Родитель
Сommit
5e9b4b964c

+ 33 - 0
src/app/views/new-statistics/components/custom-change-date/custom-change-date.component.html

@@ -0,0 +1,33 @@
1
+<div class="customChangeDate">
2
+  <div class="searchDataItem">
3
+    <nz-radio-group [(ngModel)]="dateType" (ngModelChange)="changeDateType($event)">
4
+      <label *ngFor="let data of dateTypes" nz-radio-button [nzValue]="data.value">{{data.label}}</label>
5
+    </nz-radio-group>
6
+  </div>
7
+  <div class="searchDataItem">
8
+    <span class="label">建单时间</span>:
9
+    <nz-range-picker *ngIf="dateType=='day'" [(ngModel)]="dateRange" [nzAllowClear]='false'
10
+      [nzDisabledDate]="disabledDate" (ngModelChange)="changeDate($event)">
11
+    </nz-range-picker>
12
+    <nz-month-picker *ngIf="dateType=='month'" [(ngModel)]="monthRangeStart" [nzDisabledDate]="disabledMonthStart"
13
+      (ngModelChange)="changeMonthStart($event)" nzPlaceHolder="请选择开始月份">
14
+    </nz-month-picker>
15
+    <span *ngIf="dateType=='month'"> ~ </span>
16
+    <nz-month-picker *ngIf="dateType=='month'" [(ngModel)]="monthRangeEnd" [nzDisabledDate]="disabledMonthEnd"
17
+      (ngModelChange)="changeMonthEnd($event)" nzPlaceHolder="请选择截止月份">
18
+    </nz-month-picker>
19
+    <nz-year-picker *ngIf="dateType=='year'" [(ngModel)]="yearRangeStart" [nzDisabledDate]="disabledYearStart"
20
+      (ngModelChange)="changeYearStart($event)" nzPlaceHolder="请选择开始年份">
21
+    </nz-year-picker>
22
+    <span *ngIf="dateType=='year'"> ~ </span>
23
+    <nz-year-picker *ngIf="dateType=='year'" [(ngModel)]="yearRangeEnd" (ngModelChange)="changeYearEnd($event)"
24
+      [nzDisabledDate]="disabledYearEnd" nzPlaceHolder="请选择截止年份">
25
+    </nz-year-picker>
26
+  </div>
27
+  <div class="searchDataItem ml8">
28
+    <nz-select class="formItem" [ngStyle]="{width: '92px'}" [nzDropdownMatchSelectWidth]="false" [nzShowSearch]="false"
29
+      nzPlaceHolder="请选择时间" [(ngModel)]="defRange" (ngModelChange)="changeDateRange($event)">
30
+      <nz-option nzLabel="{{data.label}}" nzValue="{{data.id}}" *ngFor="let data of defRanges"></nz-option>
31
+    </nz-select>
32
+  </div>
33
+</div>

+ 15 - 0
src/app/views/new-statistics/components/custom-change-date/custom-change-date.component.less

@@ -0,0 +1,15 @@
1
+.customChangeDate{
2
+  display: flex;
3
+  align-items: center;
4
+  margin-right: 24px;
5
+  .searchDataItem{
6
+    margin-left: 16px;
7
+    &:last-of-type{
8
+      margin-left: 0;
9
+    }
10
+    .label{
11
+      font-size: 16px;
12
+    }
13
+  }
14
+}
15
+

+ 268 - 0
src/app/views/new-statistics/components/custom-change-date/custom-change-date.component.ts

@@ -0,0 +1,268 @@
1
+import { Component, OnInit, Output, Input } from '@angular/core';
2
+import { EventEmitter } from '@angular/core';
3
+import { differenceInCalendarDays, endOfMonth, endOfYear, startOfDay, format, endOfDay, startOfMonth, startOfYear } from "date-fns";
4
+import { DateService } from 'src/app/services/date.service';
5
+
6
+@Component({
7
+  selector: 'app-custom-change-date',
8
+  templateUrl: './custom-change-date.component.html',
9
+  styleUrls: ['./custom-change-date.component.less']
10
+})
11
+export class CustomChangeDateComponent implements OnInit {
12
+  @Output() customChangeDateEmit = new EventEmitter();
13
+  @Input() queryType: number;
14
+  constructor(
15
+    private dateService: DateService,
16
+  ) { }
17
+
18
+  dateType: string = "day"; //选中时间维度
19
+  dateTypes: any = [
20
+    {
21
+      label: "按天",
22
+      value: "day",
23
+    },
24
+    {
25
+      label: "按月",
26
+      value: "month",
27
+    },
28
+    {
29
+      label: "按年",
30
+      value: "year",
31
+    },
32
+  ]; //时间维度
33
+  defRange = "1"; //默认上周
34
+  defRanges = [
35
+    {
36
+      label: "上周",
37
+      id: 1,
38
+    },
39
+    {
40
+      label: "上月",
41
+      id: 2,
42
+    },
43
+    {
44
+      label: "上年",
45
+      id: 3,
46
+    },
47
+  ]; //时间默认区间
48
+
49
+  dateRange: any = []; //发起时间区间 天
50
+  monthRangeStart: any; //发起时间 月 起
51
+  monthRangeEnd: any; //发起时间 月 止
52
+  yearRangeStart: any; //发起时间 年 起
53
+  yearRangeEnd: any; //发起时间 年 止
54
+
55
+  ngOnInit() {}
56
+
57
+  // this.customChangeDateEmit.emit({queryType, hospital, duty, parent});
58
+
59
+  // 修改时间展示维度
60
+  changeDateType(res) {
61
+    console.log(res, this.dateType);
62
+    this.dateType = res;
63
+    switch (res) {
64
+      case "day":
65
+        this.defRanges = [
66
+          {
67
+            label: "上周",
68
+            id: 1,
69
+          },
70
+          {
71
+            label: "上月",
72
+            id: 2,
73
+          },
74
+          {
75
+            label: "上年",
76
+            id: 3,
77
+          },
78
+        ]; //时间默认区间
79
+        this.defRange = "1"; //默认上周
80
+        this.changeDateRange("1");
81
+        break;
82
+      case "month":
83
+        this.defRanges = [
84
+          {
85
+            label: "上月",
86
+            id: 2,
87
+          },
88
+          {
89
+            label: "上年",
90
+            id: 3,
91
+          },
92
+        ]; //时间默认区间
93
+        this.defRange = "2"; //上月
94
+        this.changeDateRange("2");
95
+        break;
96
+      case "year":
97
+        this.defRanges = [
98
+          {
99
+            label: "上年",
100
+            id: 3,
101
+          },
102
+        ]; //时间默认区间
103
+        this.defRange = "3"; //默认上周
104
+        this.changeDateRange("3");
105
+        break;
106
+    }
107
+  }
108
+
109
+  // 禁选日期
110
+  disabledDate = (current: Date): boolean => {
111
+    // Can not select days before today and today
112
+    return differenceInCalendarDays(current, this.today) > 0;
113
+  };
114
+
115
+  // 禁选月份开始
116
+  disabledMonthStart = (current: Date): boolean => {
117
+    // Can not select days before today and today
118
+    let cur = differenceInCalendarDays(current, endOfMonth(this.today)) > 0;
119
+    let staEnd = differenceInCalendarDays(current, this.monthRangeEnd) > 0;
120
+    return cur || staEnd;
121
+  };
122
+  // 禁选月份结束
123
+  disabledMonthEnd = (current: Date): boolean => {
124
+    // Can not select days before today and today
125
+    let cur = differenceInCalendarDays(current, endOfMonth(this.today)) > 0;
126
+    let staEnd = differenceInCalendarDays(this.monthRangeStart, current) > 0;
127
+    return cur || staEnd;
128
+  };
129
+
130
+  // 禁选年份开始
131
+  disabledYearStart = (current: Date): boolean => {
132
+    // Can not select days before today and today
133
+    let cur = differenceInCalendarDays(current, endOfYear(this.today)) > 0;
134
+    let staEnd = differenceInCalendarDays(current, this.yearRangeEnd) > 0;
135
+    return cur || staEnd;
136
+  };
137
+
138
+  // 禁选年份结束
139
+  disabledYearEnd = (current: Date): boolean => {
140
+    // Can not select days before today and today
141
+    let cur = differenceInCalendarDays(current, endOfYear(this.today)) > 0;
142
+    let staEnd = differenceInCalendarDays(this.yearRangeStart, current) > 0;
143
+    return cur || staEnd;
144
+  };
145
+
146
+  // 日期选择 日
147
+  startDate: string; //发起时间开始
148
+  endDate: string; //发起时间结束
149
+  changeDate(result?): void {
150
+    console.log(this.dateRange);
151
+    console.log(result);
152
+    this.dateRange = result;
153
+    if (!this.quick) {
154
+      // 不是快捷选择
155
+      this.defRange = null;
156
+    }
157
+    if (!result || !result.length) {
158
+      this.startDate = this.endDate = "";
159
+      return;
160
+    }
161
+    this.startDate =
162
+      result[0].getFullYear() +
163
+      "-" +
164
+      (result[0].getMonth() + 1) +
165
+      "-" +
166
+      result[0].getDate();
167
+    this.endDate =
168
+      result[1].getFullYear() +
169
+      "-" +
170
+      (result[1].getMonth() + 1) +
171
+      "-" +
172
+      result[1].getDate();
173
+  }
174
+
175
+  // 月份选择
176
+  changeMonthStart(result?) {
177
+    console.log(result);
178
+    this.monthRangeStart = result;
179
+    if (!this.quick) {
180
+      // 不是快捷选择
181
+      this.defRange = null;
182
+    }
183
+    if (!result) {
184
+      this.startDate = this.endDate = "";
185
+      return;
186
+    }
187
+    this.startDate = format(startOfMonth(result), 'yyyy-MM-dd');
188
+  }
189
+  changeMonthEnd(result?) {
190
+    console.log(result);
191
+    this.monthRangeEnd = result;
192
+    if (!this.quick) {
193
+      // 不是快捷选择
194
+      this.defRange = null;
195
+    }
196
+    if (!result) {
197
+      this.startDate = this.endDate = "";
198
+      return;
199
+    }
200
+    this.endDate = format(endOfMonth(result), 'yyyy-MM-dd');
201
+  }
202
+  // 年份选择
203
+  changeYearStart(result?) {
204
+    console.log(result);
205
+    this.yearRangeStart = result;
206
+    if (!this.quick) {
207
+      // 不是快捷选择
208
+      this.defRange = null;
209
+    }
210
+    if (!result) {
211
+      this.startDate = this.endDate = "";
212
+      return;
213
+    }
214
+    this.startDate = format(startOfYear(result), 'yyyy-MM-dd');
215
+    // this.endDate = result.getFullYear() + '-01-01';
216
+  }
217
+  changeYearEnd(result?) {
218
+    console.log(result);
219
+    this.yearRangeEnd = result;
220
+    if (!this.quick) {
221
+      // 不是快捷选择
222
+      this.defRange = null;
223
+    }
224
+    if (!result) {
225
+      this.startDate = this.endDate = "";
226
+      return;
227
+    }
228
+    this.endDate = format(endOfYear(result), 'yyyy-MM-dd');
229
+  }
230
+
231
+  // 日期选择 快速修改时间区间
232
+  today = new Date();
233
+  quick: boolean = false;
234
+  changeDateRange(res) {
235
+    console.log(res);
236
+    this.quick = true;
237
+    switch (res) {
238
+      case "1":
239
+        // 上周
240
+        let lastweekstartdate = this.dateService.date().lastWeekStartDate;
241
+        let lastweekenddate = this.dateService.date().lastWeekEndDate;
242
+        console.log(lastweekstartdate, lastweekenddate);
243
+        this.changeDate([lastweekstartdate, lastweekenddate]);
244
+        break;
245
+      case "2":
246
+        // 上月
247
+        let lastmonthstartdate = this.dateService.date().lastMonthStartDate;
248
+        let lastmonthenddate = this.dateService.date().lastMonthEndDate;
249
+        console.log(lastmonthstartdate, lastmonthenddate);
250
+        this.changeDate([lastmonthstartdate, lastmonthenddate]);
251
+        this.changeMonthStart(lastmonthstartdate);
252
+        this.changeMonthEnd(lastmonthenddate);
253
+        break;
254
+      case "3":
255
+        // 上年
256
+        let lastyearstartdate = this.dateService.date().lastYearStartDate;
257
+        let lastyearenddate = this.dateService.date().lastYearEndDate;
258
+        console.log(lastyearstartdate, lastyearenddate);
259
+        this.changeDate([lastyearstartdate, lastyearenddate]);
260
+        this.changeMonthStart(lastyearstartdate);
261
+        this.changeMonthEnd(lastyearenddate);
262
+        this.changeYearStart(lastyearstartdate);
263
+        this.changeYearEnd(lastyearenddate);
264
+        break;
265
+    }
266
+    this.quick = false;
267
+  }
268
+}

+ 20 - 0
src/app/views/new-statistics/components/custom-change-date/custom-change-date.module.ts

@@ -0,0 +1,20 @@
1
+import { CustomChangeDateComponent } from './custom-change-date.component';
2
+import { NgModule } from '@angular/core';
3
+import { CommonModule } from '@angular/common';
4
+
5
+import { ShareModule } from 'src/app/share/share.module';
6
+
7
+
8
+@NgModule({
9
+  declarations: [
10
+    CustomChangeDateComponent,
11
+  ],
12
+  imports: [
13
+    CommonModule,
14
+    ShareModule,
15
+  ],
16
+  exports: [
17
+    CustomChangeDateComponent,
18
+  ]
19
+})
20
+export class CustomChangeDateModule { }

+ 3 - 2
src/app/views/new-statistics/phone-statistics/date-phone-statistics/date-phone-statistics.component.html

@@ -1,10 +1,11 @@
1 1
 <div class="searchDataWrap">
2 2
   <div class="searchData">
3
-    <div class="searchDataItem">
3
+    <app-custom-change-date (customChangeDateEmit)="customChangeDateEmit($event)"></app-custom-change-date>
4
+    <!-- <div class="searchDataItem">
4 5
       <span class="label">建单时间</span>:
5 6
       <nz-range-picker [(ngModel)]="dateRange" [nzAllowClear]="false" (ngModelChange)="changeDate($event)" (nzOnCalendarChange)="onCalendarChangeDate($event)">
6 7
       </nz-range-picker>
7
-    </div>
8
+    </div> -->
8 9
     <div class="searchDataItem">
9 10
       <span class="label">统计分类</span>:
10 11
       <nz-select class="selectItem" [nzDropdownMatchSelectWidth]="false" nzAllowClear nzPlaceHolder="请选择统计分类" [(ngModel)]="statisticsTypeId" (nzOpenChange)="openChangeStatisticsType($event)">

+ 1 - 1
src/app/views/new-statistics/phone-statistics/date-phone-statistics/date-phone-statistics.component.less

@@ -27,7 +27,7 @@
27 27
           font-size: 16px;
28 28
         }
29 29
         .selectItem{
30
-          width: 224px;
30
+          width: 160px;
31 31
         }
32 32
       }
33 33
     }

+ 2 - 0
src/app/views/new-statistics/phone-statistics/date-phone-statistics/date-phone-statistics.component.ts

@@ -44,6 +44,8 @@ export class DatePhoneStatisticsComponent implements OnInit, AfterViewInit {
44 44
     }, 0)
45 45
   }
46 46
 
47
+  customChangeDateEmit(){}
48
+
47 49
   getQueryParams(){
48 50
     let queryParams = this.tabService.getQueryParams();
49 51
     this.tabService.clearQueryParams();

+ 2 - 0
src/app/views/new-statistics/phone-statistics/date-phone-statistics/date-phone-statistics.module.ts

@@ -6,6 +6,7 @@ import { DatePhoneStatisticsRoutingModule } from './date-phone-statistics-routin
6 6
 import { ShareModule } from 'src/app/share/share.module';
7 7
 import { VirtualScrollerModule } from 'ngx-virtual-scroller';
8 8
 import { PhoneSearchMoreModule } from '../../components/phone-search-more/phone-search-more.module';
9
+import { CustomChangeDateModule } from '../../components/custom-change-date/custom-change-date.module';
9 10
 
10 11
 
11 12
 @NgModule({
@@ -18,6 +19,7 @@ import { PhoneSearchMoreModule } from '../../components/phone-search-more/phone-
18 19
     ShareModule,
19 20
     VirtualScrollerModule,
20 21
     PhoneSearchMoreModule,
22
+    CustomChangeDateModule,
21 23
   ]
22 24
 })
23 25
 export class DatePhoneStatisticsModule { }