import { UntypedFormGroup } from '@angular/forms'; import { Component, OnInit, ViewChild } from '@angular/core'; import { DynamicFormComponent, RhBaseDynamicService } from 'rh-base/shared'; import { RhBaseDto, DataResultT, RhSelectableDto, RhTableButtonInfoDto, OpMode, RhSafeAny, CodeClassModel, RhDynamicTableFieldDto, RhTableQueryOptionDto, RhSelectItem, RhDynamicInterfaceDto, RhLoginedUserDto, WithNil } from 'rh-base/model'; import { MsgHelper, ObjectHelper, RhApiUrlsService, RhRouteHelper, FormHelper, RhStorageService } from 'rh-base/core'; import { RhInventoryControlService } from '../inventory-control.service'; import { MaterialInventoryLockConfigDto } from '../../inventory-manage-model'; import { Router } from '@angular/router'; @Component({ selector: 'rh-inventory-lock', templateUrl: './inventory-lock.component.html', styleUrls: ['./inventory-lock.component.less'] }) export class RhInventoryLockComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; selectedIndex = 0; editDto: RhBaseDto = {}; dataLoading = false; dataresult!: DataResultT; defaultFieldDataset: RhDynamicTableFieldDto[] = []; editButtonDataset: RhTableButtonInfoDto[] = []; titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('new', '新建', 'primary', false, 'file', false, null, () => this.openEditTab(), true) ]; extraButtonDataset: RhTableButtonInfoDto[] = []; currentUser: WithNil; collapseQueryDto: RhBaseDto = {}; defaultQueryDto: RhBaseDto = {}; materialInventoryDetailQueryDto: RhBaseDto = {}; defaultQueryDtoStorageLocation: RhBaseDto = {}; lockTypes: RhSelectItem[] = []; currentLockType: string | undefined; url: string; beforeSubmit = (data: RhBaseDto, context: DynamicFormComponent) => { if (this.currentLockType === 'Custom') { const fields = ['MaterialCode', 'LotNum', 'WarehouseCode', 'StorageLocationCode', 'FactoryCode']; if (fields.every((f) => !data[f])) { MsgHelper.ShowWarningMessage('必须填写至少一项锁库内容!'); return false; } } data['LockType'] = this.currentLockType; data['IsLocked'] = true; context.submitLoading = true; this.storeMaterialInventoryLockConfigDatas( [data] as MaterialInventoryLockConfigDto[], () => { context.submitLoading = false; }, () => { context.defaultDto = ObjectHelper.createRhBaseDto(); context.resetDto = ObjectHelper.createRhBaseDto(); context.relatedDto = ObjectHelper.createRhBaseDto(); FormHelper.resetForm(context.defaultForm); // context.defaultForm.reset(); // this.resetEditDto(); } ); return false; }; constructor( private apiUrls: RhApiUrlsService, private operator: RhInventoryControlService, public dynamicSer: RhBaseDynamicService, public router: Router, public storage: RhStorageService ) { this.url = RhRouteHelper.getRealRoute(this.router.url); } ngOnInit(): void { this.getLockTypeDatas(); this.currentUser = this.storage.getUserSession()?.User; // this.defaultQueryDto = { FactoryCode: this.currentUser?.FactoryCode }; } resetEditDto() { this.editDto = { OpSign: OpMode.OpAdd, __flag: new Date().getTime() }; } initDefaultQueryDto(dto: RhSafeAny) { this.collapseQueryDto = dto; this.defaultQueryDto = { ...this.defaultQueryDto, ...this.collapseQueryDto }; } getValueChange() { this.defaultQueryDto = { ...this.defaultQueryDto, ...this.collapseQueryDto }; setTimeout(() => { this.getDatas(); }); } openEditTab() { this.editDto = ObjectHelper.createRhBaseDto(); this.lockTypeChange(0); this.selectedIndex = 1; } closeEditTab() { this.selectedIndex = 0; } setDatas(dataset: DataResultT) { this.dataresult = dataset; if (!this.dataresult?.Success) { MsgHelper.ShowWarningMessage(`搜索无数据!${this.dataresult?.Message}`); } } dataLoadingChange(status: boolean) { this.dataLoading = status; } setInitFieldDataset(item: CodeClassModel) { const tempDatas: RhDynamicTableFieldDto[] = []; 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) { if (this.queryFormCmt) { this.queryFormCmt.submitDefaultForm(null, option); } } storeMaterialInventoryLockConfigDatas(datas: MaterialInventoryLockConfigDto[], cb: () => void, onOk?: () => void) { this.operator.StoreMaterialInventoryLockConfigDatas(datas).subscribe( (result) => { if (result.Success) { MsgHelper.ShowSuccessMessage('保存锁库配置成功!'); this.getDatas(); if (onOk) onOk(); } else { MsgHelper.ShowWarningMessage(`保存锁库配置失败!${result.Message}`); } cb(); }, () => cb() ); } getLockTypeDatas() { this.apiUrls.getSettingEntry('Wms', 'MaterialInventory', 'MaterialInventoryLockType').subscribe((result) => { if (result.Success) { this.lockTypes = result.Attach; const CustomIndex = this.lockTypes.findIndex((f) => f.Value === 'Custom'); if (CustomIndex !== -1 && CustomIndex !== 0) { this.lockTypes.splice(0, 0, this.lockTypes[CustomIndex]); this.lockTypes.splice(CustomIndex + 1, 1); } } }); } selectedIndexChange(index: number) { if (index === 0) { this.materialInventoryDetailQueryDto = {}; } } lockTypeChange(index: number) { this.currentLockType = this.lockTypes[index]?.Value?.toString(); this.materialInventoryDetailQueryDto = {}; this.editDto = { OpSign: OpMode.OpAdd, __flag: new Date().getTime() }; } onMaterialCodeChange(code: string, formgroup: UntypedFormGroup) { if (code !== this.materialInventoryDetailQueryDto['MaterialCode']) { this.materialInventoryDetailQueryDto = { ...this.materialInventoryDetailQueryDto, MaterialCode: code }; } if (!code) { formgroup.get('LotNum')?.setValue(null); } } onWarehouseCodeChange(code: string, formgroup: UntypedFormGroup) { if (code) { this.defaultQueryDtoStorageLocation = { WarehouseCode: code }; } else { this.defaultQueryDtoStorageLocation = { WarehouseCode: null }; formgroup.get('StorageLocationCode')?.setValue(null); formgroup.get('StorageLocationName')?.setValue(null); } if (code !== this.materialInventoryDetailQueryDto['WarehouseCode']) { this.materialInventoryDetailQueryDto = { ...this.materialInventoryDetailQueryDto, WarehouseCode: code }; } } onStorageLocationCodeChange(code: string) { if (code !== this.materialInventoryDetailQueryDto['StorageLocationCode']) { this.materialInventoryDetailQueryDto = { ...this.materialInventoryDetailQueryDto, StorageLocationCode: code }; } } onFactoryCodeChange(code: string) { if (code !== this.materialInventoryDetailQueryDto['FactoryCode']) { this.materialInventoryDetailQueryDto = { ...this.materialInventoryDetailQueryDto, FactoryCode: code }; } } getSelectedMaterialInventoryDetailData(data: RhSelectableDto) { const fields = this.currentLockType === 'LotNum' ? ['MaterialCode', 'MaterialName', 'LotNum'] : [ 'MaterialCode', 'MaterialName', 'WarehouseCode', 'WarehouseName', 'StorageLocationCode', 'StorageLocationName', 'LotNum', 'FactoryCode' ]; // if (data) { // // this.defaultQueryDtoStorageLocation = {}; // const relatedDatas = fields.map(f => { return { sourceName: f, mappedName: f } }); // this.dynamicSer.formCustomizeEventTrigger( // { // id: `${this.url}_${this.currentLockType}EditForm`, // eventType: null, // options: null, // value: data, // relatedFieldDatas: relatedDatas // } // ); // } if (data) { const temp = ObjectHelper.createRhBaseDto(); fields.forEach((f) => (temp[f] = data[f])); this.editDto = { ...temp, __flag: new Date().getTime() }; } } }