import { RhQmpService } from './../../../../qmp.service'; import { MsgHelper } from 'rh-base/core'; import { RhBaseDto, DataResultT, RhSafeAny, RhGenericTreeNode, ProcessRoutingOutPutDto } from 'rh-base/model'; import { IpqcProductInspectSchemaQueryDto, IpqcProductCreatedInspectSchemaDto, EmployeeMessageNotifyGroupConfigDto, ProcessInspectRulesDto, ProcessRoutingEntryDto, EmployeeMessageNotifyGroupConfigQueryDto, SelectedProcessDto } from './../../../../qmp-model'; import { RhProcessControlService } from './../../../process-control.service'; import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; import { NzTreeNode } from 'ng-zorro-antd/tree'; type ProcessRouteTreeNodeType = ProcessRoutingOutPutDto | ProcessRoutingEntryDto; @Component({ selector: 'rh-ipqc-process-route-schema', templateUrl: './ipqc-process-route-schema.component.html', styleUrls: ['./ipqc-process-route-schema.component.less'] }) export class IpqcProcessRouteSchemaComponent implements OnInit { @Input() rhProcessRouteCode!: string; @Input() rhMaterial!: { MaterialCode: string; MaterialName: string; MaterialSpecification: string }; @Input() rhInspectCategoryInEdit: { label: string; value: string; checked?: boolean; disabled?: boolean }[] = []; // @Input() rhEditDto: RhBaseDto = {}; @Output() rhClose = new EventEmitter(); routeQueryDto: RhSafeAny = null; startDate!: Date; endDate!: Date; qualityInspectGroup: EmployeeMessageNotifyGroupConfigDto[] = []; editDto!: IpqcProductCreatedInspectSchemaDto | RhSafeAny; inspectRuleDto: ProcessInspectRulesDto | null = null; selectedNode!: RhGenericTreeNode; /** 当前的编辑模式:单个编辑还是批量编辑(使用checkbox) */ editType: 'single' | 'batch' = 'single'; dataHandler = (data: RhBaseDto) => { // data.ValidStartDate = this.startDate; // data.ValidEndDate = this.endDate; // 检验类别赋值 data['ProductCode'] = this.rhMaterial.MaterialCode; data['ProductName'] = this.rhMaterial.MaterialName; data['ProductSpecification'] = this.rhMaterial.MaterialSpecification; this.rhInspectCategoryInEdit.forEach((ele) => { data[ele.value] = ele.checked; }); if (this.inspectRuleDto) { data['InspectRulesDto'] = this.inspectRuleDto; } if (this.editType === 'single') { // 选中单个工序 if (this.selectedNode?.isLeaf) { const nodeData = this.selectedNode.origin.customData as ProcessRoutingEntryDto; // 设置已选择工序 // 设置已选择工序 data['SelectedProcess'] = [ SelectedProcessDto.create( nodeData.ProcessRoutingEntryCode as string, nodeData.ProcessCode as string, nodeData.ProcessName as string ) ]; data['ProcessRoutingCode'] = nodeData.ProcessRoutingCode; data['ProcessRoutingName'] = nodeData['ProcessRoutingName']; data['ProcessCode'] = nodeData.ProcessCode; } else { if (!this.selectedNode) { MsgHelper.ShowWarningMessage(`请先选择工序或者工艺路线!`); return false; } // 选中了工艺路线 const nodeData = this.selectedNode.origin.customData as ProcessRoutingOutPutDto; data['ProcessRoutingCode'] = nodeData.ProcessRoutingCode; data['ProcessRoutingName'] = nodeData.ProcessRoutingName; } } else { // 批量操作 // 批量操作 data['SelectedProcess'] = this.editDto.SelectedProcess; if (!data?.['SelectedProcess']?.length) { MsgHelper.ShowWarningMessage(`请先选择工序!`); return false; } const nodeData = this.selectedNode.origin.customData as ProcessRoutingOutPutDto; data['ProcessRoutingCode'] = nodeData.ProcessRoutingCode; data['ProcessRoutingName'] = nodeData.ProcessRoutingName; } return true; }; constructor(private operator: RhProcessControlService, private qmpSer: RhQmpService) { // } ngOnInit(): void { this.editDto = this.editDto || this.initEditDto(); this.getQualityInspectGroup(); this.routeQueryDto = this.rhProcessRouteCode ? { ProcessRoutingCode: this.rhProcessRouteCode } : null; } close() { this.rhClose.emit(); } onSelectNodeChange(node: RhGenericTreeNode) { this.selectedNode = node; const queryDto = IpqcProductInspectSchemaQueryDto.create(); queryDto.ProcessRoutingCode = this.rhProcessRouteCode; queryDto.ProductCode = this.rhMaterial.MaterialCode; // 选中的是工序节点 if (node.isLeaf) { queryDto.ProcessRoutingEntryCode = (node?.origin.customData as ProcessRoutingEntryDto).ProcessRoutingEntryCode; } else { // 选中的是工艺路线节点 queryDto.ProcessRoutingCode = (node?.origin.customData as ProcessRoutingOutPutDto).ProcessRoutingCode; } this.operator.GetIpqcProductCreatedInspectSchemaData(queryDto).subscribe((result) => { this.editDto = result?.Success ? result.Attach : this.initEditDto(); this.editDto.IsUse = true; this.editDto.ProductCode = this.editDto.ProductCode || this.rhMaterial.MaterialCode; this.editDto.ProductName = this.editDto.ProductName || this.rhMaterial.MaterialName; this.editDto.ProductSpecification = this.editDto.ProductSpecification || this.rhMaterial.MaterialSpecification; // 刷新检验类别数据 this.rhInspectCategoryInEdit.forEach((ele) => { ele.checked = this.editDto[ele.value]; // 新建时已经选中的检验类型无法编辑 ele.disabled = ele.checked; }); }); } onStoreNewSchemaData(result: DataResultT) { if (result && result.Success) { MsgHelper.ShowSuccessMessage(`保存数据成功!`); this.inspectRuleDto = null; this.rhClose.emit(); } else { MsgHelper.ShowWarningModal(`存储数据失败!${result.Message}`); } } onCheckBoxChange(nodes: NzTreeNode[]) { this.editDto = this.initEditDto(); this.rhInspectCategoryInEdit.forEach((ele) => { ele.checked = false; ele.disabled = false; }); this.editType = 'batch'; if (nodes?.length) { this.editDto.SelectedProcess = this.getSelectProcessDatas(nodes); } } setStartAndEndDate(dates: Date[]) { if (!dates || dates?.length < 2) { return; } this.startDate = new Date(dates[0]); this.endDate = new Date(dates[1]); } onEditInspectRuleChange(data: ProcessInspectRulesDto) { this.inspectRuleDto = data; } private initEditDto(): IpqcProductCreatedInspectSchemaDto { const temp = IpqcProductCreatedInspectSchemaDto.create(); temp.ProductCode = this.rhMaterial.MaterialCode; temp.ProductName = this.rhMaterial.MaterialName; temp.ProductSpecification = this.rhMaterial.MaterialSpecification; temp.IsUse = true; return temp; } // 获取检验组 private getQualityInspectGroup() { const queryDto = EmployeeMessageNotifyGroupConfigQueryDto.create(); queryDto.IsEnable = true; queryDto.Mode = 8; queryDto.ModuleKey = 'QualityManagement'; this.qmpSer.GetEmployeeMessageNotifyGroupConfigDatas(queryDto).subscribe((result) => { if (result && result.Success) { this.qualityInspectGroup = result.Attach; } else { this.qualityInspectGroup = []; } }); } private getSelectProcessDatas(nodes: NzTreeNode[]): SelectedProcessDto[] { this.selectedNode = nodes[0] as RhSafeAny; const tempDatas: SelectedProcessDto[] = []; nodes.forEach((ele) => { if (ele.children.length) { ele.children.forEach((innerEle) => { const nodeData = innerEle.origin['customData'] as ProcessRoutingEntryDto; tempDatas.push( SelectedProcessDto.create( nodeData.ProcessRoutingEntryCode as string, nodeData.ProcessCode as string, nodeData.ProcessName as string ) ); }); } else { // 判断是不是工序节点 const nodeData = ele.origin['customData'] as ProcessRoutingEntryDto; if (nodeData.ProcessCode) { tempDatas.push( SelectedProcessDto.create( nodeData.ProcessRoutingEntryCode as string, nodeData.ProcessCode as string, nodeData.ProcessName as string ) ); } } }); return tempDatas; } }