import { MsgHelper, RhStorageService } from 'rh-base/core'; import { DataResultT, RhSelectableDto, CodeClassModel, RhDynamicTableFieldDto, RhTableQueryOptionDto, RhBaseDto, RhLoginedUserDto, RhTableButtonInfoDto, RhDynamicComponentFieldType, RhSafeAny } from 'rh-base/model'; import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'; import { DynamicFormComponent } from 'rh-base/shared'; import { ProductMaterialBindedMetadataDto, ProductMaterialBindedMetadataQueryDto, ProductMaterialBindedRecordDto, ScanVerifyDto } from './../../qmp-model'; import { RhTrackManagementService } from '../track-management.service'; import { NzInputNumberComponent } from 'ng-zorro-antd/input-number'; @Component({ selector: 'rh-production-plan-track', templateUrl: './production-plan-track.component.html', styleUrls: ['./production-plan-track.component.less'] }) export class RhProductionPlanTrackComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; @ViewChild('scanInput', { static: false }) scanInput!: ElementRef; @ViewChild('bindContentInput', { static: false }) bindContentInput!: ElementRef; @ViewChild('qtyNumber', { static: false }) qtyNumber!: NzInputNumberComponent; selectedIndex = 0; dataLoading = false; VerifiedNum = 0; dataresult!: DataResultT; defaultFieldDataset: RhDynamicComponentFieldType[] = []; SNisVerified = false; // 当前登录 currentUser!: RhLoginedUserDto; /** 生产计划详情 */ ProductionPlanDetail!: RhBaseDto; bindedDatas: ProductMaterialBindedMetadataDto[] = []; isShowSubmitButton = false; style = {}; //是否正在编辑 isnumberChange = false; tipText!: string; SN!: string; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'scan', '关键件绑定', 'default', false, 'link', false, null, (data) => this.openEditTab(data as RhBaseDto), true ) ]; constructor(private operator: RhTrackManagementService, private storage: RhStorageService) { // } ngOnInit(): void { // 当前登录员 this.currentUser = this.storage.getUserSession()?.User as RhLoginedUserDto; } setDatas(dataset: DataResultT) { this.dataresult = dataset; if (!this.dataresult?.Success) { MsgHelper.ShowWarningMessage(`搜索无数据!${this.dataresult?.Message}`); } } dataLoadingChange(status: boolean) { this.dataLoading = status; } setInitFieldDatset(item: CodeClassModel) { const tempDatas: RhDynamicComponentFieldType[] = []; item.CodeProperties.forEach((ele) => { const temp = RhDynamicTableFieldDto.create(); temp.name = ele.PropertyName; temp.displayName = ele.Descirption; tempDatas.push(temp); }); this.defaultFieldDataset = [...tempDatas]; } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(option); } openEditTab(data: RhBaseDto) { // this.ProductionPlanDetail = data; this.selectedIndex = 1; //获取已绑定物料的数据 this.getProductMaterialBindedMetadataDatas(); } //调用子组件中的接口 private getDatas(option?: RhTableQueryOptionDto) { if (this.queryFormCmt) { this.queryFormCmt.submitDefaultForm(null, option); } } closeEditTab() { this.selectedIndex = 0; } getProductMaterialBindedMetadataDatas() { const queryDto = ProductMaterialBindedMetadataQueryDto.create(); queryDto.ProductCode = this.ProductionPlanDetail['ProductCode']; queryDto.ProductName = this.ProductionPlanDetail['ProductName']; this.operator.GetProductMaterialBindedMetadataDatas(queryDto).subscribe((result) => { if (result && result.Success) { this.bindedDatas = result.Attach; this.openScanInput(); } else { this.bindedDatas = []; MsgHelper.ShowWarningMessage(`暂无数据${result.Message}`); } }); } openScanInput() { this.bindedDatas.forEach((ele) => { ele['isScan'] = true; }); this.bindedDatas = [...this.bindedDatas]; } openEdit(index: number) { this.bindedDatas.forEach((ele) => { ele['isOpenEditBindedQty'] = false; }); this.bindedDatas[index]['isOpenEditBindedQty'] = true; this.bindedDatas = [...this.bindedDatas]; } closeEdit(index: number) { if (!this.isnumberChange) { this.bindedDatas[index]['isOpenEditBindedQty'] = false; this.isnumberChange = false; } else { this.openEdit(index); } } closeScanInput(index: number) { this.bindedDatas[index]['isScan'] = false; } Verify($event: RhSafeAny, BindedContent: string, index: number) { if ($event.keyCode === 27) { //取消 this.closeScanInput(index); } if ($event.keyCode === 13) { //确定 const queryDto = ScanVerifyDto.create(); queryDto.MaterialCode = this.bindedDatas[index].MaterialCode; queryDto.ProductCode = this.ProductionPlanDetail['ProductCode']; queryDto.ProductionPlanCode = this.ProductionPlanDetail['ProductionPlanCode']; queryDto.ScanCode = BindedContent; this.operator.ScanVerify(queryDto).subscribe((result) => { if (result && result.Success) { this.closeScanInput(index); this.bindedDatas[index]['isScan'] = false; if (index + 1 < this.bindedDatas.length) { this.bindedDatas[index + 1]['isScan'] = true; } else if (index + 1 == this.bindedDatas.length) { this.isShowSubmitButton = true; } else { this.isShowSubmitButton = false; } this.bindedDatas[index]['isVerified'] = true; this.VerifiedNum++; //焦点在下一个扫描物料中 this.focusOnInput(); } else { MsgHelper.ShowWarningMessage('验证失败!请再次扫描'); this.bindedDatas[index]['isVerified'] = false; } this.bindedDatas = [...this.bindedDatas]; if (this.VerifiedNum == this.bindedDatas.length && this.SNisVerified == true) { this.submitDatas(); } }); } } SnEnter($event: RhSafeAny) { if ($event.keyCode === 13) { const queryDto = ScanVerifyDto.create(); //queryDto.MaterialCode = this.bindedDatas[0].MaterialCode; queryDto.ProductCode = this.ProductionPlanDetail['ProductCode']; queryDto.ProductionPlanCode = this.ProductionPlanDetail['ProductionPlanCode']; queryDto.ScanSNCode = this.SN; this.operator.ScanVerify(queryDto).subscribe((result) => { if (result && result.Success) { this.SNisVerified = true; //焦点在下一个扫描物料中 this.focusOnInput(); } else { MsgHelper.ShowWarningMessage('SN验证失败!请再次扫描'); this.SN = ''; } }); } } // openEditBindedContent(index: number) { // this.bindedDatas.forEach((ele) => { // ele.isOpenEditBindedContent = false; // }); // this.bindedDatas[index].isOpenEditBindedContent = true; // this.bindedDatas = [...this.bindedDatas]; // } closeEditBindedContent(index: number) { this.bindedDatas[index]['isOpenEditBindedContent'] = false; } // storeBindedContent($event, BindedContent: string, index: number) { // // $event.preventDefault(); // if ($event.keyCode === 27) { // //取消 // this.closeEditBindedContent(index); // } // if ($event.keyCode === 13) { // if (!BindedContent) { // this.style = { // border: '1px solid red' // }; // this.tipText = '请填写绑定内容!'; // return false; // } else { // this.bindedDatas[index].isVerified = true; // this.style = {}; // this.tipText = null; // this.closeEditBindedContent(index); // this.openEdit(index); // //焦点在下一个扫描物料中 // this.focusOnInputNumber(); // } // } // } focusOnInput() { setTimeout(() => { if (this.scanInput) { this.scanInput.nativeElement.select(); this.scanInput.nativeElement.focus(); } }); } // focusOnBindContentInput() { // setTimeout(() => { // if (this.bindContentInput) { // this.bindContentInput.nativeElement.select(); // this.bindContentInput.nativeElement.focus(); // } // }); // } focusOnInputNumber() { setTimeout(() => { if (this.qtyNumber) { this.qtyNumber.focus(); } }); } isfocus(i: number) { this.isnumberChange = true; } storeNewBindedQty($event: RhSafeAny, index: number): void { if ($event.keyCode === 27) { //取消 this.closeEdit(index); } if ($event.keyCode === 13) { if (this.bindedDatas[index]['newDefaultBindedQty'] === 0) { this.style = { border: '1px solid red' }; this.tipText = '绑定数量需大于0'; // return false; } else { this.style = {}; this.tipText = ''; this.isnumberChange = false; this.closeEdit(index); this.bindedDatas[index].DefaultBindedQty = this.bindedDatas[index]['newDefaultBindedQty']; if (index + 1 < this.bindedDatas.length) { this.bindedDatas[index + 1]['isScan'] = true; } else if (index + 1 == this.bindedDatas.length) { this.isShowSubmitButton = true; } else { this.isShowSubmitButton = false; } //焦点在下一个扫描物料中 this.focusOnInput(); } } } updateBindedQty(index: number, e: number): boolean | void { if (e === 0) { this.style = { border: '1px solid red' }; this.tipText = '绑定数量需大于0'; return false; } else { this.style = {}; this.tipText = ''; this.bindedDatas[index]['newDefaultBindedQty'] = e; } this.isnumberChange = true; } submitDatas() { // 利用语法糖map()映射 const Datas = this.bindedDatas.map((ele) => { const temp = ProductMaterialBindedRecordDto.create(); temp.ProductCode = this.ProductionPlanDetail['ProductCode']; temp.ProductName = this.ProductionPlanDetail['ProductName']; temp.SaleOrderCode = this.ProductionPlanDetail['SaleOrderCode']; temp.MaterialCode = ele.MaterialCode; temp.MaterialName = ele.MaterialName; temp.BindedQty = ele.DefaultBindedQty; temp.ProductionPlanCode = this.ProductionPlanDetail['ProductionPlanCode']; temp.BindedContent = ele['BindedContent']; temp.BindedType = ele.BindedType; temp.OpUser = this.currentUser.UserName; temp.OpDate = new Date(); if (ele.BindedType === 'SN') { temp.SN = this.SN; } else { temp.SN = null; } // temp.ProcessCode =; // temp.ProcessName =; temp.OrganizationStructureCode = this.ProductionPlanDetail['OrganizationStructureCode']; temp.OrganizationStructureName = this.ProductionPlanDetail['OrganizationStructureName']; return temp; }); this.operator.StoreProductMaterialBindedRecordDatas(Datas).subscribe((result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage('数据存储成功'); this.SN = ''; this.bindedDatas.forEach((ele) => { ele['isVerified'] = false; ele['isScan'] = true; ele['BindedContent'] = ''; }); this.SNisVerified = false; this.VerifiedNum = 0; const snFocus = document.getElementById('SN'); snFocus?.focus(); } else { MsgHelper.ShowWarningMessage(`数据存储失败!${result.Message}`); } }); } }