import { Component, OnInit, ViewChild, Input, SimpleChanges } from '@angular/core'; import { DataResultT, RhBaseDto, RhSafeAny, RhTableButtonInfoDto, CodeClassModel, RhDynamicTableFieldDto, RhTableQueryOptionDto } from 'rh-base/model'; import { NzTreeNode } from 'ng-zorro-antd/tree'; import { RhLabelService } from './../../../label.service'; import { LabelTemplateDesignRuleDto, LabelRuleOutput } from './../../../label-model'; import { PrintSNFields } from './../../../label-type-data'; import { MsgHelper, RhWmsSysConfigService, ObjectHelper } from 'rh-base/core'; import { DynamicFormComponent } from 'rh-base/shared'; @Component({ selector: 'rh-material-inventory-sn-print-material', templateUrl: './material-inventory-sn-print-material.component.html', styleUrls: ['./material-inventory-sn-print-material.component.less'] }) export class MaterialInventorySnPrintMaterialComponent implements OnInit { @Input() rhLabelRuleDto!: LabelRuleOutput; ruleType!: string; @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; dataresult!: DataResultT; defaultFieldDataset: RhDynamicTableFieldDto[] = []; dataLoading = false; //树内选中的物料 selectedMaterial: RhSafeAny; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('snPrint', '条码打印', 'default', false, 'tag', false, null, (data) => this.openPrintModal(data as RhBaseDto)) ]; titleButtonDataset: RhTableButtonInfoDto[] = []; extraButtonDataset: RhTableButtonInfoDto[] = []; defaultQueryDto: RhSafeAny = {}; /** 选中的数据 */ selectItem: RhBaseDto | null = null; /** 选中的模板 */ selectedLabelSpecifyDto!: LabelTemplateDesignRuleDto; isShowPrintModal = false; /** 打印SN对应字段 */ printSNFieldMapped = PrintSNFields; // 启用库区货架,隐藏部分配置 isEnableWarehouseAreaAndWarehouseShelf = false; isEnableStorageLocation = false; visibleSetting = {}; // 启用库区货架,就需要调用高级库存查询接口 advancedQuery = false; materialInventoryAdvanced = 'MaterialInventoryAdvanced'; // 是否即时库存标签,打印接口不一样 isInventoryType = false; printLabel = (data: RhBaseDto) => { if (this.isInventoryType) { ObjectHelper.MapT(this.selectItem as RhBaseDto, data); } else { data['BusinessType'] = this.rhLabelRuleDto.RuleId; const field = this.printSNFieldMapped[this.rhLabelRuleDto.RuleId]; data['SN'] = this.selectItem?.[field]; } data['RuleId'] = this.rhLabelRuleDto.RuleId; return true; }; 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.isInventoryType = true; this.getIsEnableWarehouseAreaAndWarehouseShelf(); this.getIsEnableStorageLocation(); } else { this.isInventoryType = false; } } } 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); } getDatas(option?: RhTableQueryOptionDto) { if (this.queryFormCmt) { const queryDto: RhSafeAny = {}; if (this.selectedMaterial?.MaterialCode) { queryDto.MaterialCode = this.selectedMaterial.MaterialCode; } this.defaultQueryDto = queryDto; setTimeout(() => { this.queryFormCmt.submitDefaultForm(null, option); }); } } SelectedMaterialCode(node: NzTreeNode) { if (node && node.origin['customData']) { const data = node.origin['customData']; if (node.level === 1 && node.isSelected) { this.selectedMaterial = data; this.getDatas(); } } else { this.selectedMaterial = null; } } openPrintModal(data: RhBaseDto) { this.selectItem = data; this.isShowPrintModal = true; } closePrintModal() { this.selectItem = null; this.isShowPrintModal = false; } onStoreDatas(result: DataResultT) { if (result?.__context) { result.__context.submitLoading = true; setTimeout(() => { result.__context.submitLoading = false; }, 3000); } MsgHelper.ShowGlobalLoadingMessage(`正在调用打印机,请稍候...`); if (result?.Success) { // TODO: 唤起打印插件 this.operator.getPrintLabelClientUrlNew(result.Attach); } else { MsgHelper.ShowWarningModal(`条码生成失败,提示:${result.Message}`); MsgHelper.CloseGlobalLoadingMessage(); } } rhModelChange(dto: LabelTemplateDesignRuleDto) { this.selectedLabelSpecifyDto = dto; } /** 是否启用库区货架 */ getIsEnableWarehouseAreaAndWarehouseShelf() { // this.isEnableWarehouseAreaAndWarehouseShelf = this.wmsSysConfigSer.getIsEnableWarehouseAreaAndWarehouseShelf(); // if (!this.isEnableWarehouseAreaAndWarehouseShelf) { // const temp = { // WarehouseAreaCode: false, // WarehouseAreaName: false, // WarehouseShelfCode: false, // WarehouseShelfName: false // }; // Object.assign(this.visibleSetting, temp); // this.advancedQuery = false; // } else { this.advancedQuery = true; // } } /** 是否启用库位 */ getIsEnableStorageLocation() { this.isEnableStorageLocation = this.wmsSysConfigSer.getIsEnableStorageLocation() as boolean; if (!this.isEnableStorageLocation) { const temp = { StorageLocationCode: false, StorageLocationName: false }; Object.assign(this.visibleSetting, temp); } } }