import { MsgHelper, RhWmsSysConfigService } from 'rh-base/core'; import { Component, Input, OnInit, SimpleChanges, ViewChild } from '@angular/core'; import { RhLabelService } from '../../../label.service'; import { LabelRuleOutput, LabelTemplateDesignRuleDto, ProductSnLibraryDto, SnLibraryInWarehouseDto, SnLibraryMaterialInventoryDto, LabelPrintDataLibraryDto } from '../../../label-model'; import { DynamicFormComponent } from 'rh-base/shared'; import { DataResultT, RhBaseDto, RhTableButtonInfoDto, RhDynamicInterfaceDto, RhSafeAny, CodeClassModel, RhDynamicTableFieldDto, RhTableQueryOptionDto, RhSelectableDto } from 'rh-base/model'; @Component({ selector: 'rh-label-manage-default', templateUrl: './label-manage-default.component.html', styleUrls: ['./label-manage-default.component.css'] }) export class LabelManageDefaultComponent implements OnInit { @Input() rhLabelRuleDto!: LabelRuleOutput; ruleType!: string; @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; dataresult!: DataResultT; defaultFieldDataset: RhDynamicTableFieldDto[] = []; dataLoading = false; /** 选中的模板 */ selectedLabelSpecifyDto!: LabelTemplateDesignRuleDto; titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'again', '补打', 'primary', false, 'sync', false, null, (data) => this.makeUpLabel(data as RhBaseDto[]), false ), new RhTableButtonInfoDto('del', '作废', 'primary', true, 'delete', false, null, (data) => this.cancelLabel(data as RhBaseDto[]), false) ]; makeUpModalItems!: RhBaseDto[]; isMakeUpModalShow = false; visibleTableSetting = {}; visibleFormSetting = {}; printLabel = (data: RhBaseDto) => { data['RuleId'] = this.rhLabelRuleDto.RuleId; switch (this.ruleType) { case 'PurchaseMaterial': data['PurchaseMaterialSnLibraryDtos'] = this.makeUpModalItems; break; case 'ProduceInWarehouse': data['SnLibraryProductionDtos'] = this.makeUpModalItems; break; case 'MaterialInventory': data['SnLibraryMaterialInventoryDtos'] = this.makeUpModalItems; break; case 'ProductUnicSN': data['ProductSnLibraryDtos'] = this.makeUpModalItems; break; } return true; }; // 补打 接口 formInterface: RhDynamicInterfaceDto | null = null; constructor(private operator: RhLabelService, private wmsSysConfigSer: RhWmsSysConfigService) {} ngOnInit(): void { // } ngOnChanges(changes: SimpleChanges): void { const { rhLabelRuleDto } = changes; if (rhLabelRuleDto && rhLabelRuleDto.currentValue) { this.ruleType = this.rhLabelRuleDto.RuleId.replace('Label', ''); if (this.ruleType === 'MaterialInventory') { this.initTalbleAndFormFieldDisplay(); } if (this.ruleType === 'ProductUnicSN') { this.formInterface = { interfaceType: 'post', port: 52882, controllerName: 'SnLibraryApi', interfaceName: 'RebuildSnLibraryMaterialInventoryLabel' }; } } } initTalbleAndFormFieldDisplay() { /** 是否启用库区货架 */ // const isEnableWarehouseAreaAndWarehouseShelf = this.wmsSysConfigSer.getIsEnableWarehouseAreaAndWarehouseShelf(); /** 是否启用库位 */ const isEnableStorageLocation = this.wmsSysConfigSer.getIsEnableStorageLocation(); const visibleTableSetting = {}; const visibleFormSetting = {}; // if (!isEnableWarehouseAreaAndWarehouseShelf) { // const temp = { // WarehouseAreaCode: false, // WarehouseAreaName: false, // WarehouseShelfCode: false, // WarehouseShelfName: false // }; // Object.assign(visibleTableSetting, temp); // Object.assign(visibleFormSetting, temp); // } if (!isEnableStorageLocation) { const temp = { StorageLocationCode: false, StorageLocationName: false }; Object.assign(visibleTableSetting, temp); Object.assign(visibleFormSetting, temp); } this.visibleTableSetting = visibleTableSetting; this.visibleFormSetting = visibleFormSetting; } /** * * @param data */ makeUpLabel(data: RhBaseDto[]) { this.isMakeUpModalShow = true; this.makeUpModalItems = data; } /** * * @param data */ cancelLabel(data: RhBaseDto[]) { MsgHelper.ShowConfirmModal('是否废除', '是否确认作废作废标签打印数据?', () => { switch (this.ruleType) { case 'PurchaseMaterial': this.PurchaseMaterialLabelCanal(data); break; case 'ProduceInWarehouse': this.ProduceInWarehouseCanal(data); break; case 'MaterialInventory': this.MaterialInventoryLabelCanal(data); break; case 'ProductUnicSN': this.ProductUnicSNLabelCanal(data); break; } }); } /** * 采购物料标签 作废 * @param data */ PurchaseMaterialLabelCanal(data: RhBaseDto[]) { this.operator.AbortedLabelPrintDatas(data as LabelPrintDataLibraryDto[]).subscribe((result) => { if (result.Success) { MsgHelper.ShowInfoMessage('作废成功!'); this.getDatas(); } else { MsgHelper.ShowErrorMessage('作废失败!' + result.Message); } }); } /** * 生产物料标签 作废 * @param data */ ProduceInWarehouseCanal(data: RhSelectableDto[]) { this.operator.AbortedInWarehouseLabelDatas(data as SnLibraryInWarehouseDto[]).subscribe((result) => { if (result.Success) { MsgHelper.ShowInfoMessage('作废成功!'); this.getDatas(); } else { MsgHelper.ShowErrorMessage('作废失败!' + result.Message); } }); } /** * 库存物料标签 作废 * @param data */ MaterialInventoryLabelCanal(data: RhSelectableDto[]) { this.operator.AbortedSnLibraryMaterialInventoryDatas_Wms(data as SnLibraryMaterialInventoryDto[]).subscribe((result) => { if (result.Success) { MsgHelper.ShowInfoMessage('作废成功!'); this.getDatas(); } else { MsgHelper.ShowErrorMessage('作废失败!' + result.Message); } }); } /** * 生产唯一码标签 * @param data */ ProductUnicSNLabelCanal(data: RhSelectableDto[]) { this.operator.AbortedSnLibraryMaterialInventoryDatas_Emp(data as ProductSnLibraryDto[]).subscribe((result) => { if (result.Success) { MsgHelper.ShowInfoMessage('作废成功!'); this.getDatas(); } else { MsgHelper.ShowErrorMessage('作废失败!' + result.Message); } }); } onStoreDatas(result: DataResultT) { if (result?.__context) { result.__context.submitLoading = true; setTimeout(() => { result.__context.submitLoading = false; }, 3000); } if (result?.Success) { // TODO: 唤起打印插件 this.operator.getPrintLabelClientUrlNew(result.Attach); this.closePrintModal(); this.getDatas(); } else { MsgHelper.ShowWarningModal(`条码生成失败,提示:${result.Message}`); MsgHelper.CloseGlobalLoadingMessage(); } } rhModelChange(dto: LabelTemplateDesignRuleDto) { this.selectedLabelSpecifyDto = dto; } closePrintModal() { this.isMakeUpModalShow = false; this.makeUpModalItems = []; } setDatas(dataset: DataResultT) { this.dataresult = dataset; } 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]; } dataLoadingChange(status: boolean) { this.dataLoading = status; } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(option); } private getDatas(option?: RhTableQueryOptionDto) { if (this.queryFormCmt) { this.queryFormCmt.submitDefaultForm(null, option); } } }