import { NzTreeNode } from 'ng-zorro-antd/tree'; import { RhDynamicComponentFieldType, RhSelectItem } from 'rh-base/model'; import { ProcessRoutingOutPutDto, ProductProcessRouteDto, ProductProcessRouteQueryDto, View_ProductProcessDto } from './../../mdp-model'; import { Component, OnInit, ViewChild } from '@angular/core'; import { CodeClassModel, DataResultT, OpMode, RhBaseDto, RhDynamicTableFieldDto, RhSafeAny, RhTableButtonInfoDto, RhTableQueryOptionDto } from 'rh-base/model'; import { UntypedFormBuilder } from '@angular/forms'; import { RhProcessRouteService } from '../process-route.service'; import { MsgHelper, ObjectHelper, RhNavigatorService } from 'rh-base/core'; import { DynamicFormComponent, MaterialTreeComponent } from 'rh-base/shared'; @Component({ selector: 'rh-product-process-route-manage', templateUrl: './product-process-route-manage.component.html', styleUrls: ['./product-process-route-manage.component.less'] }) export class RhProductProcessRouteManageComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; @ViewChild('bindProcessQueryForm', { static: false }) bindProcessQueryForm!: DynamicFormComponent; @ViewChild('materialTree', { static: false }) materialTreeCmt!: MaterialTreeComponent; selectedIndex = 0; dataresult!: DataResultT; defaultFieldDataset: RhDynamicComponentFieldType[] = []; dataLoading = false; editDto: RhBaseDto = {}; /** 绑定的工艺路线集合 */ ProcessRouteItems: RhSelectItem[] = []; /** 选中的工艺路线 */ selectedProcessRoute: RhSelectItem | null = null; /** 是否显示绑定的工艺路线 */ isShowGrandsonNode = false; editButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto('edit', '编辑', 'default', 'edit', false, null, (data) => this.openEditTab(data as RhBaseDto), true) new RhTableButtonInfoDto('maintainProcessRoute', '维护工艺路线', 'default', false, 'link', false, null, (data) => this.openMaintainStageTab(data as RhBaseDto) ) ]; titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('bind', '关联工艺路线', 'primary', false, 'link', false, null, () => this.openProcessModal(), true) // new RhTableButtonInfoDto('newButton', '新建', 'primary', 'file', false, null, () => this.openEditTab(), true) ]; // 工序维护 selectedProductProcessDto!: View_ProductProcessDto; defaultQueryDto: RhSafeAny = {}; //产品树内选中的产品 selectedProduct: RhSafeAny; //选中的产品节点信息 SelectedNode!: NzTreeNode; /** 物料关联工艺路线 */ isOpenProcessModal = false; /** 工艺路线 */ bindProcessDataresult = { Attach: [] as ProcessRoutingOutPutDto[] } as DataResultT; /** 选中的工艺路线 */ selectedProcesses: ProcessRoutingOutPutDto[] = []; constructor(private operator: RhProcessRouteService, public fb: UntypedFormBuilder, private navigator: RhNavigatorService) { // } ngOnInit(): void { // } setDatas(dataset: DataResultT) { this.dataresult = dataset; } setInitFieldDataset(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]; } dataLoadingChange(status: boolean) { this.dataLoading = status; } openEditTab(data?: RhBaseDto) { if (data) { this.editDto = data; this.editDto.OpSign = OpMode.OpEdit; } else { this.editDto = {}; this.editDto.OpSign = OpMode.OpAdd; } this.selectedIndex = 1; } closeEditTab() { this.selectedIndex = 0; } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(option); } private getDatas(option?: RhTableQueryOptionDto) { if (this.queryFormCmt) { const queryDto: RhSafeAny = {}; queryDto.ProductCode = this.selectedProduct?.MaterialCode; queryDto.ProductName = this.selectedProduct?.MaterialName; if (this.SelectedNode) { if (this.SelectedNode.level === 2) { queryDto.ProcessRoutingCode = this.selectedProcessRoute?.Value; } else if (this.SelectedNode.level === 1) { queryDto.ProcessRoutingCode = null; } } // 保证查询条件不同,去触发表单重新查询 if (ObjectHelper.equal(queryDto, this.defaultQueryDto)) { this.defaultQueryDto = { ...queryDto, ...{ default: null } }; } else { this.defaultQueryDto = { ...queryDto }; } setTimeout(() => { this.queryFormCmt.submitDefaultForm(null, option); }, 100); } } onStoreDatas(result: DataResultT) { if (result && result.Success) { const msg = this.editDto.OpSign === OpMode.OpAdd ? '新增' : '编辑'; MsgHelper.ShowSuccessMessage(`${msg}数据成功`); this.selectedIndex = 0; this.getDatas(); } else { MsgHelper.ShowWarningMessage(`数据存储失败!${result.Message}`); } } /** 跳转至工艺路线页面 */ // gotoAddProcessRoute() { // this.navigator.navigatorTrigger('RH_ProcessRouteManage'); // } openMaintainStageTab(data: RhBaseDto) { this.selectedProductProcessDto = data as View_ProductProcessDto; this.selectedIndex = 1; } closeMaintainStageTab() { this.selectedIndex = 0; } upgradeSuccess() { this.getDatas(); } // SelectedProductCode(item: RhSafeAny) { // this.selectedProduct = item; // this.getDatas(); // /** 获取绑定的工艺路线集合 */ // this.getBindingProcessRouteItems(); // } getSelectedNode(node: NzTreeNode) { if (node) { this.SelectedNode = node; if (node.origin['customData']) { const data = node.origin['customData']; if (node.level === 2 && node.isSelected) { this.selectedProduct = node.parentNode?.origin['customData']; this.selectedProcessRoute = data; this.getDatas(); } if (node.level === 1 && node.isSelected) { node.isExpanded = true; this.selectedProduct = data; this.getDatas(); /** 获取绑定的工艺路线集合 */ this.getBindingProcessRouteItems(); } } else { this.selectedProcessRoute = null; this.selectedProduct = null; } } } getBindingProcessRouteItems() { this.isShowGrandsonNode = true; if (this.SelectedNode.level === 1) { this.ProcessRouteItems = []; const queryDto = ProductProcessRouteQueryDto.create(); queryDto.ProductCode = this.selectedProduct?.MaterialCode; queryDto.ProductName = this.selectedProduct?.MaterialName; this.operator.GetProductBindingProcessRouteItems(queryDto).subscribe((result) => { if (result && result.Success) { this.ProcessRouteItems = result.Attach; } else { this.ProcessRouteItems = []; } }); } } getProcessRouteInfo(ProcessRoute: RhSelectItem) { this.selectedProcessRoute = ProcessRoute; this.getDatas(); } /******************************物料关联工艺路线******************************************** */ //打开工艺路线列表 openProcessModal() { if (!this.SelectedNode) { MsgHelper.ShowInfoMessage(`请先在左侧的物料树列表中选择物料!`); return; } const node = this.SelectedNode; if (node.level === 1) { this.isOpenProcessModal = true; } else { MsgHelper.ShowWarningMessage('请选择物料'); // return false; } } //关闭工艺路线列表 closeProcessModal() { this.isOpenProcessModal = false; this.selectedProcesses = []; this.resetSelected(); } setBindProcessDatas(dataset: DataResultT) { this.bindProcessDataresult = dataset; } refreshProcessDatas(option: RhTableQueryOptionDto) { this.getProcessRouteDatas(option); } private getProcessRouteDatas(option?: RhTableQueryOptionDto) { if (this.bindProcessQueryForm) { this.bindProcessQueryForm.submitDefaultForm(null, option); } } /** 选中的工艺路线数据 */ selectedProcessDatas(datas: ProcessRoutingOutPutDto[]) { const selectDatas = datas; const bindDatas = this.ProcessRouteItems; if (selectDatas?.length && bindDatas?.length) { for (let i = 0; i < selectDatas.length; i++) { for (let j = 0; j < bindDatas.length; j++) { if (selectDatas[i] && selectDatas[i]?.ProcessRoutingCode === bindDatas[j].Value) { MsgHelper.ShowWarningMessage(`该工艺路线(${selectDatas[i].ProcessRoutingName})已被绑定,请选择其他的工艺路线!`); selectDatas[i].select = false; selectDatas.splice(i, 1); } } } } this.selectedProcesses = selectDatas; } //点击确定 confirmProcessSelect() { // 利用语法糖map()映射 const queryDto = this.selectedProcesses.map((ele) => { const temp = {} as ProductProcessRouteDto; temp.ProcessRoutingCode = ele.ProcessRoutingCode; temp.ProcessRoutingName = ele.ProcessRoutingName; temp.ProductCode = this.selectedProduct?.MaterialCode; temp.ProductName = this.selectedProduct?.MaterialName; return temp; }); this.operator.StoreProductProcessRouteDatas(queryDto).subscribe((result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage('数据存储成功'); this.materialTreeCmt.selectTreeNode(this.SelectedNode); this.getDatas(); this.closeProcessModal(); } else { MsgHelper.ShowWarningMessage(`数据存储失败!${result.Message}`); } }); } resetSelected() { this.bindProcessDataresult.Attach.forEach((ele) => { ele.select = false; }); this.bindProcessDataresult = { ...this.bindProcessDataresult }; } }