import { UntypedFormGroup } from '@angular/forms'; import { RhLabelService } from './../../label.service'; import { LabelRuleOutput, ProductSnCreateRuleDto, LabelRuleInput } from './../../label-model'; import { Component, OnInit } from '@angular/core'; import { RhSelectItem, RhBaseDto, DataResultT, RhSelectableDto, RhInterfaceLocationDto, OpMode, RhSafeAny, LabelRuleQueryDto } from 'rh-base/model'; import { MsgHelper, ObjectHelper, RhApiUrlsService } from 'rh-base/core'; import { RhPortType } from 'rh-base/model'; @Component({ selector: 'rh-material-inventory-label-rule', templateUrl: './material-inventory-label-rule.component.html', styleUrls: ['./material-inventory-label-rule.component.less'] }) export class RhMaterialInventoryLabelRuleComponent implements OnInit { businessDataset: RhSelectItem[] = []; businessInitStatus: RhSelectItem[] = []; dataLoading = false; selectedBusinessType = ''; labelRuleDataloading = false; labelRuleDataset: LabelRuleOutput[] = []; selectedIndex = 0; editDto: RhBaseDto = {}; dataresult!: DataResultT; selectedItem: RhBaseDto | null = null; isShowCodeEditModal = false; isShowSampleModal = false; currentStatus: 'copy' | 'edit' | null = 'copy'; // isShowBindingModal = false; /** 标签条码生成示例接口 */ sampleGenerateInterface: RhInterfaceLocationDto = { interfaceType: 'post', port: this.apiUlr.getPortNum(RhPortType.mdp), controllerName: 'LabelRuleApi', interfaceName: 'LabelSnCreate' }; isShowAllLabel = false; constructor(private operator: RhLabelService, private apiUlr: RhApiUrlsService) { // } ngOnInit(): void { this.getBusinessDatas(); this.getLabelBusinessInitStatus(); } openEditTab(data?: RhBaseDto, $event?: Event) { if ($event) { $event.preventDefault(); $event.stopImmediatePropagation(); } if (data) { this.editDto = data; this.editDto.OpSign = OpMode.OpEdit; } else { this.editDto = {}; this.editDto.OpSign = OpMode.OpAdd; } this.selectedIndex = 1; this.currentStatus = 'edit'; } closeEditTab() { // this.selectedIndex = 0; this.currentStatus = null; } onStoreData(result: DataResultT) { if (result && result.Success) { const msg = this.editDto.OpSign === OpMode.OpAdd ? '新增' : '编辑'; MsgHelper.ShowSuccessMessage(`${msg}数据成功!`); if (this.editDto.OpSign === OpMode.OpEdit) { this.selectedIndex = 0; this.currentStatus = null; } this.editDto = ObjectHelper.createRhBaseDto(); this.onModelChange(this.selectedBusinessType); } else { MsgHelper.ShowWarningModal(`存储数据失败!${result.Message}`); } } onLabelVisibleChange() { this.getLabelRuleDatas(this.selectedBusinessType); } saveLabelRule(rules: string[]) { (this.selectedItem as ProductSnCreateRuleDto).CodingRules = rules; this.operator.StoreLabelRuleDataNew(this.selectedItem as LabelRuleInput).subscribe((result) => { if (result?.Success) { MsgHelper.ShowSuccessMessage('规则保存成功!'); this.closeCodeEditModal(); } else { MsgHelper.ShowWarningModal(`规则保存失败!`); } }); } openCodeEditModal(data: RhBaseDto, $event?: Event) { if ($event) { $event.preventDefault(); $event.stopImmediatePropagation(); } this.selectedItem = data; this.isShowCodeEditModal = true; } closeCodeEditModal() { this.selectedItem = null; this.isShowCodeEditModal = false; this.onModelChange(this.selectedBusinessType); } closeSampleModal() { this.selectedItem = null; this.isShowSampleModal = false; } openSampleModal(data: RhBaseDto, $event?: Event) { if ($event) { $event.preventDefault(); $event.stopImmediatePropagation(); } this.selectedItem = data; this.isShowSampleModal = true; } openBindingModal(data: RhBaseDto, $event?: Event) { if ($event) { $event.preventDefault(); $event.stopImmediatePropagation(); } this.selectedItem = data; this.selectedIndex = 1; this.currentStatus = 'copy'; } closeCopyModal() { this.selectedItem = null; this.closeEditTab(); this.onModelChange(this.selectedBusinessType); } onModelChange(type: string) { if (!type) { return; } this.selectedBusinessType = type; this.getLabelRuleDatas(this.selectedBusinessType); } ruleIdChange(ruleId: string, form: UntypedFormGroup) { const data = this.businessInitStatus.find((f) => f.Text === ruleId); if (data) { form.get('BusinessStatus')?.setValue(data.Value); } } private getLabelRuleDatas(businessType: string) { // 获取对应产品标签业务类型数据 const queryDto = LabelRuleQueryDto.create(); queryDto.LabelType = 'MaterialInventoryLabel'; queryDto.LabelBusinessTypeCode = businessType; // 默认只显示启用的数据`true`,显示全部需要传入`null` queryDto.IsEnable = this.isShowAllLabel === true ? null : 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) ); } private getBusinessDatas() { this.dataLoading = true; this.apiUlr .getSettingEntry({ moduleKey: 'LabelConfiguration', groupKey: 'MaterialInventoryLabel', paraCode: 'MaterialInventoryLabelBusinessType' }) .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.dataLoading = false; }, () => (this.dataLoading = false) ); } private getLabelBusinessInitStatus() { this.operator.GetLabelBusinessInitStatus().subscribe((result) => { if (result.Success) { this.businessInitStatus = result.Attach; } else { this.businessInitStatus = []; } }); } }