import { RhMaterialDefineService } from './../../../material-define.service'; import { MaterialDocumentDto } from './../../../../mdp-model'; import { Component, OnInit, Input, Output, EventEmitter, SimpleChanges } from '@angular/core'; import { DataResultT, RhSafeAny, RhBaseDto, OpMode } from 'rh-base/model'; import { MsgHelper } from 'rh-base/core'; import { UntypedFormBuilder } from '@angular/forms'; import { Router } from '@angular/router'; import * as _ from 'lodash'; import { RhBaseDynamicService } from 'rh-base/shared'; @Component({ selector: 'rh-material-document-edit', templateUrl: './material-document-edit.component.html', styleUrls: ['./material-document-edit.component.less'] }) export class MaterialDocumentEditComponent implements OnInit { @Input() rhData!: MaterialDocumentDto; @Output() rhClose = new EventEmitter(); @Output() rhSubmit = new EventEmitter(); // editForm: FormGroup; // submitLoading = false; isShowMContent = false; isShowPContent = false; isShowSpContent = false; // protected destroy$ = new Subject(); // rhUrl: string; rhName = 'materialDocumentEditForm'; checkOptions: { label: string; value: string; checked?: boolean }[] = [ { 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.rhName, config: { type: 'supplier', displayMode: 1 } }; customerFieldData = { placeholder: '客户代码', relatedComponentName: this.rhName, config: { type: 'customer', displayMode: 1 } }; bomFieldData = { placeholder: '启用BOM编码', relatedComponentName: this.rhName, config: { type: 'bom' } }; constructor( private router: Router, private fb: UntypedFormBuilder, private operator: RhMaterialDefineService, private dynamicService: RhBaseDynamicService ) {} ngOnInit(): void { // this.rhUrl = RhRouteHelper.getRealRoute(this.router.url); // 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.editForm.get(ele.mappedName)?.patchValue(data.value[ele.sourceName]); // }); // } // }); } ngOnChanges(changes: SimpleChanges): void { const { rhData } = changes; if (rhData && rhData.currentValue) { this.rhData.OpSign = OpMode.OpEdit; this.isShowMContent = (this.checkOptions.find((f) => f.value === 'IsMaterial') as RhSafeAny).checked = !!this.rhData.IsMaterial; this.isShowPContent = (this.checkOptions.find((f) => f.value === 'IsProduct') as RhSafeAny).checked = !!this.rhData.IsProduct; this.isShowSpContent = (this.checkOptions.find((f) => f.value === 'IsSemiFinishedProduct') as RhSafeAny).checked = !!this.rhData.IsSemiFinishedProduct; // if (this.editForm) { // const temp = { ...this.rhData }; // temp['checkOptions'] = _.cloneDeep(this.checkOptions); // this.editForm.reset(temp); // } else { // this.createEditForm(this.rhData); // } } } // ngOnDestroy() { // this.destroy$.next(); // this.destroy$.complete(); // } beforeSubmit = (data: RhBaseDto) => { 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; }; close() { this.rhClose.emit(); } onSubmitInterface(result: DataResultT) { if (result && result.Success) { MsgHelper.ShowSuccessMessage('物料基础信息存储成功!'); // this.rhClose.emit(); this.rhSubmit.emit(); } else { MsgHelper.ShowWarningModal(`物料基础信息存储失败!${result.Message}`); } } // createEditForm(dto: MaterialDocumentDto) { // this.editForm = this.fb.group({ // /** 物料类别_U */ // MaterialCategory: [dto.MaterialCategory], // /** 关联旧物料编码_U */ // MappedOldMaterialCode: [dto.MappedOldMaterialCode], // /** 供应商代码_U */ // SupplierCode: [dto.SupplierCode], // SupplierName: [dto.SupplierName], // /** 计量单位_B */ // MeasureUnit: [dto.MeasureUnit], // /** ERP物料代码_U */ // MaterialErpCode: [dto.MaterialErpCode], // /** ERP物料名称_U */ // MaterialErpName: [dto.MaterialErpName], // /** ERP物料规格_U */ // MaterialErpSpecification: [dto.MaterialErpSpecification], // /** 默认车间_U */ // DefaultWorkShopCode: [dto.DefaultWorkShopCode], // /** 默认仓库_U */ // DefaultWarehouse: [dto.DefaultWarehouse], // /** 默认库位_U */ // DefaultStockPlace: [dto.DefaultStockPlace], // /** 物料状态_U */ // MaterialState: [dto.MaterialState], // /** 客户编码 */ // CustomerCode: [dto.CustomerCode], // CustomerName: [dto.CustomerName], // /** 客户产品编码 */ // CustomerProductCode: [dto.CustomerProductCode], // /** 启用BOM编码 */ // UsingBomCode: [dto.UsingBomCode], // /** 生产类型 */ // ProductionType: [dto.ProductionType], // /** 备注_U */ // Remark: [dto.Remark], // checkOptions: [_.cloneDeep(this.checkOptions)] // }); // } // submitEditForm(event: Event) { // if (event) { // event.preventDefault(); // } // this.resetMaterialTypeRelatedFields(); // FormHelper.YGSubmitForm(this.rhData, this.editForm, (dto) => { // this.submitLoading = true; // this.operator.StoreMaterialDocumentData(dto).subscribe( // (result) => { // if (result && result.Success) { // MsgHelper.ShowSuccessMessage('物料基础信息存储成功!'); // this.rhSubmit.emit(); // } else { // MsgHelper.ShowWarningModal(`物料基础信息存储失败!${result.Message}`); // } // this.submitLoading = false; // }, // () => { // this.submitLoading = false; // } // ); // }); // } 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; } // 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(); // } }