import { Component, OnInit, ViewChild } from '@angular/core'; import { DynamicFormComponent, WarehouseConfigDto, WarehouseConfigQueryDto } from 'rh-base/shared'; import { DataResultT, RhSelectableDto, RhTableButtonInfoDto, RhLoginedUserDto, CodeClassModel, RhDynamicTableFieldDto, RhTableQueryOptionDto, RhBaseDto, OpMode, RhSafeAny, WithNil } from 'rh-base/model'; import { RhStorageService, MsgHelper } from 'rh-base/core'; import { RhInventoryCountService } from '../inventory-count.service'; import { InventoryVerificationOrderMasterDto, InventoryVerificationOrderDetailQueryDto, InventoryVerificationResultDetailDto, InventoryVerificationOrderDetailDto, DataImportDto } from './../../inventory-manage-model'; import { RhInventoryManageService } from './../../inventory-manage.service'; import { UntypedFormGroup } from '@angular/forms'; import { NzUploadFile } from 'ng-zorro-antd/upload'; import { Observable, Observer } from 'rxjs'; type TabType = 'verificationResultDetails' | 'inOutOrderDetails'; @Component({ selector: 'rh-inventory-verification-handle', templateUrl: './inventory-verification-handle.component.html', styleUrls: ['./inventory-verification-handle.component.less'] }) export class RhInventoryVerificationHandleComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; selectedIndex = 0; dataLoading = false; dataresult!: DataResultT; curOrder!: RhSelectableDto; currentResult!: DataResultT; warehouseData!: WarehouseConfigDto[]; selectWarehouse = []; verificationResultDetailsResult!: DataResultT; verificationResultDetailsLoading = false; // 盘点明细编辑对象 editDtoCheck: RhSafeAny = {}; // 任务单字段按钮 defaultFieldDataset: RhDynamicTableFieldDto[] = []; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'start', '开始盘点', 'default', false, 'file-add', false, null, (data) => this.startInventoryVerification(data as RhBaseDto), true, true ), new RhTableButtonInfoDto('verificationResultDetails', '盘点作业管理', 'default', false, 'form', false, null, (data) => this.openDetailTab({ data } as RhBaseDto, 'verificationResultDetails') ), new RhTableButtonInfoDto( 'end', '完成盘点', 'default', false, 'file-done', false, null, (data) => this.completedInventoryVerification(data as RhBaseDto), true, true ) ]; titleButtonDataset: RhTableButtonInfoDto[] = []; // 盘点明细按钮 titleButtonDatasetCheck: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('new', '新建', 'primary', false, 'file', false, null, () => this.openEditModalCheck(), true), new RhTableButtonInfoDto('rowEdit', '填写盘点记录', 'primary', false, 'edit', false, null, () => this.editAvailableQty(), true), new RhTableButtonInfoDto('export', '导出', 'default', false, 'export', false, null, () => this.exportDetailDatas(), true), new RhTableButtonInfoDto('import', '导入', 'default', false, 'import', false, null, () => this.openDetailDatasImportModal(), true) ]; titleButtonDatasetCheckT = [ new RhTableButtonInfoDto( 'new', '新建', 'primary', false, 'file', false, null, () => this.openEditModalCheck(), true ), new RhTableButtonInfoDto( 'rowCheck', '保存盘点记录', 'primary', false, 'check', false, null, () => this.updateAvaliableQty(), true, true ), new RhTableButtonInfoDto('rowFill', '填充实盘数量', 'primary', false, 'edit', false, null, () => this.fillAvaliableQty(), true, true), new RhTableButtonInfoDto('redo', '取消', 'default', false, 'redo', false, null, () => this.cancelEditAvaliableQty(), true) // new RhTableButtonInfoDto('export', '导出', 'default', false, 'export', false, null, () => this.exportDetailDatas(), true), // new RhTableButtonInfoDto('import', '导入', 'default', false, 'import', false, null, () => this.openDetailDatasImportModal(), true) ]; extraButtonDatasetCheck: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'end', '完成盘点', 'primary', false, 'file-done', false, null, () => this.completedInventoryVerification(), true, true ), new RhTableButtonInfoDto('back', '返回', 'default', false, 'rollback', false, null, () => this.closeDetailTab(), true) ]; // 辅助字段 currentUser: WithNil; curFactoryDefaultQueryDto = {}; isShowDetail = false; isEnableEditAvaliableQty = true; // 文件上传 isShowDetailDatasImportModal = false; uploading = false; curUploadData!: DataImportDto; /** 上传的文件列表 */ uploadFileList: NzUploadFile[] = []; // 弹窗可见性 isShowEditModalCheck = false; // 表单可见性 editFormVisibleSettingCheck = {}; // 表格可见性 tableVisibleSetting = {}; // 仓储联动 defaultQueryDtoWarehouseArea = {}; defaultQueryDtoWarehouseShelf = {}; defaultQueryDtoStorageLocation = {}; // 物料搜索 // defaultQueryDtoMaterial = {}; currentDetailsType = null; radioOptions = [ { Text: '全部', Value: null }, { Text: '已盘', Value: true }, { Text: '未盘', Value: false } ]; beforeSubmitEditDetailsCheck = (data: RhBaseDto) => { this.storeInventoryVerificationDatas([data as InventoryVerificationOrderDetailDto], () => this.closeEditModalCheck()); return false; }; get isEnableInventoryVerificationAddMaterial() { return this.inventoryManageSer.isEnableInventoryVerificationAddMaterial; } get isEnableWarehouseAreaAndWarehouseShelf() { return this.inventoryManageSer.isEnableWarehouseAreaAndWarehouseShelf; } get isEnableStorageLocation() { return this.inventoryManageSer.isEnableStorageLocation; } get isEnableSN() { return this.inventoryManageSer.isEnableSN; } get isEnableExpirationDate() { return this.inventoryManageSer.isEnableExpirationDate; } get isEnableLotNum() { return this.inventoryManageSer.isEnableLotNum; } get isInInventoryVerification() { const list = ['InventoryVerification', 'RepeatInventory']; return list.includes(this.curOrder?.['OrderStatus']); } get isReadOnly() { return this.isShowDetail || (this.curOrder && !this.isInInventoryVerification); } get titleBtnDataset() { return this.isReadOnly ? [] : this.isEnableEditAvaliableQty ? this.titleButtonDatasetCheck : this.titleButtonDatasetCheckT; } get extraBtnDataset() { return this.isReadOnly ? [] : this.extraButtonDatasetCheck; } constructor( public storage: RhStorageService, private operator: RhInventoryCountService, private inventoryManageSer: RhInventoryManageService ) { } ngOnInit(): void { this.initPageConfig(); this.getWarehouse(); } initPageConfig() { // 获取当前用户信息 this.currentUser = this.storage.getUserSession()?.User; this.curFactoryDefaultQueryDto = { FactoryCode: this.currentUser?.FactoryCode }; // 设置表格按钮可见性 // 开始盘点(审核通过) this.editButtonDataset[0].visible = `data=>data.OrderStatus==='AuditPass'`; // 盘点明细(盘点中) this.editButtonDataset[1].visible = `data=>data.OrderStatus==='InventoryVerification'||data.OrderStatus==='RepeatInventory'`; // 完成盘点(盘点中) this.editButtonDataset[2].visible = `data=>data.OrderStatus==='InventoryVerification'||data.OrderStatus==='RepeatInventory'`; } 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); } } getWarehouse() { const dto = WarehouseConfigQueryDto.create(); dto.Mode = 8; this.operator.GetWarehouseConfigDatas(dto).subscribe((result) => { if (result) { this.warehouseData = result.Attach; } }); } getWarehouseName(item: string) { return this.warehouseData.find((f) => f.WarehouseCode == item)?.WarehouseName; } onSelctedChange(data: string | any[]) { if (data.length) { this.verificationResultDetailsResult = { Attach: [], TotalCount: 0 } as RhSafeAny; this.verificationResultDetailsResult.Attach = this.currentResult.Attach.filter((f) => data.indexOf(f['WarehouseCode']) != -1); this.verificationResultDetailsResult.TotalCount = this.verificationResultDetailsResult.Attach.length; } else { this.verificationResultDetailsResult = { Attach: [], TotalCount: 0 } as RhSafeAny; this.verificationResultDetailsResult = this.currentResult; } } selectedIndexChange(index: number) { if (index === 0) { this.curOrder = {}; this.currentDetailsType = null; this.isEnableEditAvaliableQty = true; } } openDetailTab(dto: RhBaseDto, type?: TabType) { this.curOrder = dto['data']; this.initTableVisibleSetting(); if (type) { this.isShowDetail = false; } else { this.isShowDetail = true; } this.getInventoryVerificationOrderDetailDatas(); this.titleButtonDatasetCheck[0].visible = this.isEnableInventoryVerificationAddMaterial; this.titleButtonDatasetCheckT[0].visible = this.isEnableInventoryVerificationAddMaterial; this.selectedIndex = 1; } closeDetailTab() { this.selectedIndex = 0; } /** 开始盘点 */ startInventoryVerification(data: RhBaseDto) { this.editButtonDataset[0].loading = true; this.editButtonDataset = [...this.editButtonDataset]; this.operator.StartInventoryVerification(data as InventoryVerificationOrderMasterDto).subscribe( (result) => { if (result.Success) { MsgHelper.ShowSuccessMessage('开始盘点成功!'); this.getDatas(); } else { MsgHelper.ShowWarningMessage(`开始盘点失败!${result.Message}`); } this.editButtonDataset[0].loading = false; this.editButtonDataset = [...this.editButtonDataset]; }, () => { this.editButtonDataset[0].loading = false; this.editButtonDataset = [...this.editButtonDataset]; } ); } /** 结束盘点 */ completedInventoryVerification(data?: RhBaseDto) { if (!data) { data = this.curOrder!; } this.editButtonDataset[2].loading = true; this.editButtonDataset = [...this.editButtonDataset]; this.operator.CompletedInventoryVerification(data as InventoryVerificationOrderMasterDto).subscribe( (result) => { if (result.Success) { MsgHelper.ShowSuccessMessage('结束盘点成功!'); this.getDatas(); this.closeDetailTab(); } else { MsgHelper.ShowWarningMessage(`结束盘点失败!${result.Message}`); } this.editButtonDataset[2].loading = false; this.editButtonDataset = [...this.editButtonDataset]; }, () => { this.editButtonDataset[2].loading = false; this.editButtonDataset = [...this.editButtonDataset]; } ); } /** 获取盘点明细 */ getInventoryVerificationOrderDetailDatas() { const queryDto = InventoryVerificationOrderDetailQueryDto.create(); queryDto.OrderCode = this.curOrder?.['OrderCode']; queryDto.InventoryProcess = this.curOrder?.['OrderStatus'] === 'RepeatInventory' ? 'RepeatInventory' : null; queryDto.IsVerified = this.currentDetailsType; queryDto.Mode = 8; this.verificationResultDetailsLoading = true; this.operator.GetInventoryVerificationOrderDetailDatas(queryDto).subscribe( (result) => { if (result.Success) { this.currentResult = result; this.verificationResultDetailsResult = result; this.verificationResultDetailsResult.httpRequestPara = queryDto; this.onSelctedChange(this.selectWarehouse); } else { MsgHelper.ShowWarningMessage(`查询无数据!${result.Message}`); this.verificationResultDetailsResult = { Success: false, Attach: [] } as RhSafeAny; } this.verificationResultDetailsLoading = false; }, () => { this.verificationResultDetailsLoading = false; } ); } /** 编辑=》保存盘点明细(来自任务单明细) */ updateInventoryVerificationDatas(datas: InventoryVerificationOrderDetailDto[], cb?: () => void) { this.titleButtonDatasetCheckT[1].loading = true; this.titleButtonDatasetCheckT = [...this.titleButtonDatasetCheckT]; this.operator.UpdateInventoryVerificationDatas(datas).subscribe( (result) => { if (result.Success) { MsgHelper.ShowSuccessMessage('盘点任务单明细成功!'); this.getInventoryVerificationOrderDetailDatas(); if (cb) cb(); } else { MsgHelper.ShowWarningMessage(`盘点任务单明细失败!${result.Message}`); } this.titleButtonDatasetCheckT[1].loading = false; this.titleButtonDatasetCheckT = [...this.titleButtonDatasetCheckT]; }, () => { this.titleButtonDatasetCheckT[1].loading = false; this.titleButtonDatasetCheckT = [...this.titleButtonDatasetCheckT]; } ); } /** 新增=》保存盘点明细(来自自定义新增) */ storeInventoryVerificationDatas(datas: InventoryVerificationOrderDetailDto[], cb?: () => void) { this.operator.StoreInventoryVerificationDatas(datas).subscribe((result) => { if (result.Success) { MsgHelper.ShowSuccessMessage('存储盘点明细成功!'); this.getInventoryVerificationOrderDetailDatas(); if (cb) cb(); } else { MsgHelper.ShowWarningMessage(`保存盘点明细失败!${result.Message}`); } }); } /** 行编辑 */ editAvailableQty() { this.verificationResultDetailsResult.Attach.forEach((data) => (data.select = true)); this.isEnableEditAvaliableQty = false; } /** 行保存 */ updateAvaliableQty() { MsgHelper.ShowConfirmModal("提示","是否保存盘点明细?",()=>{ this.updateInventoryVerificationDatas(this.verificationResultDetailsResult.Attach as InventoryVerificationOrderDetailDto[], () => { this.isEnableEditAvaliableQty = true; this.verificationResultDetailsResult.Attach.forEach((data) => (data.select = false)); }); }) } fillAvaliableQty(){ MsgHelper.ShowConfirmModal( '是否自动填充实盘数量', '是否自动填充库存数量至实盘数量?', () => { this.verificationResultDetailsResult.Attach.forEach((ele) => { if (!ele['AvailableQty']) { ele['AvailableQty'] = ele['InventoryQty']; } }); this.updateInventoryVerificationDatas(this.verificationResultDetailsResult.Attach as InventoryVerificationOrderDetailDto[], () => { this.isEnableEditAvaliableQty = true; this.verificationResultDetailsResult.Attach.forEach((data) => (data.select = false)); }); }, () => { // TODO: } ); } /** 取消行编辑 */ cancelEditAvaliableQty() { this.getInventoryVerificationOrderDetailDatas(); this.isEnableEditAvaliableQty = true; this.verificationResultDetailsResult.Attach.forEach((data) => (data.select = false)); } /** 打开编辑盘点明细弹窗 */ openEditModalCheck(data?: RhBaseDto) { this.initEditFormVisibleSetting(); if (data) { this.editDtoCheck = data; this.editDtoCheck.OpSign = OpMode.OpEdit; } else { this.editDtoCheck = InventoryVerificationResultDetailDto.create(); this.editDtoCheck['OrderCode'] = this.curOrder?.['OrderCode']; this.editDtoCheck['WarehouseCode'] = this.curOrder?.['WarehouseCode']; this.editDtoCheck['WarehouseName'] = this.curOrder?.['WarehouseName']; this.editDtoCheck['SchemeCode'] = this.curOrder?.['SchemeCode']; this.editDtoCheck['SchemeName'] = this.curOrder?.['SchemeName']; this.editDtoCheck.OpSign = OpMode.OpAdd; } // 仓库赋值 const code = this.editDtoCheck['WarehouseCode']; // Object.assign(this.defaultQueryDtoMaterial, { WarehouseCode: code ? `$${code}` : null }); Object.assign(this.defaultQueryDtoWarehouseArea, { WarehouseCode: code ? `$${code}` : null }); Object.assign(this.defaultQueryDtoWarehouseShelf, { WarehouseCode: code ? `$${code}` : null }); Object.assign(this.defaultQueryDtoStorageLocation, { WarehouseCode: code ? `$${code}` : null }); this.isShowEditModalCheck = true; } closeEditModalCheck() { this.isShowEditModalCheck = false; this.editDtoCheck = null; // this.defaultQueryDtoMaterial = {}; this.defaultQueryDtoWarehouseArea = {}; this.defaultQueryDtoWarehouseShelf = {}; this.defaultQueryDtoStorageLocation = {}; } initTableVisibleSetting() { this.tableVisibleSetting = {}; Object.assign(this.tableVisibleSetting, this.inventoryManageSer.initVisibleSetting()); if (this.curOrder?.['VerificationType'] === 'BlindCheck') { // 盘点任务类型为盲盘 Object.assign(this.tableVisibleSetting, { InventoryQty: false, DiffQty: false }); } else { // 盘点任务类型为明盘 Object.assign(this.tableVisibleSetting, { InventoryQty: true, DiffQty: true }); } } initEditFormVisibleSetting() { this.editFormVisibleSettingCheck = {}; Object.assign(this.editFormVisibleSettingCheck, this.inventoryManageSer.initVisibleSetting()); } //#region 导入导出区域开始 exportDetailDatas() { this.operator.downloadInventoryVerificationOrderDetailData( this.curOrder as InventoryVerificationOrderMasterDto, this.selectWarehouse.length ? this.selectWarehouse : this.curOrder?.['WarehouseCode'] ); } openDetailDatasImportModal() { this.isShowDetailDatasImportModal = true; } closeDetailDatasImportModal() { this.isShowDetailDatasImportModal = false; this.uploadFileList = []; } initDataImportDto() { const dto = DataImportDto.create(); dto.BusinessCode = 'InventoryVerification'; dto.OperatorCode = this.currentUser?.UserName; dto.OperatorName = this.currentUser?.DisplayName; dto.FactoryCode = this.currentUser?.FactoryCode; return dto; } beforeUpload = (file: NzUploadFile) => { return new Observable((observer: Observer) => { const reader = new FileReader(); reader.readAsDataURL(file as RhSafeAny); reader.onload = () => { this.curUploadData = this.initDataImportDto(); this.curUploadData.FileStreamString = reader.result as RhSafeAny; this.uploadFileList = [file]; observer.next(false); observer.complete(); }; reader.onerror = (e) => { MsgHelper.ShowWarningModal(`读取文件失败!${e}`); observer.next(false); observer.complete(); }; }); }; handleUpload() { this.uploading = true; this.operator.DataImport(this.curUploadData).subscribe( (result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage('数据上传成功!'); this.getInventoryVerificationOrderDetailDatas(); this.closeDetailDatasImportModal(); } else { MsgHelper.ShowWarningModal(`数据上传失败!${result.Message}`); } this.uploading = false; }, () => (this.uploading = false) ); } //#endregion 导入导出区域结束 //#region 仓库管理联动区域开始 changeWarehouseConfigForm(code: string, type: string, formgroup: UntypedFormGroup) { switch (type) { case 'warehouse': Object.assign(this.defaultQueryDtoWarehouseArea, { WarehouseCode: code ? `$${code}` : null }); Object.assign(this.defaultQueryDtoWarehouseShelf, { WarehouseCode: code ? `$${code}` : null }); Object.assign(this.defaultQueryDtoStorageLocation, { WarehouseCode: code ? `$${code}` : null }); if (!code) { formgroup.get('WarehouseAreaCode')?.setValue(null); formgroup.get('WarehouseAreaName')?.setValue(null); formgroup.get('WarehouseShelfCode')?.setValue(null); formgroup.get('WarehouseShelfName')?.setValue(null); formgroup.get('StorageLocationCode')?.setValue(null); formgroup.get('StorageLocationName')?.setValue(null); } break; case 'warehouseArea': Object.assign(this.defaultQueryDtoWarehouseShelf, { WarehouseAreaCode: code ? `$${code}` : null }); Object.assign(this.defaultQueryDtoStorageLocation, { WarehouseAreaCode: code ? `$${code}` : null }); if (!code) { formgroup.get('WarehouseShelfCode')?.setValue(null); formgroup.get('WarehouseShelfName')?.setValue(null); formgroup.get('StorageLocationCode')?.setValue(null); formgroup.get('StorageLocationName')?.setValue(null); } break; case 'warehouseShelf': Object.assign(this.defaultQueryDtoStorageLocation, { WarehouseShelfCode: code ? `$${code}` : null }); if (!code) { formgroup.get('StorageLocationCode')?.setValue(null); formgroup.get('StorageLocationName')?.setValue(null); } break; case 'storageLocation': break; default: break; } } //#endregion 仓库管理联动区域结束 }