import { Component, ChangeDetectionStrategy, OnInit, ChangeDetectorRef, ElementRef } from '@angular/core'; import { NzMessageService } from 'ng-zorro-antd'; import { STColumn, XlsxService } from '@delon/abc'; import { getTimeDistance } from '@delon/util'; import { _HttpClient } from '@delon/theme'; import { I18NService } from '@core'; import { yuan } from '@shared'; import { ProjectFileService } from 'app/services/projectFile/project-file.service'; import { FbsWorkshopDispatchListService } from 'app/services/fbs/fbs-workshop-dispatch-list.service'; import { FbsAbnormalWorkingHoursService } from 'app/services/fbs/fbs-abnormal-working-hours.service'; import { FbsWorkshopDispatchList } from 'app/entity/fbs/fbs-workshop-dispatch-list'; import { convertingNumbers } from '@shared/utils/shared'; @Component({ selector: 'app-dashboard-analysis', templateUrl: './analysis.component.html', styleUrls: ['./analysis.component.less'], styles:[ ` table{ border-collapse:collapse;border:none; } th{ border:solid#000 1px; } td{ border:solid#000 1px; } .bolder{ font-weight:bolder; } ` ] // changeDetection: ChangeDetectionStrategy.OnPush, }) export class DashboardAnalysisComponent implements OnInit { data: any = {}; loading = true; date_range: Date[] = []; rankingListData: any[] = Array(7) .fill({}) .map((item, i) => { return { title: this.i18n.fanyi('app.analysis.test', { no: i }), total: 323234, }; }); titleMap = { y1: this.i18n.fanyi('app.analysis.traffic'), y2: this.i18n.fanyi('app.analysis.payments'), }; searchColumn: STColumn[] = [ { title: '排名', i18n: 'app.analysis.table.rank', index: 'index' }, { title: '搜索关键词', i18n: 'app.analysis.table.search-keyword', index: 'keyword', click: (item: any) => this.msg.success(item.keyword), }, { type: 'number', title: '用户数', i18n: 'app.analysis.table.users', index: 'count', sorter: (a, b) => a.count - b.count, }, { type: 'number', title: '周涨幅', i18n: 'app.analysis.table.weekly-range', index: 'range', render: 'range', sorter: (a, b) => a.range - b.range, }, ]; constructor( private http: _HttpClient, public msg: NzMessageService, private i18n: I18NService, private cdr: ChangeDetectorRef, private projectFileService: ProjectFileService, private fbsWorkshopDispatchListService:FbsWorkshopDispatchListService, private fbsAbnormalWorkingHoursService:FbsAbnormalWorkingHoursService, private xlsx: XlsxService ) { } ngOnInit() { // const offlineData: any[] = []; // for (let i = 0; i < 10; i += 1) { // offlineData.push({ // name: `门店${i}`, // cvr: Math.ceil(Math.random() * 9) / 10, // }); // }; // offlineData.forEach((item: any, idx: number) => { // item.show = idx === 0; // item.chart = Object.assign([], offlineData); // }); // this.http.get('/chart').subscribe((res: any) => { // res.offlineData.forEach((item: any, idx: number) => { // item.show = idx === 0; // item.chart = Object.assign([], res.offlineChartData); // }); // this.data = res; // this.loading = false; // }); this.getCircleChartData(); this.feeTotal = `¥ ${this.feeData.reduce((pre, now) => now.y + pre, 0).toFixed(2)}`; this.alertTotal = `¥ ${this.feeData.reduce((pre, now) => now.y + pre, 0).toFixed(2)}`; this.getNow(); this.getSumDispatchReport(); this.getAbnormalWorkingHoursReport(); this.getPlanningReport(); } /** * @description: 获取数据 * @param {type} * @author: 段亚鑫 */ isVisible = false; getCircleChartData() { this.projectFileService.queryStatusNum().then((response) => { this.projectFeeData = response.result.statusList; this.projectFeeTotal = response.result.sum; this.isVisible = true; this.loading = false; // this.chart.render(); }) } /** * @description: 渲染图表 * @param {type} * @author: 段亚鑫 */ chart: any; render(el: ElementRef) { const data = [{ item: '事例一', count: 40, percent: 0.4 }, { item: '事例二', count: 21, percent: 0.21 }, { item: '事例三', count: 17, percent: 0.17 }, { item: '事例四', count: 13, percent: 0.13 }, { item: '事例五', count: 9, percent: 0.09 }]; this.chart = new G2.Chart({ container: el.nativeElement, forceFit: true, height: 450, animate: false }); this.chart.source(data, { percent: { formatter: function formatter(val) { val = val * 100 + '%'; return val; } } }); this.chart.coord('theta', { radius: 0.75, innerRadius: 0.6 }); this.chart.tooltip({ showTitle: false, itemTpl: '
  • {name}: {value}
  • ' }); // 文本 this.chart.guide().html({ position: ['50%', '50%'], html: '
    主机
    200
    ', alignX: 'middle', alignY: 'middle' }); const interval = this.chart.intervalStack().position('percent').color('item').label('percent', { formatter: function formatter(val, item) { return item.point.item + ': ' + val; } }).tooltip('item*percent', function (item, percent) { percent = percent * 100 + '%'; return { name: item, value: percent }; }).style({ lineWidth: 1, stroke: '#fff' }); // this.chart.render(); interval.setSelected(data[0]); } setDate(type: any) { this.date_range = getTimeDistance(type); setTimeout(() => this.cdr.detectChanges()); } salesType = 'all'; salesPieData: any; salesTotal = 0; changeSaleType() { this.salesPieData = this.salesType === 'all' ? this.data.salesTypeData : this.salesType === 'online' ? this.data.salesTypeDataOnline : this.data.salesTypeDataOffline; if (this.salesPieData) { this.salesTotal = this.salesPieData.reduce((pre, now) => now.y + pre, 0); } this.cdr.detectChanges(); } handlePieValueFormat(value: any) { return yuan(value); } saleTabs: any[] = [{ key: 'sales', show: true }, { key: 'visits' }]; salesChange(idx: number) { if (this.saleTabs[idx].show !== true) { this.saleTabs[idx].show = true; this.cdr.detectChanges(); } } offlineIdx = 0; offlineChange(idx: number) { if (this.data.offlineData[idx].show !== true) { this.data.offlineData[idx].show = true; this.cdr.detectChanges(); } } projectFeeTotal: any = null; projectFeeData = [ // {x:'试剂/PD01',y:5.0,}, // {x:'试剂/PDA',y:2.5,}, // {x:'试剂/PR02',y:1.5,}, // {x:'检测/PD01',y:5.5,}, // {x:'检测/PDA',y:2.2,}, // {x:'检测/PR02',y:1.6,}, // {x:'会议/PD01',y:0.8,}, // {x:'会议/PDA',y:3.2,}, // {x:'会议/PR02',y:1.5,}, // {x:'培训/PD01',y:2.5,}, // {x:'培训/PDA',y:7.6,}, // {x:'培训/PR02',y:1.8,}, // {x:'会议/PD01',y:0.8,}, // {x:'会议/PDA',y:3.2,}, // {x:'人工/PR02',y:4.2,}, ]; projectFeeFormat(val: number) { // console.error(val) return val+"/个"; } feeTotal: string; feeData = [ { x: '一季度', y: 10000, }, { x: '二季度', y: 40000, }, { x: '三季度', y: 80000, }, { x: '四季度', y: 30000, }, ]; feeFormat(val: number) { return `¥ ${val.toFixed(2)}`; } alertTotal: string; alertData = [ { x: '办公费', y: 8000, }, { x: '检测费', y: 12000, }, { x: '设备采购费', y: 66000, }, { x: '培训费', y: 45000, }, ]; alertFormat(val: number) { return `¥ ${val.toFixed(2)}`; } saveLoading=false; /** * 获取报表数据 */ listOfDataSelect=null; getSumDispatchReport(){ this.saveLoading=true; this.fbsWorkshopDispatchListService.getSumDispatchReport(this.fbsWorkshopDispatchList).then((response)=>{ this.listOfData=response.result; this.defaultSwitch(); this.isSwitchChange(); if(this.listOfDataSelect===null){ this.listOfDataSelect=JSON.parse(JSON.stringify(response.result)); } //获取时间集合数据 this.getDateList(); //总效率 this.getEfficiencyTotal() this.saveLoading=false; }) } achievementRateTotal="";//总达成率 productivityTotal="";//生产率 getEfficiencyTotal(){ this.listOfData.forEach(element => { let numberOfTasksTotal=element.numberOfTasksTotal;//计划数量 let standardWorkingHoursActualTotal=element.standardWorkingHoursActualTotal;//实际标准工时 let quantityCompletedTotal=element.quantityCompletedTotal;//完成数量 let manHoursCompletedTotal=element.manHoursCompletedTotal;//完成工时 if(element.projectName==="统计"){ this.achievementRateTotal=((Number(quantityCompletedTotal)/Number(numberOfTasksTotal))*100).toFixed(1); console.log(standardWorkingHoursActualTotal) this.productivityTotal=((Number(standardWorkingHoursActualTotal)/Number(manHoursCompletedTotal))*100).toFixed(1) } }); } /** * 获取时间列集合数据 */ widthLength=0; dateList=[]; getDateList(){ if(this.listOfData&&this.listOfData.length>0){ this.dateList=this.listOfData[0].fbsWorkshopDispatchListList // this.widthLength=(this.listOfData[0].fbsWorkshopDispatchListList.length*700)+890; this.widthLength=(this.listOfData[0].fbsWorkshopDispatchListList.length*600)+840; } } /** * 异常工时统计 */ abnormalWorkingHoursList:any=[]; AbnormalWorkingHoursTotal:any={} getAbnormalWorkingHoursReport(){ this.fbsAbnormalWorkingHoursService.getAbnormalWorkingHoursReport().then((response)=>{ this.abnormalWorkingHoursList=response.result.fbsAbnormalWorkingHoursList; let attendanceHours=0;//出勤总工时 let overtimeHours=0;//加班总工时 let train=0;//其他总工时 let abnormalWorkingHours=0;//异常总工时统计 let warehouse=0;//仓库总工时统计 this.abnormalWorkingHoursList.forEach(element => { if(element.attendanceHours){ attendanceHours=attendanceHours+Number(element.attendanceHours); } if(element.overtimeHours){ overtimeHours=overtimeHours+Number(element.overtimeHours); } train=train+Number(element.train)+Number(element.meeting)+Number(element.fiveS)+Number(element.researchAndDevelopment); abnormalWorkingHours=abnormalWorkingHours+Number(element.quality)+Number(element.design)+Number(element.rework)+Number(element.materiel)+Number(element.energy)+Number(element.other)+Number(element.equipment)+Number(element.plan); warehouse=warehouse+Number(element.mixedIngredients)+Number(element.warehousing)+Number(element.pack)+Number(element.warehouseOthers) }); this.AbnormalWorkingHoursTotal.attendanceHours=attendanceHours; this.AbnormalWorkingHoursTotal.overtimeHours=overtimeHours; this.AbnormalWorkingHoursTotal.train=train; this.AbnormalWorkingHoursTotal.abnormalWorkingHours=abnormalWorkingHours; this.AbnormalWorkingHoursTotal.warehouse=warehouse; }) } fbsWorkshopDispatchList:FbsWorkshopDispatchList={}; listOfData=[] isSwitch=false;//是否显示已完成订单 isSwitchChange(){ this.listOfData.forEach(element => { if(element.status===4){ if(this.isSwitch===false){ element.isSwitch=false; }else{ element.isSwitch=true; } } }); } defaultSwitch(){ this.listOfData.forEach(element => { if(element.status===4){ element.isSwitch=false; }else{ element.isSwitch=true; } }); } /** * 导出 */ year="0"; month="0"; //初始化年月 默认当前年月 getNow(){ let date = new Date(); this.fbsWorkshopDispatchList.year=date.getFullYear()+""; if(date.getMonth()<10){ this.fbsWorkshopDispatchList.month="0"+(date.getMonth()+1) }else{ this.fbsWorkshopDispatchList.month=(date.getMonth()+1)+""; } } exportLoading=false; export(){ // let month=this.year.substring(2,4)+this.month; // this.fbsWorkshopDispatchListService.export(month).then((response)=>{ // let list=[]; // list=response.result // this.exportLoading=true; let data = []; let title = [ ['项目名称'], // 项目名称 ['生产订单号'], // 生产订单号 ['物料编码'], // 物料编码 ['物料名称'], // 物料名称 ['月度计划'], // 月度计划 ['标准工时'], // 标准工时 ['累计完成数量'], // 累计完成数量 ['累计完成工时'], // 累计完成工时 ]; data.push(title); this.listOfData.forEach(element => { let row=[]; row.push(element.projectName) row.push(element.productionOrderNumberName) row.push(element.productId) row.push(element.product) row.push(convertingNumbers(element.numberOfTasksTotal)) row.push(convertingNumbers(element.standardWorkingHoursTotal)) row.push(element.quantityCompletedTotal)//quantityCompletedTotal//latestCompletedQuantity row.push(convertingNumbers(element.manHoursCompletedTotal)) data.push(row); }); let efficiencyTotal=[ ['总达成率'], [this.achievementRateTotal+'%'], ['总生产效率'], [this.productivityTotal+'%'], ['出勤总工时'], [this.AbnormalWorkingHoursTotal.attendanceHours], ['加班总工时'], [this.AbnormalWorkingHoursTotal.overtimeHours], ['其他总工时'], [this.AbnormalWorkingHoursTotal.train], ['异常总工时统计'], [this.AbnormalWorkingHoursTotal.abnormalWorkingHours], ['仓库总工时统计'], [this.AbnormalWorkingHoursTotal.warehouse] ]; data.push(efficiencyTotal); // 导出 this.xlsx.export({ sheets: [ { data: data, name: '生产订单汇总导出', }, ], filename: '生产订单汇总导出.xlsx', }); // this.exportLoading=false; // }) } planningReportList=[] planningReportLoading=false; fbsWorkshopDispatchListPlanningReport:FbsWorkshopDispatchList={} columnTable2Width=0; getPlanningReport(){ this.planningReportLoading=true; this.fbsWorkshopDispatchListService.getPlanningReport().then((response)=>{ this.fbsWorkshopDispatchListPlanningReport=response.result; this.planningReportList=response.result.fbsWorkshopDispatchListList; this.columnTable2Width=response.result.dayList.length*25+360 this.planningReportLoading=false; }) } }