import { RhFactoryLayoutService } from './../factory-layout.service'; import { Component, OnInit, ViewChild } from '@angular/core'; import { CodeClassModel, DataResultT, OpMode, RhBaseDto, RhDynamicComponentFieldType, RhDynamicTableFieldDto, RhInterfaceLocationDto, RhSafeAny, RhSelectableDto, RhSelectItem, RhTableButtonInfoDto, RhTableQueryOptionDto } from 'rh-base/model'; import { NzTreeNode } from 'ng-zorro-antd/tree'; import { MsgHelper } from 'rh-base/core'; import { DynamicFormComponent } from 'rh-base/shared'; import { OrderStatusParasDto, OrderStatusParasQueryDto, OrganizationStructureTreeNode, WorkShopLineExtProperyQueryDto, WorkShopLineInfoDto, WorkShopLineInfoQueryDto, WorkShopLineReportParameterBatchStoreDto } from '../../mdp-model'; import { FormHelper, ObjectHelper, RhApiUrlsService } from 'rh-base/core'; import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; type displayDto = RhSelectableDto & { name: string; displayName: string; }; @Component({ selector: 'rh-workshop-line-info-setting', templateUrl: './workshop-line-info-setting.component.html', styleUrls: ['./workshop-line-info-setting.component.less'] }) export class RhWorkshopLineInfoSettingComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; treeName = '组织架构'; nodeDatas: NzTreeNode[] = []; selectedNode: NzTreeNode | null = null; selectedIndex = 0; editDto: RhBaseDto = {}; dataLoading = false; dataresult!: DataResultT; isShowEditModal = false; defaultFieldDataset: RhDynamicComponentFieldType[] = []; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('edit', '编辑', 'default', false, 'edit', false, null, (data) => this.openEditModal(data as RhBaseDto), true), new RhTableButtonInfoDto( 'calendar', '关联工厂日历', 'default', false, 'calendar', false, null, (data) => this.openMappedCalendarModal(data as WorkShopLineInfoDto), true ) ]; titleButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto( // 'configuration', // '参数配置', // 'default', // 'setting', // false, // null, // () => this.openParameterConfigurationTab(), // true // ) ]; extraButtonDataset: RhTableButtonInfoDto[] = []; isShowMappedCalendarModal = false; mapping = false; selectedCalendarData: RhSelectableDto | null = null; selectedData: WorkShopLineInfoDto | null = null; // selectedDatas: WorkShopLineInfoDto[] = []; workShopDatas: WorkShopLineInfoDto[] = []; // 参数配置 isShowParConfigTab = false; businessType: OrderStatusParasDto[] = []; reportParDto: RhBaseDto = {}; // 报工参数 workShopDataset!: displayDto[]; checkedWorkShopDataset: displayDto[] = []; batchValue: RhBaseDto = {}; // 批量配置 batchStoreForm!: UntypedFormGroup; batchStoreDto!: WorkShopLineReportParameterBatchStoreDto; submitBatchDatasLoading = false; selectedGoodWareHouseData!: RhSelectableDto; /** 选中的业务类型 */ selectedBusinessType!: string; /** 当前选择的生产模式 */ productionMode: string | null = null; // 生产模式列表 productionModeList: RhSelectItem[] = []; // 派工对象列表 dispatcherList: RhSelectItem[] = []; /** 是否启用开工 */ isUseStartProduction = false; /** 是否启用分派 */ isUseDispatchProduction = false; /** 是否启用超额汇报 */ isUseOverReport = false; /** 是否启用第三方汇报 */ isUseTheThirdPartyReport = false; /** 是否启用接收数量 */ isUseReceived = false; /** 是否允许部分报工 */ isUsePartReport = true; goodWareHouseFieldData = { placeholder: '良品仓库', relatedComponentName: 'ProductionParameter', config: { type: 'warehouse', displayMode: 1, relatedModelDatas: [ { sourceName: 'WarehouseCode', mappedName: 'ReportInGoodWareHouseCode' }, { sourceName: 'WarehouseName', mappedName: 'ReportInGoodWareHouseName' } ], relatedFieldDatas: [ { sourceName: 'WarehouseCode', mappedName: 'ReportInGoodWareHouseCode' }, { sourceName: 'WarehouseName', mappedName: 'ReportInGoodWareHouseName' } ] } }; inScrapedWareHouseFieldData = { placeholder: '报废品仓库', relatedComponentName: 'ProductionParameter', config: { type: 'warehouse', displayMode: 1, relatedModelDatas: [ { sourceName: 'WarehouseCode', mappedName: 'ReportInScrapedWareHouseCode' }, { sourceName: 'WarehouseName', mappedName: 'ReportInScrapedWareHouseName' } ], relatedFieldDatas: [ { sourceName: 'WarehouseCode', mappedName: 'ReportInScrapedWareHouseCode' }, { sourceName: 'WarehouseName', mappedName: 'ReportInScrapedWareHouseName' } ] } }; // 批量form goodWareHouseFieldDataBatch = { placeholder: '良品仓库', relatedComponentName: 'batchProductionParameter', config: { type: 'warehouse', displayMode: 1, relatedModelDatas: [ { sourceName: 'WarehouseCode', mappedName: 'ReportInGoodWareHouseCode' }, { sourceName: 'WarehouseName', mappedName: 'ReportInGoodWareHouseName' } ], relatedFieldDatas: [ { sourceName: 'WarehouseCode', mappedName: 'ReportInGoodWareHouseCode' }, { sourceName: 'WarehouseName', mappedName: 'ReportInGoodWareHouseName' } ] } }; inScrapedWareHouseFieldDataBatch = { placeholder: '报废品仓库', relatedComponentName: 'batchProductionParameter', config: { type: 'warehouse', displayMode: 1, relatedModelDatas: [ { sourceName: 'WarehouseCode', mappedName: 'ReportInScrapedWareHouseCode' }, { sourceName: 'WarehouseName', mappedName: 'ReportInScrapedWareHouseName' } ], relatedFieldDatas: [ { sourceName: 'WarehouseCode', mappedName: 'ReportInScrapedWareHouseCode' }, { sourceName: 'WarehouseName', mappedName: 'ReportInScrapedWareHouseName' } ] } }; /** 是否启用流转卡 */ isUseFlowCard = false; constructor(private operator: RhFactoryLayoutService, private apiUrl: RhApiUrlsService, private fb: UntypedFormBuilder) { // } ngOnInit(): void { this.getBusinessTypes(); this.getWorkShopLineList(); // 生产执行参数配置相关 this.getProductionModeList(); this.getDispatchingObjectList(); this.batchStoreDto = this.initBatchStoreDto(); this.createBatchStoreForm(this.batchStoreDto); } beforeSubmit = (data: RhBaseDto) => { data['WorkShopLineInfoDtos'] = this.batchValue['WorkShopLineInfoDtos']; return true; }; selectedIndexChange(index: number) { if (index === 0) { this.isShowEditModal = this.isShowParConfigTab = false; } } openEditModal(data?: RhBaseDto) { // if (data) { this.editDto = data; this.editDto.OpSign = OpMode.OpEdit; } else { this.editDto = {}; this.editDto.OpSign = OpMode.OpAdd; } this.selectedIndex = 1; this.isShowEditModal = true; } closeEditModal() { // this.selectedIndex = 0; this.isShowEditModal = false; } setDatas(result: DataResultT) { if (result.pureInputPara && this.selectedNode) { this.selectedNode.isSelected = false; this.selectedNode = null; } this.dataresult = result; if (!result || !result.Success) { MsgHelper.ShowInfoMessage(`查询无数据!${this.dataresult.Message}`); } } dataLoadingChange(status: boolean) { this.dataLoading = status; } onSelectNode(node: NzTreeNode) { if (node?.origin?.['customData']) { this.selectedNode = node; const nodeData = node.origin['customData'] as OrganizationStructureTreeNode; if (!['WorkShop', 'ProductShop'].includes(nodeData.OrganizationType)) { MsgHelper.ShowWarningMessage(`请选中车间或者产线节点!`); return; } // 使用精确查询 const tempDto = { WorkShopCode: `$${nodeData.OrganizationStructureCode}`, OrganizationType: `${nodeData.OrganizationType}` }; this.getDatas(void 0, tempDto); } } onStoreData(result: DataResultT) { if (result && result.Success) { const msg = this.editDto.OpSign === OpMode.OpAdd ? '新增' : '编辑'; MsgHelper.ShowSuccessMessage(`${msg}数据成功!`); if (this.editDto.OpSign === OpMode.OpEdit) { this.selectedIndex = 0; } this.editDto = ObjectHelper.createRhBaseDto(); this.getDatas(); } else { MsgHelper.ShowWarningModal(`存储数据失败!${result.Message}`); } } 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); } // 调用子组件中的接口 private getDatas(option?: RhTableQueryOptionDto, queryDto?: { [prop: string]: string }) { if (this.queryFormCmt) { this.queryFormCmt.submitDefaultForm(null, option, queryDto); } } //#region 关联工厂日历 openMappedCalendarModal(data: WorkShopLineInfoDto) { this.selectedData = data; this.isShowMappedCalendarModal = true; } closeMappedCalendarModal() { this.isShowMappedCalendarModal = false; this.selectedData = null; this.selectedCalendarData = null; } onSelectedCalendarData(datas: RhSelectableDto[] | RhSelectableDto) { if (Array.isArray(datas)) { if (datas && datas.length) { this.selectedCalendarData = datas[0]; } else { this.selectedCalendarData = null; } } else { if (datas) { this.selectedCalendarData = datas; } else { this.selectedCalendarData = null; } } } mappedCalendar() { (this.selectedData as WorkShopLineInfoDto).FactoryCalendarCode = this.selectedCalendarData?.['FactoryCalendarCode'] as string; this.mapping = true; this.operator.StoreWorkLineInfoData(this.selectedData as WorkShopLineInfoDto).subscribe( (result) => { if (result.Success) { MsgHelper.ShowSuccessMessage('关联工厂日历成功!'); this.closeMappedCalendarModal(); this.getDatas(); } else { MsgHelper.ShowWarningMessage(`关联工厂日历失败!${result.Message}`); } this.mapping = false; }, () => { this.mapping = false; } ); } //#endregion // // 获取车间/产线信息并存入list getWorkShopLineList() { this.getWorkShopLineListPromise(); } getWorkShopLineListPromise() { return new Promise((resolve) => { const queryDto = WorkShopLineInfoQueryDto.create(); queryDto.Mode = 8; this.operator.GetWorkShopLineInfoDatas(queryDto).subscribe( (result) => { if (result && result.Success) { this.workShopDatas = result.Attach; this.workShopDataset = result.Attach.map((ele) => { return { name: ele.OrganizationStructureCode as string, displayName: ele.OrganizationStructureName as string }; }); } else { this.workShopDatas = []; this.workShopDataset = []; MsgHelper.ShowWarningMessage(`获取车间/产线列表失败!`); } resolve(result); }, (e) => resolve(e) ); }); } // 获取BusinessType[] getBusinessTypes() { const queryDto = OrderStatusParasQueryDto.create(); queryDto.BusinessTypeCode = 'WorkShopLineBusinessType'; this.operator.GetOrderStatusParasDatas(queryDto).subscribe((result) => { if (result && result.Success) { this.businessType = result.Attach.reverse(); /** 选中业务类型默认为第一个 */ this.selectedBusinessType = this.businessType[0].OrderStatusName as string; } else { MsgHelper.ShowWarningMessage(`获取车间产线业务类型数据失败!`); this.businessType = []; this.selectedBusinessType = ''; } }); } initParConfigDtos() { this.businessType.forEach((ele) => { ele.ParDto = {}; ele.ParDto.OpSign = OpMode.OpEdit; }); } async openParameterConfigurationTab() { if (!this.businessType?.length) { MsgHelper.ShowWarningModal(`车间产线业务类型数据为空,无法进行参数编辑。请至开发工具箱页面配置后重试!`); return; } await this.getWorkShopLineListPromise(); this.initParConfigDtos(); this.isShowParConfigTab = true; this.selectedIndex = 1; // 默认选中第一条数据 this.workShopDataset[0].select = true; this.onSelectWorkShopData(this.workShopDataset[0]); } closeParameterConfigurationTab() { this.isShowParConfigTab = false; this.selectedIndex = 0; this.checkedWorkShopDataset = []; this.workShopDataset.forEach((item) => { item.select = false; item.check = false; }); } // 获取数据的通用方法(参数类型和对应接口进行匹配) getParConfigFormData(business: string) { const queryDto = WorkShopLineExtProperyQueryDto.create(); queryDto.OrganizationStructureCode = this.selectedData?.OrganizationStructureCode; const index = this.businessType.findIndex((ele) => ele.OrderStatusName === business); // console.log(business); switch (business) { // 生产执行参数 case 'ProductionParameter': // this.getParameterData('GetWorkShopLineReportParameterData',index); this.operator.GetWorkShopLineProductionParameterData(queryDto).subscribe((result) => { if (result && result.Success) { this.businessType[index].ParDto = result.Attach; ObjectHelper.MapT(this.selectedData as WorkShopLineInfoDto, this.businessType[index]?.ParDto); } else { this.businessType[index].ParDto = {}; } this.setProductionParameterItems(this.businessType[index].ParDto); this.businessType[index].ParDto.OpSign = OpMode.OpEdit; }); break; // 计划导入参数 case 'PlanImportParameter': // this.getParameterData('GetWorkShopLineProductionParameterData', index); this.operator.GetWorkShopLinePlanImportParameterData(queryDto).subscribe((result) => { if (result && result.Success) { this.businessType[index].ParDto = result.Attach; ObjectHelper.MapT(this.selectedData as WorkShopLineInfoDto, this.businessType[index].ParDto); } else { this.businessType[index].ParDto = {}; } this.businessType[index].ParDto.OpSign = OpMode.OpEdit; }); break; default: this.businessType[index].ParDto = {}; this.businessType[index].ParDto.OpSign = OpMode.OpEdit; break; } } getParameterData(interfaceName: string, index: number) { const interfaceDto: RhInterfaceLocationDto = { interfaceType: 'post', port: 52880, controllerName: 'FactoryLayoutWebApi', interfaceName: interfaceName }; this.apiUrl .httpHandler(interfaceDto, { OrganizationStructureCode: this.selectedData?.OrganizationStructureCode }) .subscribe((result) => { if (result && result.Success) { this.businessType[index].ParDto = result.Attach; ObjectHelper.MapT(this.selectedData as WorkShopLineInfoDto, this.businessType[index].ParDto); } else { this.businessType[index].ParDto = {}; } this.businessType[index].ParDto.OpSign = OpMode.OpEdit; }); } onSelectWorkShopData(item: displayDto) { this.workShopDataset.forEach((ele) => (ele.check = false)); this.checkedWorkShopDataset = []; // 获取到对应的车间产线信息 this.productionMode = null; this.selectedData = this.workShopDatas.find((ele) => ele.OrganizationStructureCode === item.name) as WorkShopLineInfoDto; this.getParConfigFormData(this.selectedBusinessType); } // 保存 onStoreParConfig(result: DataResultT) { this.batchValue; if (result && result.Success) { MsgHelper.ShowSuccessMessage(`配置成功`); if (this.checkedWorkShopDataset.length > 0) { this.businessType.forEach((ele) => (ele.ParDto = {})); this.businessType = [...this.businessType]; this.workShopDataset.forEach((ele) => (ele.check = false)); this.checkedWorkShopDataset = []; } } else { MsgHelper.ShowWarningModal(`配置失败!${result.Message}`); } } onCheckWorkShopData() { this.checkedWorkShopDataset = []; // this.batchStoreDto = this.initBatchStoreDto(); // this.createBatchStoreForm(this.batchStoreDto); this.batchValue['WorkShopLineInfoDtos'] = []; this.checkedWorkShopDataset = this.workShopDataset.filter((ele) => ele.check); if (this.checkedWorkShopDataset.length > 0) { this.workShopDataset.forEach((ele) => (ele.select = false)); this.checkedWorkShopDataset.forEach((ele) => { const dto = this.workShopDatas.find((item) => item.OrganizationStructureCode === ele.name); // this.batchStoreDto.WorkShopLineInfoDtos.push(dto); this.batchValue['WorkShopLineInfoDtos'].push(dto); this.batchValue = { ...this.batchValue }; }); } else { this.clearDatas(); } this.setProductionParameterItems(); } clearDatas() { this.businessType.forEach((ele) => (ele.ParDto = {})); this.businessType = [...this.businessType]; this.workShopDataset.forEach((ele) => (ele.check = false)); this.checkedWorkShopDataset = []; } // ********** 批量配置 ********** initBatchStoreDto(): WorkShopLineReportParameterBatchStoreDto { const dto = WorkShopLineReportParameterBatchStoreDto.create(); return dto; } createBatchStoreForm(dto: WorkShopLineReportParameterBatchStoreDto) { this.batchStoreForm = this.fb.group({ /** 报工入良品仓库编码 */ ReportInGoodWareHouseCode: [dto.WorkShopLineInfoDtos, [Validators.required]], /** 报工入良品仓库名称 */ ReportInGoodWareHouseName: [dto.ReportInGoodWareHouseCode, [Validators.required]], /** 报工入报废品仓库编码 */ ReportInScrapedWareHouseCode: [dto.ReportInScrapedWareHouseCode, [Validators.required]], /** 报工入报废品仓库名称 */ ReportInScrapedWareHouseName: [dto.ReportInScrapedWareHouseName, [Validators.required]] }); } resetBatchStoreForm($event: Event | null) { if ($event) { $event.preventDefault(); } this.batchStoreDto = this.initBatchStoreDto(); this.batchStoreForm.reset(this.batchStoreDto); } onSelectGoodWareHouse() { setTimeout(() => { if (this.batchStoreDto.ReportInGoodWareHouseCode) { this.batchStoreForm.get('ReportInGoodWareHouseName')?.setValue(this.batchStoreDto.ReportInGoodWareHouseName); } }); } onSelectInScrapedWareHouse() { setTimeout(() => { if (this.batchStoreDto.ReportInScrapedWareHouseCode) { this.batchStoreForm.get('ReportInScrapedWareHouseName')?.setValue(this.batchStoreDto.ReportInScrapedWareHouseName); } }); } submitBatchStoreForm($event: Event) { if ($event) { $event.preventDefault(); } this.submitBatchDatasLoading = true; // console.log(this.batchStoreDto, this.batchStoreForm.value); FormHelper.YGSubmitForm( this.batchStoreDto, this.batchStoreForm, (dto) => { this.operator.StoreWorkShopLineReportParameterDatas(dto as WorkShopLineReportParameterBatchStoreDto).subscribe((result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage(`批量配置成功`); this.clearDatas(); this.resetBatchStoreForm(null); } else { MsgHelper.ShowWarningMessage(`批量配置失败:${result.Message}`); } this.submitBatchDatasLoading = false; }); }, () => { this.submitBatchDatasLoading = false; } ); } /** 切换tab页动作 */ selectedTabChange(business: string) { if (this.selectedBusinessType === 'business') { return; } else { this.selectedBusinessType = business; this.getParConfigFormData(business); } } //#region 生产执行参数字段显隐配置 // 获取生产模式列表 getProductionModeList() { this.apiUrl.GetOrderStatusSelectItems('WorkShopLineProductionMode').subscribe((result) => { if (result && result.Success) { this.productionModeList = result.Attach; } else { this.productionModeList = []; } }); } // 获取派工对象list getDispatchingObjectList() { this.apiUrl.GetOrderStatusSelectItems('ProductionDispatchingObject').subscribe((result) => { if (result && result.Success) { this.dispatcherList = result.Attach; } else { this.dispatcherList = []; } }); } // 设置相关数据 setProductionParameterItems(dto?: RhBaseDto) { if (dto) { this.productionMode = dto['ProductionMode']; this.isUseStartProduction = dto['isUseStartProduction']; this.isUseDispatchProduction = dto['isUseDispatchProduction']; this.isUseOverReport = dto['isUseOverReport']; this.isUseTheThirdPartyReport = dto['isUseTheThirdPartyReport']; this.isUseReceived = dto['isUseReceived']; } else { this.productionMode = null; this.isUseStartProduction = false; this.isUseDispatchProduction = false; this.isUseOverReport = false; this.isUseTheThirdPartyReport = false; this.isUseReceived = false; } } setProductionMode(mode: string, form: UntypedFormGroup) { this.productionMode = mode; if (form) { if (mode === 'DiscreteMode') { // 离散模式下清空是否自动下达和派工对象的数据 form.get('IsUseDispatchAutoIssued')?.patchValue(false); form.get('DispatchingObject')?.patchValue(null); } else if (mode === 'PlanDispatch') { // 计划派工模式下清空是否启用流转卡、是否启用接收数量和是否启用部分报工的数据 form.get('IsUseFlowCard')?.patchValue(false); form.get('IsUseReceived')?.patchValue(false); form.get('IsUsePartReport')?.patchValue(false); } } } // 是否启用开工 setIsUseStartProduction(isUse: boolean, form: UntypedFormGroup) { this.isUseStartProduction = isUse; if (form) { form.get('IsUseReceived')?.patchValue(null); form.get('IsUsePartReport')?.patchValue(false); } } // 是否启用分派 setIsUseDispatchProduction(isUse: boolean, form: UntypedFormGroup) { this.isUseDispatchProduction = isUse; if (form) { form.get('DispatchingObject')?.patchValue(null); } } // 是否启用超额汇报 setIsUseOverReport(isUse: boolean, form: UntypedFormGroup) { this.isUseOverReport = isUse; if (form) { form.get('OverReportScale')?.patchValue(null); } } // 是否启用第三方汇报 setIsUseTheThirdPartyReport(isUse: boolean, form: UntypedFormGroup) { this.isUseTheThirdPartyReport = isUse; if (form) { form.get('ReportInScrapedWareHouseCode')?.patchValue(null); form.get('ReportInScrapedWareHouseName')?.patchValue(null); form.get('ReportInGoodWareHouseCode')?.patchValue(null); form.get('ReportInGoodWareHouseName')?.patchValue(null); } } // 是否启用接收数量 setIsUseReceived(isUse: boolean, form: UntypedFormGroup) { this.isUseReceived = isUse; if (isUse) { this.isUsePartReport = false; } else { this.isUsePartReport = true; } if (form) { form.get('IsUsePartReport')?.patchValue(false); } } // 是否启用流转卡 setIsUseFlowCard(isUse: boolean, form: UntypedFormGroup) { this.isUseFlowCard = isUse; if (form) { form.get('IsUseProductionWipData')?.patchValue(false); } } //#endregion 生产执行参数字段显隐配置 // }