import { UntypedFormGroup, Validators } from '@angular/forms'; import { RhLabelService } from './../../label.service'; import { LabelTemplateDesignRuleDto, LabelRuleOutput } from './../../label-model'; import { Component, OnInit, Output, ViewChild, EventEmitter, TemplateRef, Input } from '@angular/core'; import { DynamicFormComponent } from 'rh-base/shared'; import { RhBaseDto, DataResultT, RhSelectableDto, RhTableButtonInfoDto, CodeClassModel, RhDynamicTableFieldDto, RhTableQueryOptionDto, RhSelectItem, LabelRuleQueryDto, RhSafeAny } from 'rh-base/model'; import { ObjectHelper, MsgHelper, RhApiUrlsService, RhWmsSysConfigService } from 'rh-base/core'; import { ProductRuleTypes } from './../../label-type-data'; @Component({ selector: 'rh-product-inventory-sn-print', templateUrl: './product-inventory-sn-print.component.html', styleUrls: ['./product-inventory-sn-print.component.less'] }) export class RhProductInventorySnPrintComponent implements OnInit { businessDataset: RhSelectItem[] = []; businessDataLoading = false; selectedBusinessType!: string; labelRuleDataset: LabelRuleOutput[] = []; labelRuleDataloading = false; selectedLabelRuleDto!: LabelRuleOutput | RhSafeAny; selectedIndex = 0; isShowPrintModal = false; /** 选中的生产计划数据 */ selectItem: RhBaseDto | null = null; /** 选中的模板 */ selectedLabelSpecifyDto!: LabelTemplateDesignRuleDto; @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; dataLoading = false; dataresult!: DataResultT; defaultFieldDataset: RhDynamicTableFieldDto[] = []; titleButtonDataset: RhTableButtonInfoDto[] = []; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('snPrint', '条码打印', 'default', false, 'tag', false, null, (data) => this.openPrintModal(data as RhBaseDto)) ]; extraButtonDataset: RhTableButtonInfoDto[] = []; collapseQueryDto = {}; defaultQueryDto = {}; isEnableLotNum = false; isEnableExpiryDays = false; ruleType = ''; ruleTypeList = ProductRuleTypes; selectedTab!: 'print' | 'manage'; printLabel = (data: RhBaseDto) => { ObjectHelper.MapT(this.selectItem as RhBaseDto, data, true, false); data['RuleId'] = this.selectedLabelSpecifyDto.RuleId; return true; }; @Output() rhTipChange = new EventEmitter(); @Input() rhManageTemp!: TemplateRef; @Input() rhPrintTemp!: TemplateRef; @Input() rhManageList = []; @Input() rhPrintList = []; constructor(private operator: RhLabelService, public apiurlSer: RhApiUrlsService, private wmsSysConfigSer: RhWmsSysConfigService) { // } ngOnInit(): void { // this.getBusinessDatas(); } initDefaultQueryDto(dto: RhSafeAny) { this.collapseQueryDto = dto; this.defaultQueryDto = { ...this.defaultQueryDto, ...this.collapseQueryDto }; } getValueChange() { this.defaultQueryDto = { ...this.defaultQueryDto, ...this.collapseQueryDto }; setTimeout(() => { this.getDatas(); }); } setDatas(dataset: DataResultT) { this.dataresult = dataset; } dataLoadingChange(status: boolean) { this.dataLoading = status; } setInitFieldDatset(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); } } onModelChange(type: string) { if (!type) { return; } this.selectedBusinessType = type; // 获取对应产品标签业务类型数据 const queryDto = LabelRuleQueryDto.create(); queryDto.LabelType = 'ProductLabel'; queryDto.LabelBusinessTypeCode = type; queryDto.IsEnable = true; this.labelRuleDataloading = true; this.operator.GetLabelRuleDatasNew(queryDto).subscribe( (result) => { if (result.Success) { this.labelRuleDataset = result.Attach; } else { this.labelRuleDataset = []; MsgHelper.ShowInfoMessage(`查询无数据:${result.Message}`); } this.labelRuleDataloading = false; }, () => (this.labelRuleDataloading = false) ); } rhModelChange(dto: LabelTemplateDesignRuleDto) { this.selectedLabelSpecifyDto = dto; } totalQtyChange(totalQty: number, formgroup: UntypedFormGroup) { const qty = formgroup.get('Qty')?.value; if (totalQty && qty) { const snCreateQty = Math.ceil(totalQty / qty); formgroup.get('SnCreateQty')?.setValue(snCreateQty); } else { formgroup.get('SnCreateQty')?.setValue(null); } } qtyChange(qty: number, formgroup: UntypedFormGroup) { const totalQty = formgroup.get('TotalQty')?.value; if (totalQty && qty) { const snCreateQty = Math.ceil(totalQty / qty); formgroup.get('SnCreateQty')?.setValue(snCreateQty); } else { formgroup.get('SnCreateQty')?.setValue(null); } } onStoreDatas(result: DataResultT) { if (result?.Success) { // TODO: 唤起打印插件 this.operator.getPrintLabelClientUrlNew(result.Attach); } else { MsgHelper.ShowWarningModal(`条码生成失败,提示:${result.Message}`); } } onSelectLabelRule(item: LabelRuleOutput) { // 判断当前没有外部传入自定义视图 const list = !this.rhPrintTemp && !this.rhPrintList.length ? ['BlisterBoxLabel_1', 'InnerBox_1', 'otr'] : []; this.selectedTab = 'print'; this.selectedLabelRuleDto = item; this.ruleType = this.selectedLabelRuleDto.RuleId as string; this.rhTipChange.emit({ type: this.selectedTab, ...item }); if ([...list, ...this.ruleTypeList, ...this.rhPrintList].includes(this.ruleType)) { this.openPrintTab(); } else { MsgHelper.ShowWarningMessage('不存在对应的打印页面!'); } } /** 去管理 */ onSelectLabelManage(item: LabelRuleOutput) { // const list = !this.rhManageTemp && !this.rhManageList.length ? ['BlisterBoxLabel_1', 'InnerBox_1', 'otr'] : []; this.selectedTab = 'manage'; this.selectedLabelRuleDto = item; this.ruleType = this.selectedLabelRuleDto.RuleId; this.rhTipChange.emit({ type: this.selectedTab, ...item }); if ([...this.ruleTypeList, ...this.rhManageList].includes(this.ruleType)) { this.openManageTab(); } else { MsgHelper.ShowWarningMessage('不存在对应的管理页面!'); } } openManageTab() { this.selectedIndex = 1; } openPrintTab() { this.selectedIndex = 1; } closePrintTab() { this.selectedIndex = 0; } openPrintModal(data: RhBaseDto) { this.selectItem = data; this.isShowPrintModal = true; } closePrintModal() { this.selectItem = null; this.isShowPrintModal = false; } afterPrintFormInit(formgroup: UntypedFormGroup) { // 是否启用批次号,启用则必填 this.getIsEnableLotNum(); // 是否启用保质期,启用则生产日期必填 this.getIsEnableExpirationDate(); if (this.isEnableLotNum) { formgroup.get('LotNum')?.setValidators(Validators.required); } else { formgroup.get('LotNum')?.clearValidators(); } formgroup.get('LotNum')?.updateValueAndValidity(); if (this.isEnableExpiryDays) { formgroup.get('ProduceDate')?.setValidators(Validators.required); } else { formgroup.get('ProduceDate')?.clearValidators(); } formgroup.get('ProduceDate')?.updateValueAndValidity(); } private getBusinessDatas() { this.businessDataLoading = true; this.apiurlSer .getSettingEntry({ moduleKey: 'LabelConfiguration', groupKey: 'LabelTemplateDesignRule', paraCode: 'ProductLabelBusinessType' }) .subscribe( (result) => { if (result.Success) { this.businessDataset = result.Attach; // 默认选中第一个选项 if (this.businessDataset[0]?.Value) { this.onModelChange(this.businessDataset[0].Value as string); this.businessDataset[0].select = true; } } else { this.businessDataset = []; MsgHelper.ShowWarningMessage(`获取仓储标签业务类型数据失败!`); } this.businessDataLoading = false; }, () => (this.businessDataLoading = false) ); } getIsEnableLotNum() { this.isEnableLotNum = this.wmsSysConfigSer.getIsEnableLotNum() as boolean; } getIsEnableExpirationDate() { this.isEnableExpiryDays = this.wmsSysConfigSer.getIsEnableExpirationDate() as boolean; } }