123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- import { TabService } from './../../services/tab.service';
- import { NzMessageService } from 'ng-zorro-antd/message';
- import { Component, OnInit, HostListener, AfterViewInit, ViewChild } from "@angular/core";
- import { MainService } from 'src/app/services/main.service';
- import { ActivatedRoute, Router } from '@angular/router';
- import cloneDeep from 'lodash-es/cloneDeep'
- import { CustomChangeDateComponent } from '../../components/custom-change-date/custom-change-date.component';
- @Component({
- selector: "app-date-business-statistics",
- templateUrl: "./date-business-statistics.component.html",
- styleUrls: ["./date-business-statistics.component.less"],
- })
- export class DateBusinessStatisticsComponent implements OnInit, AfterViewInit {
- @ViewChild('customChangeDate', { static: false }) customChangeDateComponent!: CustomChangeDateComponent;
- constructor(
- private mainService: MainService,
- private message: NzMessageService,
- private route: ActivatedRoute,
- private router: Router,
- private tabService: TabService,
- ) {}
- listOfData: any[] = []; //表格数据
- listOfDataEnd: any[] = []; //表格合计
- pageIndex: number = 1; //表格当前页码
- pageSize: number = 30; //表格每页展示条数
- listLength: number = 0; //表格总数据量
- widthConfig: any[] = [];
- ngOnInit() {}
- ngAfterViewInit(){
- this.initSessionData();
- this.getQueryParams();
- setTimeout(() => {
- this.search();
- }, 0)
- this.onResize();
- }
- tableHeight:number = 0;
- @HostListener('window:resize')
- onResize(): void {
- setTimeout(() => {
- this.tableHeight = window.innerHeight - (document.querySelector('.searchDataWrap') as HTMLElement).offsetHeight - 64 - 36 - 48 - 8 - (document.querySelector('.ant-table-header') as HTMLElement).offsetHeight - 55 - this.getMoreFilter - 2;
- }, 0)
- }
- // 数据下钻
- viewDetail1(data, type){
- let query = null
- if(type=='all'){
- query = {
- startDate: this.customChangeDateComponent.startDate || undefined,
- endDate: this.customChangeDateComponent.endDate || undefined,
- deptId: this.fieldConfig.fields.deptId,
- searchQuery:{
- statusValue: 'close',
- groupId: this.fieldConfig.fields.groupId || undefined,
- groupDTO: this.fieldConfig.fields.groupDTO || undefined,
- userId: this.fieldConfig.fields.userId || undefined,
- userDTO: this.fieldConfig.fields.userDTO || undefined,
- buildingId: this.fieldConfig.fields.buildingId || undefined,
- buildingDTO: this.fieldConfig.fields.buildingDTO || undefined,
- }
- }
- let path = '/newStatistics/distributionInspectionStatistics/incidentList'
- let flag = this.tabService.tabs.some(v => v.path === path);
- flag && this.tabService.deleteRouteSnapshot(path);
- this.tabService.setQueryParams('dateRange', [this.customChangeDateComponent.startDate, this.customChangeDateComponent.endDate]);
- this.tabService.setQueryParams('defRange', this.customChangeDateComponent.defRange);
- sessionStorage.setItem('distributionData', JSON.stringify(query))
- this.router.navigate([path], { replaceUrl: true });
- }else{
- query = {
- startDate: data.date + ' ' + '00:00:00' || undefined,
- endDate: data.date + ' ' + '23:59:59' || undefined,
- deptId: this.fieldConfig.fields.deptId,
- searchQuery:{
- statusValue: 'close',
- groupId: this.fieldConfig.fields.groupId || undefined,
- groupDTO: this.fieldConfig.fields.groupDTO || undefined,
- userId: this.fieldConfig.fields.userId || undefined,
- userDTO: this.fieldConfig.fields.userDTO || undefined,
- buildingId: this.fieldConfig.fields.buildingId || undefined,
- buildingDTO: this.fieldConfig.fields.buildingDTO || undefined,
- }
- }
- let path = '/newStatistics/distributionInspectionStatistics/incidentList'
- let flag = this.tabService.tabs.some(v => v.path === path);
- flag && this.tabService.deleteRouteSnapshot(path);
- this.tabService.setQueryParams('dateRange', [data.date + ' ' + '00:00:00', data.date + ' ' + '23:59:59']);
- this.tabService.setQueryParams('defRange', null);
- sessionStorage.setItem('distributionData', JSON.stringify(query))
- this.router.navigate([path], { replaceUrl: true });
- }
- }
- // 数据下钻
- viewDetail2(data, sublevel, type){
- let query = null
- if(type=='all'){
- query = {
- startDate: this.customChangeDateComponent.startDate || undefined,
- endDate: this.customChangeDateComponent.endDate || undefined,
- statisticsTypeId: data[sublevel.value + 'StatisticsTypeId'] ? Number(data[sublevel.value + 'StatisticsTypeId']) : -1,
- deptId: this.fieldConfig.fields.deptId,
- searchQuery:{
- statusValue: 'close',
- groupId: this.fieldConfig.fields.groupId || undefined,
- groupDTO: this.fieldConfig.fields.groupDTO || undefined,
- userId: this.fieldConfig.fields.userId || undefined,
- userDTO: this.fieldConfig.fields.userDTO || undefined,
- buildingId: this.fieldConfig.fields.buildingId || undefined,
- buildingDTO: this.fieldConfig.fields.buildingDTO || undefined,
- }
- }
- let path = '/newStatistics/distributionInspectionStatistics/incidentList'
- let flag = this.tabService.tabs.some(v => v.path === path);
- flag && this.tabService.deleteRouteSnapshot(path);
- this.tabService.setQueryParams('dateRange', [this.customChangeDateComponent.startDate, this.customChangeDateComponent.endDate]);
- this.tabService.setQueryParams('defRange', this.customChangeDateComponent.defRange);
- sessionStorage.setItem('distributionData', JSON.stringify(query))
- this.router.navigate([path], { replaceUrl: true });
- }else{
- query = {
- startDate: data.date + ' ' + '00:00:00' || undefined,
- endDate: data.date + ' ' + '23:59:59' || undefined,
- statisticsTypeId: data[sublevel.value + 'StatisticsTypeId'] ? Number(data[sublevel.value + 'StatisticsTypeId']) : -1,
- deptId: this.fieldConfig.fields.deptId,
- searchQuery:{
- statusValue: 'close',
- groupId: this.fieldConfig.fields.groupId || undefined,
- groupDTO: this.fieldConfig.fields.groupDTO || undefined,
- userId: this.fieldConfig.fields.userId || undefined,
- userDTO: this.fieldConfig.fields.userDTO || undefined,
- buildingId: this.fieldConfig.fields.buildingId || undefined,
- buildingDTO: this.fieldConfig.fields.buildingDTO || undefined,
- }
- }
- let path = '/newStatistics/distributionInspectionStatistics/incidentList'
- let flag = this.tabService.tabs.some(v => v.path === path);
- flag && this.tabService.deleteRouteSnapshot(path);
- this.tabService.setQueryParams('dateRange', [data.date + ' ' + '00:00:00', data.date + ' ' + '23:59:59']);
- this.tabService.setQueryParams('defRange', null);
- sessionStorage.setItem('distributionData', JSON.stringify(query))
- this.router.navigate([path], { replaceUrl: true });
- }
- }
- getQueryParams(){
- let queryParams = this.tabService.getQueryParams();
- this.tabService.clearQueryParams();
- if(queryParams.dateRange){
- this.dateRange = queryParams.dateRange;
- this.customChangeDateComponent.initByDate(this.dateRange);
- }
- }
- get getMoreFilter(){
- let flag = this.fieldConfig.fields.groupDTO || this.fieldConfig.fields.userDTO || this.fieldConfig.fields.buildingDTO || this.fieldConfig.fields.deptDTO;
- return flag ? 37 : 0;
- }
- // 初始化缓存数据
- queryType:any;
- hosId:any;
- dutyId:any;
- parentDutyId:any;
- async initSessionData(){
- let newStatistics = JSON.parse(sessionStorage.getItem('newStatistics'));
- let queryType:any = newStatistics.queryType;
- let realQueryType:any = newStatistics.realQueryType;
- let hosId:any = newStatistics.hospitalId;
- let dutyId:any = newStatistics.dutyId;
- let currentDeptDTO:any = newStatistics.currentDeptDTO;
- queryType = queryType ? +queryType : undefined;
- realQueryType = realQueryType ? +realQueryType : undefined;
- hosId = hosId ? +hosId : undefined;
- dutyId = dutyId ? +dutyId : undefined;
- this.queryType = queryType;
- if(queryType == 1){
- this.hosId = undefined;
- this.dutyId = undefined;
- this.parentDutyId = undefined;
- }else if(queryType == 2){
- this.hosId = hosId;
- this.dutyId = undefined;
- this.parentDutyId = undefined;
- }else if(queryType == 3){
- this.hosId = undefined;
- this.dutyId = dutyId;
- this.parentDutyId = undefined;
- }else if(queryType == 4){
- this.hosId = undefined;
- this.dutyId = undefined;
- this.parentDutyId = dutyId;
- }else if(queryType == 5){
- this.fieldConfig.fields.deptId = currentDeptDTO.id;
- let postData = {
- department: {
- id: currentDeptDTO.id,
- searchType: 1,
- },
- idx: 0,
- sum: 1,
- };
- let result:any = await this.mainService.getFetchDataList("data", "department", postData).toPromise();
- this.fieldConfig.fields.deptDTO = result.list.length ? result.list[0] : undefined;
- if(realQueryType == 1){
- this.hosId = undefined;
- this.dutyId = undefined;
- this.parentDutyId = undefined;
- }else if(realQueryType == 2){
- this.hosId = hosId;
- this.dutyId = undefined;
- this.parentDutyId = undefined;
- }else if(realQueryType == 3){
- this.hosId = undefined;
- this.dutyId = dutyId;
- this.parentDutyId = undefined;
- }else if(realQueryType == 4){
- this.hosId = undefined;
- this.dutyId = undefined;
- this.parentDutyId = dutyId;
- }
- }
- }
- get getHosId(){
- return this.parentDutyId || this.dutyId || this.hosId;
- }
- // 表格数据
- loading1 = false;
- dictionaryList: any[] = [];
- getList(num?: number, field?: string, sort?: string) {
- this.mainService.getDictionary('list', 'statistics_date_type', true).subscribe((data) => {
- this.dictionaryList = data || [];
- // this.dictionaryList = cloneDeep(dictionaryList);
- let flag = this.dictionaryList.some((item) => item.value === 'dateOther');
- // if(!dictionaryList.find(i=> i.id == -1)){
- // dictionaryList.push({id: -1, name: '未知', value: 'dateOther'});
- // }
- !flag && this.dictionaryList.push({id: -1, name: '未知', value: 'dateOther'});
- // this.dictionaryList = dictionaryList;
- this.widthConfig = new Array(this.dictionaryList.length * 3 + 3).fill('100px');
- if (num !== undefined) {
- this.pageIndex = num;
- }
- let postData:any = {
- idx: this.pageIndex - 1,
- sum: this.pageSize,
- dateType: this.customChangeDateComponent.dateType,
- startDate: this.customChangeDateComponent.startDate || undefined,
- endDate: this.customChangeDateComponent.endDate || undefined,
- hosId: this.getHosId,
- groupId: this.fieldConfig.fields.userId ? undefined : (this.fieldConfig.fields.groupId || undefined),
- userId: this.fieldConfig.fields.userId || undefined,
- buildingId: this.fieldConfig.fields.buildingId || undefined,
- deptId: this.fieldConfig.fields.deptId || undefined,
- };
- if (field && sort) {
- postData.sort = `${field} ${sort === "ascend" ? `asc` : `desc`}`
- }
- this.loading1 = true;
- this.mainService
- .postCustom("itsm/report", "dateTransOrder", postData)
- .subscribe((result) => {
- this.loading1 = false;
- this.listOfData = result.dataList.filter((v, i) => { return i != result.dataList.length - 1 });
- this.listOfDataEnd = result.dataList.filter((v, i) => { return i == result.dataList.length - 1 });
- this.listLength = result.totalCount;
- });
- });
- }
- // 列表排序
- sortCurrent:any = {};
- sortCurrentKey: string = "";
- sortCurrentValue: string | null = "";
- sort(e) {
- const { key, value } = e;
- this.sortCurrentKey = key;
- this.sortCurrentValue = value;
- this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
- }
- // 搜索
- search() {
- this.getList(1, this.sortCurrentKey, this.sortCurrentValue);
- }
- // 日期选择
- dateRange: any = [];
- // 导出
- excelExportLoading:any = false;
- excelExport(){
- this.excelExportLoading = this.message.loading("导出中..", {
- nzDuration: 0,
- }).messageId;
- let postData:any = {
- dateType: this.customChangeDateComponent.dateType,
- startDate: this.customChangeDateComponent.startDate || undefined,
- endDate: this.customChangeDateComponent.endDate || undefined,
- hosId: this.getHosId,
- groupId: this.fieldConfig.fields.userId ? undefined : (this.fieldConfig.fields.groupId || undefined),
- userId: this.fieldConfig.fields.userId || undefined,
- buildingId: this.fieldConfig.fields.buildingId || undefined,
- deptId: this.fieldConfig.fields.deptId || undefined,
- };
- if (this.sortCurrentKey && this.sortCurrentValue) {
- postData.sort = `${this.sortCurrentKey} ${this.sortCurrentValue === "ascend" ? `asc` : `desc`}`
- }
- this.mainService
- .postExportCustom("itsm/exportMergeTitle", "dateTransOrder", postData)
- .subscribe((data) => {
- this.message.remove(this.excelExportLoading);
- this.excelExportLoading = false;
- this.message.success('导出成功');
- var file = new Blob([data], {
- type: "application/vnd.ms-excel",
- });
- //trick to download store a file having its URL
- var fileURL = URL.createObjectURL(file);
- var a = document.createElement("a");
- a.href = fileURL;
- a.target = "_blank";
- a.download = `${this.route.parent.routeConfig.data.title}.xls`;
- document.body.appendChild(a);
- a.click();
- },(err) => {
- this.message.remove(this.excelExportLoading);
- this.excelExportLoading = false;
- this.message.error('导出失败');
- });
- }
- // 重置
- reset(){
- this.sortCurrentKey = "";
- this.sortCurrentValue = "";
- this.sortCurrent = {};
- this.dateRange = []
- this.fieldConfig.fields = {
- groupId: undefined,
- userId: undefined,
- buildingId: undefined,
- deptId: this.queryType == 5 ? this.fieldConfig.fields.deptId : undefined,
- deptDTO: this.queryType == 5 ? this.fieldConfig.fields.deptDTO : undefined,
- };
- this.customChangeDateComponent.resetByDate();
- setTimeout(_=>{
- this.search();
- })
- }
- // 防抖
- isLoading = false;
- // 详细搜索
- fieldConfig:any = {
- fields: {groupId: undefined, userId: undefined, buildingId: undefined, deptId: undefined},
- config: {groupAndUser: true, building: true, dept: true},
- }
- showSearchMore:boolean = false;
- showMore(){
- this.showSearchMore = true;
- }
- cancelEvent(){
- this.showSearchMore = false;
- }
- submitEvent(fields){
- this.showSearchMore = false;
- this.fieldConfig.fields = fields;
- console.log('this.fieldConfig.fields:', this.fieldConfig.fields)
- this.search();
- this.onResize();
- }
- }
|