This commit is contained in:
wangshiming
2022-04-06 14:38:10 +08:00
parent 55bd97f7f6
commit c484687413
16 changed files with 213 additions and 99 deletions

View File

@ -3,32 +3,30 @@ import { STColumn, STComponent } from '@delon/abc/st';
import { DatePipe, _HttpClient } from '@delon/theme';
import { differenceInCalendarDays } from 'date-fns';
import { DataService } from '../../../services/data.service';
import { OperationCurveComponent } from '../../operationtable/curve/curve.component';
import { DatatableCustomindexCurveComponent } from './curve/curve.component';
@Component({
selector: 'app-datatable-customindex',
templateUrl: './customindex.component.html',
styleUrls: ['./customindex.component.less'],
providers: [DatePipe]
})
export class DatatableCustomindexComponent implements OnInit {
@ViewChild('st') private readonly st!: STComponent;
@ViewChild('curve') private readonly curve!: OperationCurveComponent;
@ViewChild('curve') private readonly curve!: DatatableCustomindexCurveComponent;
type = 1;
mode = 'year';
date: any = null;
defineDate = [];
time: any = ['2022-01-01 00:00:00']
time: any = ['2022-01-01 00:00:00'];
dateFormat = 'yyyy';
today = new Date();
dateNext: any = null;
modeNext = 'year';
timeNext: any = ['2022-01-01 00:00:00']
timeNext: any = ['2022-01-01 00:00:00'];
chartData: any;
flag = false;
columns: STColumn[] = [
{ title: '用户类型', index: 'networkTransporterName', className: 'text-center' },
{ title: '用户总数', index: 'zsl', className: 'text-center' },
@ -39,18 +37,22 @@ export class DatatableCustomindexComponent implements OnInit {
{ title: '流失用户数', index: 'djd', className: 'text-center' },
{ title: '流失率', index: 'ysz', className: 'text-center' }
];
hzData: any;
hhrData: any;
sjData: any;
clData: any;
/**
* 查询参数
*/
get reqParams() {
if (this.mode === 'year') {
this.type = 1
this.type = 1;
} else if (this.mode === 'month') {
this.type = 2
this.type = 2;
} else if (this.mode === 'date') {
this.type = 3
this.type = 3;
} else {
this.type = 4
this.type = 4;
}
let params: any = {
time: this.time,
@ -61,50 +63,100 @@ export class DatatableCustomindexComponent implements OnInit {
return { ...params };
}
constructor(public service: DataService, private datePipe: DatePipe) { }
constructor(public service: DataService, private datePipe: DatePipe) {}
ngOnInit(): void {
this.initCurveData()
this.initCurveData();
}
initCurveData() {
let type = 1
let type = 1;
if (this.mode === 'year') {
type = 1
type = 1;
} else if (this.mode === 'month') {
type = 2
type = 2;
}
const params: any = {
time: this.timeNext,
type
};
this.flag = true
this.service.request(this.service.$api_operationalReportHistogram, params).subscribe(res => {
if (res) {
this.chartData = res
if (this.flag) {
this.curve.reRender()
// const params: any = {
// time: this.timeNext,
// type
// };
this.flag = true;
this.service
.request(this.service.$api_statistics_totalDetail, {
time: this.timeNext,
type: 1
})
.subscribe(res => {
if (res) {
this.chartData = res;
}
});
this.service.request(this.service.$api_statistics_totalDetail, {
time: this.timeNext,
type: 2
}).subscribe(res => {
if (res) {
this.chartData = res;
}
})
});
this.service.request(this.service.$api_statistics_totalDetail, {
time: this.timeNext,
type: 3
}).subscribe(res => {
if (res) {
this.chartData = res;
}
});
this.service.request(this.service.$api_statistics_totalDetail, {
time: this.timeNext,
type: 4
}).subscribe(res => {
if (res) {
this.chartData = res;
}
});
this.service.request(this.service.$api_statistics_total, { type: 1 }).subscribe(res => {
if (res) {
this.hzData = res;
}
});
this.service.request(this.service.$api_statistics_total, { type: 2 }).subscribe(res => {
if (res) {
this.hhrData = res;
}
});
this.service.request(this.service.$api_statistics_total, { type: 3 }).subscribe(res => {
if (res) {
this.sjData = res;
}
});
this.service.request(this.service.$api_statistics_total, { type: 4 }).subscribe(res => {
if (res) {
this.clData = res;
}
});
}
changeData() {
if (this.mode === 'year') {
this.dateFormat = 'yyyy'
this.dateFormat = 'yyyy';
} else if (this.mode === 'month') {
this.dateFormat = 'yyyy-MM'
this.dateFormat = 'yyyy-MM';
} else {
this.dateFormat = 'yyyy-MM-dd'
this.dateFormat = 'yyyy-MM-dd';
}
}
onChange(result: any) {
if (this.mode === 'year') {
this.time = [this.datePipe.transform(this.date, 'yyyy') + '-01-01 00:00:00']
this.time = [this.datePipe.transform(this.date, 'yyyy') + '-01-01 00:00:00'];
} else if (this.mode === 'month') {
this.time = [this.datePipe.transform(this.date, 'yyyy-MM') + '-01 00:00:00']
this.time = [this.datePipe.transform(this.date, 'yyyy-MM') + '-01 00:00:00'];
} else if (this.mode === 'date') {
this.time = [this.datePipe.transform(this.date, 'yyyy-MM-dd') + ' 00:00:00']
this.time = [this.datePipe.transform(this.date, 'yyyy-MM-dd') + ' 00:00:00'];
} else {
this.time = [this.datePipe.transform(this.defineDate[0], 'yyyy-MM-dd') + '00:00:00', this.datePipe.transform(this.defineDate[1], 'yyyy-MM-dd') + ' 00:00:00']
this.time = [
this.datePipe.transform(this.defineDate[0], 'yyyy-MM-dd') + '00:00:00',
this.datePipe.transform(this.defineDate[1], 'yyyy-MM-dd') + ' 00:00:00'
];
}
this.st.reload({ ...this.reqParams });
}
@ -112,24 +164,22 @@ export class DatatableCustomindexComponent implements OnInit {
// Can not select days before today and today
differenceInCalendarDays(current, this.today) > 0;
changeDataNext() {
if(this.mode === 'year') {
this.dateFormat = 'yyyy'
} else if(this.mode === 'month') {
this.dateFormat = 'yyyy-MM'
if (this.mode === 'year') {
this.dateFormat = 'yyyy';
} else if (this.mode === 'month') {
this.dateFormat = 'yyyy-MM';
}
}
onChangeNext(result: any) {
if(result === null) {
return
if (result === null) {
return;
}
if(this.mode === 'year') {
this.timeNext = [this.datePipe.transform(this.dateNext, 'yyyy') + '-01-01 00:00:00']
} else if(this.mode === 'month') {
this.timeNext = [this.datePipe.transform(this.dateNext, 'yyyy-MM') + '-01 00:00:00']
if (this.mode === 'year') {
this.timeNext = [this.datePipe.transform(this.dateNext, 'yyyy') + '-01-01 00:00:00'];
} else if (this.mode === 'month') {
this.timeNext = [this.datePipe.transform(this.dateNext, 'yyyy-MM') + '-01 00:00:00'];
}
this.initCurveData()
this.initCurveData();
}
}