import { debounceTime } from 'rxjs/operators'; import { Subject } from 'rxjs'; import { NzMessageService } from 'ng-zorro-antd/message'; import { format, addMonths, startOfMonth, endOfMonth, startOfDay, endOfDay } from 'date-fns'; import { Component, OnInit, HostListener, AfterViewInit } from "@angular/core"; import { MainService } from 'src/app/services/main.service'; import { ActivatedRoute } from '@angular/router'; @Component({ selector: "app-department-incident-statistics", templateUrl: "./department-incident-statistics.component.html", styleUrls: ["./department-incident-statistics.component.less"], }) export class DepartmentIncidentStatisticsComponent implements OnInit, AfterViewInit { constructor( private mainService: MainService, private message: NzMessageService, private route: ActivatedRoute, ) {} listOfData: any[] = []; //表格数据 listOfDataEnd: any[] = []; //表格合计 pageIndex: number = 1; //表格当前页码 pageSize: number = 30; //表格每页展示条数 listLength: number = 0; //表格总数据量 repairDeptId;//报修科室id searchTimerSubject = new Subject(); ngOnInit() { this.searchTimerSubject.pipe(debounceTime(500)).subscribe((v) => { let fun = v[0]; fun.call(this, v[1]); }); this.initSessionData(); this.search(); } ngAfterViewInit(){ this.onResize(); } tableHeight:number = 0; @HostListener('window:resize') onResize(): void { setTimeout(() => { this.tableHeight = window.innerHeight - 64 - 64 - 36 - 48 - 8 - 45 - 54 - this.getMoreFilter; console.log('this.tableHeight:', this.tableHeight) }, 0) } get getMoreFilter(){ let flag = this.fieldConfig.fields.groupDTO || this.fieldConfig.fields.userDTO || this.fieldConfig.fields.category1DTO || this.fieldConfig.fields.category2DTO || this.fieldConfig.fields.category3DTO || this.fieldConfig.fields.sourceDTO; return flag ? 21 : 0; } // 初始化缓存数据 queryType:any; hosId:any; dutyId:any; parentDutyId:any; initSessionData(){ let maintenanceStatistics = JSON.parse(sessionStorage.getItem('maintenanceStatistics')); let queryType:any = maintenanceStatistics.queryType; let hosId:any = maintenanceStatistics.hospitalId; let dutyId:any = maintenanceStatistics.dutyId; queryType = queryType ? +queryType : 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; } } get getHosId(){ return this.parentDutyId || this.dutyId || this.hosId; } // 表格数据 loading1 = false; getList(num?: number, field?: string, sort?: string) { if (num !== undefined) { this.pageIndex = num; } let postData:any = { idx: this.pageIndex - 1, sum: this.pageSize, startDate: this.dateRange[0], endDate: this.dateRange[1], hosId: this.hosId, dutyId: this.dutyId, parentDutyId: this.parentDutyId, repairDeptId: this.repairDeptId, groupId: this.fieldConfig.fields.groupId, userId: this.fieldConfig.fields.userId, categoryId: this.fieldConfig.fields.categoryId, sourceId: this.fieldConfig.fields.sourceId, hierarchy: this.fieldConfig.fields.hierarchy, }; if (field && sort) { postData.sort = `${field} ${sort === "ascend" ? `asc` : `desc`}` } this.loading1 = true; this.mainService .postCustom("itsm/report", "incidentWorkOrder", 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 = {}; 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 = [format(startOfMonth(addMonths(new Date(), -1)), 'yyyy-MM-dd HH:mm:ss'), format(endOfMonth(addMonths(new Date(), -1)), 'yyyy-MM-dd HH:mm:ss')]; changeDate(result?): void { result[0] = format(startOfDay(result[0]), 'yyyy-MM-dd HH:mm:ss'); result[1] = format(endOfDay(result[1]), 'yyyy-MM-dd HH:mm:ss'); this.dateRange = result; } onCalendarChangeDate(dateArr){ console.log(dateArr) if(dateArr.length == 2){ this.dateRange = [format(startOfDay(dateArr[0]), 'yyyy-MM-dd HH:mm:ss'), format(endOfDay(dateArr[1]), 'yyyy-MM-dd HH:mm:ss')]; } } // 导出 excelExportLoading:any = false; excelExport(){ this.excelExportLoading = this.message.loading("导出中..", { nzDuration: 0, }).messageId; let postData:any = { startDate: this.dateRange[0], endDate: this.dateRange[1], hosId: this.hosId, dutyId: this.dutyId, parentDutyId: this.parentDutyId, repairDeptId: this.repairDeptId, groupId: this.fieldConfig.fields.groupId, userId: this.fieldConfig.fields.userId, categoryId: this.fieldConfig.fields.categoryId, sourceId: this.fieldConfig.fields.sourceId, hierarchy: this.fieldConfig.fields.hierarchy, }; if (this.sortCurrentKey && this.sortCurrentValue) { postData.sort = `${this.sortCurrentKey} ${this.sortCurrentValue === "ascend" ? `asc` : `desc`}` } this.mainService .postExportCustom("itsm/export", "incidentWorkOrder", 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 = [format(startOfMonth(addMonths(new Date(), -1)), 'yyyy-MM-dd HH:mm:ss'), format(endOfMonth(addMonths(new Date(), -1)), 'yyyy-MM-dd HH:mm:ss')] this.repairDeptId = undefined; this.fieldConfig.fields = {groupId: undefined, userId: undefined, categoryId: undefined, sourceId: undefined, hierarchy: undefined}; this.search(); } // 科室搜索 changeRepairDeptInp(e) { this.searchTimer(this.getRepairDeptList, e); } // 防抖 isLoading = false; searchTimer(fun, e) { this.isLoading = true; this.searchTimerSubject.next([fun, e]); } openChangeRepairDept(flag){ flag && this.getRepairDeptList(); } // 获取报修科室列表 repairDeptList:any[] = []; getRepairDeptList(keyword?) { let data = { department: { cascadeHosId: this.getHosId, dept: keyword, searchType: 1, }, idx: 0, sum: 20, }; this.isLoading = true; this.mainService .getFetchDataList("data", "department", data) .subscribe((data) => { this.isLoading = false; this.repairDeptList = data.list; }); } // 详细搜索 fieldConfig:any = { fields: {groupId: undefined, userId: undefined, categoryId: undefined, sourceId: undefined, hierarchy: undefined}, config: {groupAndUser: true, category123: true, source: 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(); } }