import { OpMode, RhBaseDto, DataResultT, RhSafeAny } from 'rh-base/model'; import { Component, OnInit, Output, EventEmitter, Input, SimpleChanges } from '@angular/core'; import { UntypedFormGroup } from '@angular/forms'; import { MsgHelper, ObjectHelper } from 'rh-base/core'; import * as _ from 'lodash'; @Component({ selector: 'rh-material-document-add', templateUrl: './material-document-add.component.html', styleUrls: ['./material-document-add.component.less'] }) export class MaterialDocumentAddComponent implements OnInit { @Input() rhCreatedData!: RhBaseDto; @Output() rhOnGetDatas = new EventEmitter(); @Output() rhOnReturn = new EventEmitter(); // isCollapse = true; // displayFieldCount = 52; // maxDisplayFieldCount = 16; // materialDocumentAndExtPtyDto: MaterialDocumentAndExtPtyDto; basicDto: RhSafeAny; extPtyDto: RhSafeAny; snPtyDto: RhSafeAny; // materialDocumentAndExtPtyDtoForm: FormGroup; // submitLoading = false; isShowMContent = false; isShowPContent = false; isShowSpContent = false; // protected destroy$ = new Subject(); // rhUrl: string; // rhName = 'materialDocumentAndExtPtyDtoForm'; rhBasicName = 'materialBasicInfoAddForm'; rhExtPtyName = 'materialExtPtyInfoAddForm'; basicMaterialCode: string | null = null; isSubmitBasicForm = false; isSubmitExtPty = false; refresh = true; checkOptionsSource = [ { label: '原材料', value: 'IsMaterial' }, { label: '半成品', value: 'IsSemiFinishedProduct' }, { label: '成品', value: 'IsProduct' } ]; checkOptions = [ { label: '原材料', value: 'IsMaterial' }, { label: '半成品', value: 'IsSemiFinishedProduct' }, { label: '成品', value: 'IsProduct' } ]; // measureunitFieldData = { // placeholder: '计量单位', // relatedComponentName: this.rhName, // config: { // type: 'measureunit', // relatedFieldDatas: [{ sourceName: 'MeasureUnitCode', mappedName: 'MeasureUnit' }] // } // }; // externalMaterialFieldData = { // placeholder: 'ERP物料代码', // relatedComponentName: this.rhName, // config: { // type: 'externalMaterial' // } // }; // workshopFieldData = { // placeholder: '默认车间', // relatedComponentName: this.rhName, // config: { // type: 'workshop', // relatedFieldDatas: [{ sourceName: 'OrganizationStructureCode', mappedName: 'DefaultWorkShopCode' }] // } // }; // warehouseFieldData = { // placeholder: '默认仓库', // relatedComponentName: this.rhName, // config: { // type: 'warehouse', // relatedFieldDatas: [{ sourceName: 'WarehouseCode', mappedName: 'DefaultWarehouse' }] // } // }; // storagelocationFieldData = { // placeholder: '默认库位', // relatedComponentName: this.rhName, // config: { // type: 'storagelocation', // relatedFieldDatas: [{ sourceName: 'StorageLocationCode', mappedName: 'DefaultStockPlace' }] // } // }; supplierFieldData = { placeholder: '供应商代码', relatedComponentName: this.rhBasicName, config: { type: 'supplier', displayMode: 1 } }; customerFieldData = { placeholder: '客户代码', relatedComponentName: this.rhBasicName, config: { type: 'customer', displayMode: 1 } }; bomFieldData = { placeholder: '启用BOM编码', relatedComponentName: this.rhBasicName, config: { type: 'bom' } }; // MeasureAuxUnitFieldData = { // placeholder: '辅助计量单位', // relatedComponentName: this.rhName, // config: { // type: 'measureunit', // relatedFieldDatas: [{ sourceName: 'MeasureUnitCode', mappedName: 'MeasureAuxUnit' }] // } // }; snMappedName: string | null = null; snMappedPlaceholder: string | null = null; snMappedObj = { Without: null, FixedContent: '产品条码固定内容', RangeContent: '产品条码区间规则', MarkContent: '产品条码标志位' }; snMappedPlaceholderObj = { RangeContent: '$代表需要检测的数字区间' }; stockPlaceQueryDto = {}; constructor() { // } ngOnInit(): void { // this.rhUrl = RhRouteHelper.getRealRoute(this.router.url); // this.materialDocumentAndExtPtyDto = this.initMaterialDocumentAndExtPtyDto(); this.basicDto = this.initBasicDto(); this.extPtyDto = this.initExtPtyDto(); this.snPtyDto = this.initSnPtyDto(); // this.createMaterialDocumentAndExtPtyDtoForm(this.materialDocumentAndExtPtyDto); // this.dynamicService.formCustomizeEvent$.pipe(takeUntil(this.destroy$), debounceTime(200)).subscribe((data) => { // // 添加当前所在页面网址的判断 // if (data.id === `${this.rhUrl}_${this.rhName}` && data.relatedFieldDatas.length) { // data.value = data.value || {}; // data.relatedFieldDatas.forEach((ele) => { // this.materialDocumentAndExtPtyDtoForm.get(ele.mappedName)?.patchValue(data.value[ele.sourceName]); // }); // } // }); } // ngOnDestroy() { // this.destroy$.next(); // this.destroy$.complete(); // } ngOnChanges(changes: SimpleChanges): void { const { rhCreatedData } = changes; if (rhCreatedData && rhCreatedData.currentValue) { if (this.basicMaterialCode && this.rhCreatedData['MaterialCode'] === this.basicMaterialCode) { this.basicDto = _.cloneDeep(this.rhCreatedData); } } } beforeSubmitBasicForm = (data: RhBaseDto) => { if (this.isSubmitBasicForm) { MsgHelper.ShowWarningMessage('请前往编辑页面进行修改'); return false; } data['IsMaterial'] = this.isShowMContent; data['IsProduct'] = this.isShowPContent; data['IsSemiFinishedProduct'] = this.isShowSpContent; const isValid = data['IsMaterial'] || data['IsProduct'] || data['IsSemiFinishedProduct']; if (!isValid) { MsgHelper.ShowWarningMessage('必须选择物料类型!'); return false; } data = this.resetMaterialTypeRelatedFields(data); return true; }; beforeSubmitExtPtyForm = (data: RhBaseDto) => { if (this.isSubmitExtPty) { MsgHelper.ShowWarningMessage('请前往编辑页面进行修改'); return false; } data['MaterialCode'] = this.basicMaterialCode; // console.log(data, this.basicDto); return true; }; beforeSubmitSnPtyForm = (data: RhBaseDto) => { data['MaterialCode'] = this.basicMaterialCode; return true; }; // onStoreDatas(result: DataResultT) { // if (result && result.Success) { // MsgHelper.ShowSuccessMessage('新增数据成功'); // this.resetCheckOptions(); // this.rhOnGetDatas.emit(); // } else { // MsgHelper.ShowWarningMessage(`数据存储失败!${result.Message}`); // } // } onStoreBasicDatas(result: DataResultT) { if (result && result.Success) { MsgHelper.ShowSuccessMessage('存储基础信息成功'); this.basicMaterialCode = result.Attach.MaterialCode; this.basicDto = _.cloneDeep(result.Attach); this.isSubmitBasicForm = true; // this.resetCheckOptions(); this.rhOnGetDatas.emit(this.basicMaterialCode); } else { MsgHelper.ShowWarningMessage(`数据存储失败!${result.Message}`); } } onStoreExtPtyDatas(result: DataResultT) { if (result && result.Success) { MsgHelper.ShowSuccessMessage('存储扩展信息成功'); this.isSubmitExtPty = true; // this.resetCheckOptions(); this.rhOnGetDatas.emit(); } else { MsgHelper.ShowWarningMessage(`数据存储失败!${result.Message}`); } } onStoreSnPtyDatas(result: DataResultT) { if (result && result.Success) { MsgHelper.ShowSuccessMessage('存储条码验证信息成功'); this.rhOnGetDatas.emit(); } else { MsgHelper.ShowWarningMessage(`数据存储失败!${result.Message}`); } } onDefaultWarehouseChange(data: string, fg: UntypedFormGroup) { // 每次选择默认仓库需要清空默认库位信息 if (data?.trim()) { fg.get('DefaultStockPlace')?.patchValue(null); this.stockPlaceQueryDto = { WarehouseCode: data }; } } initBasicDto() { this.isShowMContent = this.isShowPContent = this.isShowSpContent = false; const dto = ObjectHelper.createRhBaseDto(); dto.OpSign = OpMode.OpEdit; return dto; } initExtPtyDto() { const dto = ObjectHelper.createRhBaseDto(); dto.OpSign = OpMode.OpEdit; return dto; } initSnPtyDto() { const dto = ObjectHelper.createRhBaseDto(); dto['ProductSnCheckMode'] = 'Without'; this.snMappedName = null; this.snMappedPlaceholder = null; dto.OpSign = OpMode.OpEdit; return dto; } // initMaterialDocumentAndExtPtyDto(): MaterialDocumentAndExtPtyDto { // this.isShowMContent = this.isShowPContent = this.isShowSpContent = false; // const dto = MaterialDocumentAndExtPtyDto.create(); // dto.OpSign = OpMode.OpAdd; // return dto; // } // createMaterialDocumentAndExtPtyDtoForm(dto: MaterialDocumentAndExtPtyDto) { // this.materialDocumentAndExtPtyDtoForm = this.fb.group({ // /** 物料编码_C */ // MaterialCode: [dto.MaterialCode, [Validators.required]], // /** 物料名称_B_C */ // MaterialName: [dto.MaterialName, [Validators.required]], // /** 物料规格_B_C */ // MaterialSpecification: [dto.MaterialSpecification], // /** 计量单位_B_C */ // MeasureUnit: [dto.MeasureUnit], // /** 物料属性_B_C */ // MaterialAttribute: [dto.MaterialAttribute], // /** 供应商代码_U_MSP */ // SupplierCode: [dto.SupplierCode], // /** 供应商名称_U_MSP */ // SupplierName: [dto.SupplierName], // /** 客户编码_PMP */ // CustomerCode: [dto.CustomerCode], // /** 客户名称_PMP */ // CustomerName: [dto.CustomerName], // /** 客户产品编码_PMP */ // CustomerProductCode: [dto.CustomerProductCode], // /** 启用BOM编码_PMP */ // UsingBomCode: [dto.UsingBomCode], // /** 生产类型_PMP */ // ProductionType: [dto.ProductionType], // /** 物料类别_U_C */ // MaterialCategory: [dto.MaterialCategory], // /** 关联旧物料编码_U_C */ // MappedOldMaterialCode: [dto.MappedOldMaterialCode], // /** ERP物料代码_U_C */ // MaterialErpCode: [dto.MaterialErpCode], // /** ERP物料名称_U_C */ // MaterialErpName: [dto.MaterialErpName], // /** ERP物料规格_U_C */ // MaterialErpSpecification: [dto.MaterialErpSpecification], // /** 默认车间_U_C */ // DefaultWorkShopCode: [dto.DefaultWorkShopCode], // /** 默认仓库_U_C */ // DefaultWarehouse: [dto.DefaultWarehouse], // /** 默认库位_U_C */ // DefaultStockPlace: [dto.DefaultStockPlace], // /** 物料状态_U_C */ // MaterialState: [dto.MaterialState], // /** ABC分类_E */ // AbcCategory: [dto.AbcCategory], // /** 发运模式_E */ // ShippingMode: [dto.ShippingMode], // /** 管理模式_E */ // ManageMode: [dto.ManageMode], // /** 是_E */ // IsTrayLot: [dto.IsTrayLot], // /** 长_E */ // VLength: [dto.VLength], // /** 宽_E */ // VWidth: [dto.VWidth], // /** 高_E */ // VHeight: [dto.VHeight], // /** 毛重_E */ // RoughWeight: [dto.RoughWeight], // /** 图号_E */ // MaterialPictureNo: [dto.MaterialPictureNo], // /** 库存上限_E */ // InventoryLimitUpper: [dto.InventoryLimitUpper], // /** 库存下限_E */ // InventoryLimitDown: [dto.InventoryLimitDown], // /** 所属仓库_E */ // // JsonRelationWarehouse: [dto.JsonRelationWarehouse], // /** 辅助计量单位_E */ // MeasureAuxUnit: [dto.MeasureAuxUnit], // /** 转换率_E */ // ConvertRate: [dto.ConvertRate], // /** 物料等级_E */ // MaterialLevel: [dto.MaterialLevel], // /** 有效期_E */ // ExpiryDays: [dto.ExpiryDays], // /** 最小允许上料量_E */ // AllowLastFeedQty: [dto.AllowLastFeedQty], // /** 辅具数量_E */ // AssistiveItemQty: [dto.AssistiveItemQty], // /** 制程批量_E */ // ProcessBatchQty: [dto.ProcessBatchQty], // /** 超收比例(%)_E */ // OverChargeScale: [dto.OverChargeScale], // /** 安全库存数量_E */ // SafeStockQty: [dto.SafeStockQty], // /** 最小订货量_E */ // MinimumOrderQty: [dto.MinimumOrderQty], // /** 采购提前期(天)_E */ // PurchaseLeadDay: [dto.PurchaseLeadDay], // /** 生产提前期(天)_E */ // ProductLeadDay: [dto.ProductLeadDay], // /** 标准产能(H)_E */ // StandardCapacity: [dto.StandardCapacity], // /** 标准包装箱数量_E */ // StandardPackingQty: [dto.StandardPackingQty], // /** 备注 */ // Remark: [dto.Remark], // checkOptions: [_.cloneDeep(this.checkOptions)] // }); // } // submitMaterialDocumentAndExtPtyDtoForm(event: Event) { // if (event) { // event.preventDefault(); // } // const isValid = // this.materialDocumentAndExtPtyDto.IsMaterial || // this.materialDocumentAndExtPtyDto.IsProduct || // this.materialDocumentAndExtPtyDto.IsSemiFinishedProduct; // if (!isValid) { // MsgHelper.ShowWarningMessage('必须选择物料类型!'); // return; // } // this.resetMaterialTypeRelatedFields(); // FormHelper.YGSubmitForm(this.materialDocumentAndExtPtyDto, this.materialDocumentAndExtPtyDtoForm, (dto) => { // this.submitLoading = true; // this.operator.StoreMaterialDocumentAndExtPtyData(dto).subscribe( // (result) => { // if (result && result.Success) { // MsgHelper.ShowSuccessMessage('新增数据成功'); // this.resetMaterialDocumentAndExtPtyDtoForm(null); // } else { // MsgHelper.ShowWarningMessage(`数据存储失败!${result.Message}`); // } // this.submitLoading = false; // }, // () => { // this.submitLoading = false; // } // ); // }); // } // resetMaterialDocumentAndExtPtyDtoForm(event: Event) { // if (event) { // event.preventDefault(); // } // this.materialDocumentAndExtPtyDto = this.initMaterialDocumentAndExtPtyDto(); // const temp = { ...this.materialDocumentAndExtPtyDto }; // temp['checkOptions'] = _.cloneDeep(this.checkOptions); // this.materialDocumentAndExtPtyDtoForm.reset(temp); // this.rhOnGetDatas.emit(); // } onReturn() { this.rhOnReturn.emit(); } // changeIsMaterial() { // this.isShowMContent = this.materialDocumentAndExtPtyDto.IsMaterial; // // this.resetMaterialTypeRelatedFields(); // } // changeIsProduct() { // this.isShowPContent = this.materialDocumentAndExtPtyDto.IsProduct; // // this.resetMaterialTypeRelatedFields(); // } // changeIsSemiFinishedProduct() { // this.isShowSpContent = this.materialDocumentAndExtPtyDto.IsSemiFinishedProduct; // // this.resetMaterialTypeRelatedFields(); // } changeCheckOptions(event: { label: string; value: string; checked: boolean }[]) { this.isShowMContent = !!event.find((f) => f.value === 'IsMaterial')?.checked; this.isShowPContent = !!event.find((f) => f.value === 'IsProduct')?.checked; this.isShowSpContent = !!event.find((f) => f.value === 'IsSemiFinishedProduct')?.checked; } resetMaterialTypeRelatedFields(data: RhBaseDto) { const MSP = ['SupplierCode', 'SupplierName']; const PSP = ['CustomerCode', 'CustomerName', 'CustomerProductCode', 'UsingBomCode', 'ProductionType']; const isShowMSP = this.isShowMContent || this.isShowSpContent; const isShowPSP = this.isShowPContent || this.isShowSpContent; if (!isShowMSP) { MSP.forEach((name) => { data[name] = null; }); } if (!isShowPSP) { PSP.forEach((name) => { data[name] = null; }); } return data; } resetCheckOptions() { this.checkOptions = _.cloneDeep(this.checkOptionsSource); this.isShowMContent = this.isShowPContent = this.isShowSpContent = false; } addNewBasicInfo() { this.basicDto = this.initBasicDto(); this.extPtyDto = this.initExtPtyDto(); this.snPtyDto = this.initSnPtyDto(); this.basicMaterialCode = null; this.isSubmitBasicForm = false; this.isSubmitExtPty = false; this.resetCheckOptions(); this.refresh = false; setTimeout(() => { this.refresh = true; }); } changeProductSnCheckMode(mode: string, formGroup: UntypedFormGroup) { this.snMappedName = this.snMappedObj[mode as keyof typeof this.snMappedObj]; this.snMappedPlaceholder = this.snMappedPlaceholderObj[mode as keyof typeof this.snMappedPlaceholderObj] || this.snMappedName; if (!this.snMappedName) { formGroup.get('ProductSnCheckParameter')?.setValue(null); } } // changeIsEnableExpirationDate(isEnable: boolean, formgroup: FormGroup) { // if (isEnable) { // formgroup.get('ExpiryDays').setValidators(Validators.required); // formgroup.get('ExpiryUnit').setValidators(Validators.required); // } else { // formgroup.get('ExpiryDays').clearValidators(); // formgroup.get('ExpiryUnit').clearValidators(); // } // formgroup.get('ExpiryDays').updateValueAndValidity(); // formgroup.get('ExpiryUnit').updateValueAndValidity(); // } }