import { Router } from '@angular/router'; import { format, addMonths, startOfMonth, endOfMonth } from 'date-fns'; import { Component, OnInit } from "@angular/core"; import { MainService } from 'src/app/services/main.service'; import { TabService } from '../../services/tab.service'; @Component({ selector: "app-synthesize-statistics", templateUrl: "./synthesize-statistics.component.html", styleUrls: ["./synthesize-statistics.component.less"], }) export class SynthesizeStatisticsComponent implements OnInit { constructor( private mainService: MainService, private tabService: TabService, public router: Router, ) {} isLoading:Boolean = false; workData:any = []; //工单统计 listOfData: any[] = []; //表格数据 pageIndex: number = 1; //表格当前页码 pageSize: number = 10; //表格每页展示条数 listLength: number = 10; //表格总数据量 activeIndex:any = 0; maintainData:any = []; //维修处理数据 repairsOptions:any={} //报修来源 option malfunctionOptions:any={} //一级故障 option buildingOptions:any={} //楼栋报修 option deptCostData:any = [ { name:'王' }, { name:'王' }, { name:'王' }, { name:'王' }, { name:'王' } ] //科室费用 consumableData:any = [ { name:'王' }, { name:'王' }, { name:'王' }, { name:'王' }, { name:'王' } ] //报修耗材 ngOnInit() { this.search(); } // 维修处理类型切换 selectCheck(type){ this.activeIndex = type this.getMaintainData(); } // 故障来源 repairsChart() { let postData:any = { startDate: this.dateRange[0], endDate: this.dateRange[1], type: 'sourceTop5', hosId: this.hosId, dutyId: this.dutyId, parentDutyId: this.parentDutyId, }; this.mainService .getReportData(postData) .subscribe((result:any) => { let datas = result.data.map(i=>{ return{ name:i.name, value:i.sum } }); this.repairsOptions = { tooltip: { trigger: "item", formatter: "{b}: {c} ({d}%)", }, legend: { data: datas, left: 'left', }, series: [ { name: "", type: "pie", radius: ["30%", "50%"], center:["50%","55%"], data: datas, emphasis: { itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' } }, label: { show: true, formatter: '{b}: {c} {d}%' }, itemStyle: { normal: { //每根柱子颜色设置 color: function (params) { let colorList = [ "#33CC85", "#72C0DD", "#FAC958", "#546FC6", "#d35b7e", "#778ccC", "#fad354", "#aldee0", "#ee84a8", "#8475c5", "#b0d097", "#ffadbb", "#fd8c67", "#d495e0", ]; return colorList[params.dataIndex]; }, }, }, }, ], }; }); } // 一级故障 malfunctionChart(){ let postData:any = { startDate: this.dateRange[0], endDate: this.dateRange[1], type: 'firstCategoryTop5', hosId: this.hosId, dutyId: this.dutyId, parentDutyId: this.parentDutyId, }; this.mainService .getReportData(postData) .subscribe((result:any) => { let datas = [] let title = [] for(let i of result.data){ datas.push(i.sum) title.push(i.category) } this.malfunctionOptions = { tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, xAxis: [ { type: 'category', data: title, axisTick: { show:false, alignWithLabel: true } } ], yAxis: [ { type: 'value', axisLine: { show:false }, axisTick:{ show:false } } ], series: [ { type: 'bar', barWidth: '30%', color: '#FFD68D', data: datas, label:{ show:true, position: "top", // 展示在柱子的上方 color: "#333" } } ] } }); } // 楼栋报修 buildingChart(){ let postData:any = { startDate: this.dateRange[0], endDate: this.dateRange[1], type: 'buildingTop5', hosId: this.hosId, dutyId: this.dutyId, parentDutyId: this.parentDutyId, }; this.mainService .getReportData(postData) .subscribe((result:any) => { let datas = [] let title = [] for(let i of result.data){ datas.push(i.sum) title.push(i.name) } this.buildingOptions = { tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, xAxis: [ { type: 'category', data: title, axisTick: { show:false, alignWithLabel: true } } ], yAxis: [ { type: 'value', axisLine: { show:false }, axisTick:{ show:false } } ], series: [ { type: 'bar', barWidth: '30%', color: '#72C0DD', data: datas, label:{ show:true, position: "top", // 展示在柱子的上方 color: "#333" } } ] } }); } // 科室费用 getDeptCostData() { let postData:any = { startDate: this.dateRange[0], endDate: this.dateRange[1], type: 'deptTop5', hosId: this.hosId, dutyId: this.dutyId, parentDutyId: this.parentDutyId, }; this.mainService .getReportData(postData) .subscribe((result:any) => { this.deptCostData = result.data || []; }); } // 耗材 getConsumableData() { let postData:any = { startDate: this.dateRange[0], endDate: this.dateRange[1], type: 'consumableTop5', hosId: this.hosId, dutyId: this.dutyId, parentDutyId: this.parentDutyId, }; this.mainService .getReportData(postData) .subscribe((result:any) => { this.isLoading = false; this.consumableData = result.data || []; }); } // 更多跳转 toPath(path){ let flag = this.tabService.tabs.some(v => v.path === path); flag && this.tabService.deleteRouteSnapshot(path); this.tabService.setQueryParams('dateRange', this.dateRange); this.router.navigate([path], { replaceUrl: true }); } // 判断更多是否显示 showMore(path){ let menus = JSON.parse(localStorage.getItem("menu")); return menus.find(v => v.link === 'maintenanceStatistics').childrens.some(v => v.link === path); } // 初始化缓存数据 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; } this.isLoading = true this.getWorkData(); this.getMaintainData(); this.repairsChart(); this.malfunctionChart(); this.buildingChart(); this.getDeptCostData(); this.getConsumableData(); } // 表格数据 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, }; this.loading1 = true; this.mainService .postCustom("itsm/report", "incidentWorkOrder", postData) .subscribe((result) => { this.loading1 = false; this.listOfData = result.dataList || []; this.listLength = result.totalCount; }); } // 头部工单数据 getWorkData() { let postData:any = { startDate: this.dateRange[0], endDate: this.dateRange[1], type: 'headerCount', hosId: this.hosId, dutyId: this.dutyId, parentDutyId: this.parentDutyId, }; this.mainService .getReportData(postData) .subscribe((result:any) => { this.workData = result.data[0] || []; }); } // 维修处理 getMaintainData() { let postData:any = { startDate: this.dateRange[0], endDate: this.dateRange[1], type: 'userHandleTop5', groupType: this.activeIndex==0?'user':'group', hosId: this.hosId, dutyId: this.dutyId, parentDutyId: this.parentDutyId, }; this.mainService .getReportData(postData) .subscribe((result:any) => { this.maintainData = result.data || []; }); } // 重置 reset(){ 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.activeIndex = 0; this.search(); } // 搜索 search() { this.initSessionData(); } // 日期选择 日 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(result[0], 'yyyy-MM-dd') + ' ' + '00:00:00'; result[1] = format(result[1], 'yyyy-MM-dd') + ' ' + '23:59:59'; this.dateRange = result; // this.search(); console.log(this.dateRange); } onCalendarChangeDate(dateArr){ // console.log(dateArr) // if(dateArr.length == 2){ // let dateStart = new Date(dateArr[0]); // let dateEnd = new Date(dateArr[1]); // dateStart.setHours(0,0,0); // dateEnd.setHours(23,59,59); // this.dateRange = [dateStart,dateEnd]; // } } }