import { Component, OnInit, ViewChild } from '@angular/core'; import { _HttpClient, ModalHelper } from '@delon/theme'; import { STColumn, STComponent, XlsxService } from '@delon/abc'; import { SFSchema } from '@delon/form'; import { FbsWorkingStatistics } from 'app/entity/fbs/fbs-working-statistics'; import { FbsWorkingStatisticsService } from 'app/services/fbs/fbs-working-statistics.service'; import { FbsPersonnelService } from 'app/services/fbs/fbs-personnel.service'; import { DatePipe } from '@angular/common'; import { NzNotificationService, NzModalService } from 'ng-zorro-antd'; import { FbsScanCodeUpdateTimeComponent } from '../update-time/update-time.component'; @Component({ selector: 'app-fbs-scan-code-list', templateUrl: './list.component.html', }) export class FbsScanCodeListComponent implements OnInit { constructor( private fbsWorkingStatisticsService: FbsWorkingStatisticsService, private fbsPersonnelService: FbsPersonnelService, private datePipe: DatePipe, private nzNotificationService: NzNotificationService, private nzModalService: NzModalService, private xlsx: XlsxService ) {} ngOnInit() { this.getList(); this.getProperList(); this.getTotalList(); } dataList = []; //表格数据 isLoading = false; //表格加载 //分页参数 page = { total: 0, current: 0, size: 0, }; fbsWorkingStatistics: FbsWorkingStatistics = {}; //派工单对象 /** * 查询按钮 */ query() { this.fbsWorkingStatistics.pageNo = 1; //主数据刷新 this.getList(); //计算各个合计 this.getTotalList(); } // 按页码查询 pageIndexChange(event) { this.fbsWorkingStatistics.pageNo = event; //主数据刷新 this.getList(); } /** * 主数据查询 */ getList() { this.isLoading = true; //时间格式化 this.fbsWorkingStatistics.start = this.datePipe.transform(this.fbsWorkingStatistics.start, 'yyyy-MM-dd'); this.fbsWorkingStatistics.end = this.datePipe.transform(this.fbsWorkingStatistics.end, 'yyyy-MM-dd'); this.fbsWorkingStatisticsService.list(this.fbsWorkingStatistics).then(response => { if (response.success) { //查询成功 this.dataList = response.result.records; //表格数据 this.page = response.result; //分页数据 // this.getTotal();//查询总计//计算各个合计 this.getTotalList(); this.isLoading = false; } }); } /** * 计算各个总计 */ getTotalList() { this.fbsWorkingStatistics.start = this.datePipe.transform(this.fbsWorkingStatistics.start, 'yyyy-MM-dd'); this.fbsWorkingStatistics.end = this.datePipe.transform(this.fbsWorkingStatistics.end, 'yyyy-MM-dd'); let fbsWorkingStatistics = JSON.parse(JSON.stringify(this.fbsWorkingStatistics)); fbsWorkingStatistics.pageSize = -1; this.fbsWorkingStatisticsService.list(fbsWorkingStatistics).then(response => { if (response.success) { //查询成功 let dataList = response.result.records; //表格数据 this.getTotal(dataList); //查询总计 this.isLoading = false; } }); } /** * 初始化总计变量 */ totalList: any = {}; initializationTotal() { this.totalList = { workingHoursTotal: 0, qualifiedNumberTotal: 0, }; } /** * 计算工时、数量总计 */ getTotal(dataList) { this.initializationTotal(); dataList.forEach(element => { this.totalList.workingHoursTotal += Number(element.workingHours); this.totalList.qualifiedNumberTotal += Number(element.qualifiedNumber); }); this.totalList.workingHoursTotal = this.totalList.workingHoursTotal.toFixed(1); this.totalList.qualifiedNumberTotal = this.totalList.qualifiedNumberTotal.toFixed(1); } /** * 初始化人员下拉数据集合 */ properList = []; getProperList() { // this.fbsWorkshopDispatchListService.getPerAndDerp().then((response)=>{ // this.properList=response.result // }) this.fbsPersonnelService.list({ pageSize: 1000 }).then(response => { this.properList = response.result.records; }); } update(item) { const modal = this.nzModalService.create({ nzTitle: '修改', nzWidth: '50%', nzContent: FbsScanCodeUpdateTimeComponent, nzComponentParams: { id: item.id, }, nzFooter: [ { //取消 label: '取消', type: 'default', onClick: model => { model.close(); }, }, { label: '保存', type: 'primary', onClick: model => { // model.save().then(()=>{ // this.getList() // }) model.save().then(() => { this.fbsWorkingStatisticsService.updateTime(model.fbsWorkingStatistics).then(response => { if (response.success) { this.nzNotificationService.success('修改成功', ''); //刷新list列表 model.close(); this.getList(); this.isLoading = false; } else { this.nzNotificationService.error('修改失败', response.message); this.isLoading = false; } }); }); }, }, ], }); } /** * 取消报工 */ cancelWorkReport(item){ if(!item.rueck&&!item.rmzhl){ this.nzNotificationService.warning('SAP确认号与计数器为空,不能取消报工', ''); return; } this.fbsWorkingStatisticsService.cancelWorkReport(item).then(response=>{ if (response.success) { this.nzNotificationService.success('取消成功', ''); //刷新list列表 this.getList(); this.isLoading = false; } else { this.nzNotificationService.error('取消失败', response.message); this.isLoading = false; } }) } view() {} /** * 导出 */ exportLoading=false; export() { this.exportLoading=true; //时间格式化 // this.fbsWorkingStatistics.start = this.datePipe.transform(this.fbsWorkingStatistics.start, 'yyyy-MM-dd'); // this.fbsWorkingStatistics.end = this.datePipe.transform(this.fbsWorkingStatistics.end, 'yyyy-MM-dd'); let fbsWorkingStatistics =JSON.parse(JSON.stringify(this.fbsWorkingStatistics)); fbsWorkingStatistics.pageNo=1 fbsWorkingStatistics.pageSize = -1; this.fbsWorkingStatisticsService.list(fbsWorkingStatistics).then(response => { if (response.success) { //查询成功 let dataList = response.result.records; //表格数据 let data=[]; //设置导出头 let title=[ ['项目编号'], ['项目名称'], ['人员编码'], ['姓名'], ['订单编号'], ['物料编码'], ['物料名称'], ['工艺流程'], ['上岗时间'], ['下岗时间'], ['扫码信息'], ['工时'], ['完成数量'] ] data.push(title); //添加导出行数据 if(dataList){ dataList.forEach(element => { let row=[]; row.push(element.costItemCode) row.push(element.projectName) row.push(element.personnelCode) row.push(element.personnelName) row.push(element.orderNumber) row.push(element.materielCode) row.push(element.materielName) row.push(element.fbsTechnologicalProcessItemName) row.push(element.firstTime) row.push(element.finalTime) row.push(element.finalInfo) row.push(element.workingHours) row.push(element.qualifiedNumber) data.push(row) }); data.push([ '总计', '', '', '', '', '', '', '', '', '', this.totalList.workingHoursTotal, this.totalList.qualifiedNumberTotal ]) } // 导出 this.xlsx.export({ sheets: [ { data: data, name: '扫码记录', }, ], filename: '扫码记录.xlsx', }); this.exportLoading = false; } }); } reportExportLoading=false reportExport(){ this.reportExportLoading=true; let fbsWorkingStatistics =JSON.parse(JSON.stringify(this.fbsWorkingStatistics)); this.fbsWorkingStatisticsService.getReportExport(fbsWorkingStatistics).then(response => { if (response.success) { //查询成功 let dataList = response.result; //表格数据 let data=[]; //设置导出头 let title=[ ['项目编号'], ['项目名称'], ['原价代码'], ['WBS元素'], ['WBS元素描述'], ['报工WBS'], ['网络号'], ['网络活动号'], ['完工成度'], ['过账日期'], ['正常工时'], ['单位'], ['完工数量'] ] data.push(title); //添加导出行数据 if(dataList){ dataList.forEach(element => { let row=[]; row.push(element.costItemCode) row.push(element.projectName) row.push(element.originalPriceCode) row.push(element.wbsElement) row.push(element.wbsElementDescription) row.push(element.workReportWbs) row.push(element.workReportNetwork) row.push(element.workReportingActivities) row.push(element.speedOfProgress) row.push(this.datePipe.transform(fbsWorkingStatistics.end, 'yyyyMMdd')) row.push(element.workingHours) row.push('H') row.push(element.qualifiedNumber) data.push(row) }); } // 导出 this.xlsx.export({ sheets: [ { data: data, name: '报表导出', }, ], filename: '报表导出.xlsx', }); this.reportExportLoading = false; }else{ this.nzNotificationService.error('导出失败', response.message); this.reportExportLoading = false; } }) } }