import { RhLabelService } from './../../label.service'; import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; import { FileHelper, FormHelper, MsgHelper } from 'rh-base/core'; import { LabelRuleDto, RhSelectItem, LabelRuleQueryDto, BusinessCategoryType, JSDQkeyComponentPrintInputDto, RhPrintDto, JSDQkeyComponentPrintOutputDto, DataResultT, RhSelectableDto, CodeClassModel, RhDynamicTableFieldDto, RhDynamicInterfaceDto, RhTableQueryOptionDto, RhTableButtonInfoDto, RhSafeAny } from 'rh-base/model'; import { Component, ViewChild } from '@angular/core'; import { RhLabelPrinterExcelService } from './label-printer-excel.service'; import { DynamicFormComponent } from 'rh-base/shared'; @Component({ selector: 'rh-label-printer-excel', templateUrl: './label-printer-excel.component.html', styleUrls: ['./label-printer-excel.component.css'] }) export class RhLabelPrinterExcelComponent { labelRuleDataloading = false; labelRuleDataset: LabelRuleDto[] = []; selectLableRuleDto!: LabelRuleDto; selectedIndex = 0; // 关键件打印 isShowPrintTab = false; printForm!: UntypedFormGroup; printDto!: JSDQkeyComponentPrintOutputDto; printLoading = false; tabTwoType = 'Print'; addPrintLoading = false; // 自定义表单 dataresult!: DataResultT; dataLoading = false; defaultFieldDataset: RhDynamicTableFieldDto[] = []; defaultExportInterface!: RhDynamicInterfaceDto; /** 搜索选项 */ @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; queryOption = RhTableQueryOptionDto.create(1, 10); editButtonDataset: RhTableButtonInfoDto[] = []; titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('addPrintButton', '标签补打', 'default', false, 'printer', false, null, () => this.addPrint(), false) ]; selectedDatas: RhSelectableDto[] = []; selectedDto: RhSelectableDto | null = null; materialFieldData = { placeholder: '物料', config: { type: 'material', relatedModelDatas: [ { sourceName: 'MaterialCode', mappedName: 'MaterialCode' }, { sourceName: 'MaterialName', mappedName: 'MaterialName' } ], relatedFieldDatas: [ { sourceName: 'MaterialCode', mappedName: 'MaterialCode' }, { sourceName: 'MaterialName', mappedName: 'MaterialName' } ] } }; supplierFieldData = { placeholder: '供应商', config: { type: 'supplier', relatedModelDatas: [ { sourceName: 'SupplierCode', mappedName: 'SupplierCode' }, { sourceName: 'SupplierName', mappedName: 'SupplierName' } ], relatedFieldDatas: [ { sourceName: 'SupplierCode', mappedName: 'SupplierCode' }, { sourceName: 'SupplierName', mappedName: 'SupplierName' } ] } }; constructor(private operator: RhLabelService, private fb: UntypedFormBuilder, private labelSer: RhLabelPrinterExcelService) {} ngOnInit() { this.printDto = this.initPrintDto(); this.createPrintForm(this.printDto); } onSelectBusinessType(item: RhSelectItem) { const queryDto = LabelRuleQueryDto.create(); queryDto.BusinessCategoryCode = item.Value as BusinessCategoryType; this.getLabelRuleDatas(queryDto); } refreshSelectDatas(dtos: RhSelectableDto[]) { this.selectedDatas = dtos; } /** * 当点击无法打印的标签时触发 */ closeTrigger() { // this.closeEditTab(); this.closePrintTab(); MsgHelper.ShowInfoMessage('该标签的打印功能未开通!'); } private getLabelRuleDatas(queryDto: LabelRuleQueryDto) { this.labelRuleDataloading = true; this.operator.GetLabelRuleDatas(queryDto).subscribe( (result) => { if (result && result.Success) { this.labelRuleDataset = result.Attach; } else { this.labelRuleDataset = []; } this.labelRuleDataloading = false; }, () => { this.labelRuleDataset = []; this.labelRuleDataloading = false; } ); } //#region 关键件打印 initPrintDto(): JSDQkeyComponentPrintOutputDto { const dto = JSDQkeyComponentPrintOutputDto.create(); return dto; } createPrintForm(dto: JSDQkeyComponentPrintOutputDto) { this.printForm = this.fb.group({ /** 物料代码 */ MaterialCode: [dto.MaterialCode, [Validators.required]], /** 物料名称 */ MaterialName: [dto.MaterialName, [Validators.required]], /** 供应商代码 */ SupplierCode: [dto.SupplierCode, [Validators.required]], /** 供应商名称 */ SupplierName: [dto.SupplierName, [Validators.required]], /** 打印份数 */ Copies: [null, [Validators.required]], /** 打印数量 */ Numbers: [null, [Validators.required]] }); } resetPrintForm(event: Event | null) { if (event) { event.preventDefault(); } this.printDto = this.initPrintDto(); this.printForm.reset(this.printDto); } openPrintTab(operating: string, item: LabelRuleDto) { if (operating === 'print') { this.tabTwoType = 'Print'; } else if (operating === 'addPrint') { this.tabTwoType = 'AddPrint'; } this.selectLableRuleDto = item; this.isShowPrintTab = true; this.selectedIndex = 1; } closePrintTab() { this.isShowPrintTab = false; this.resetPrintForm(null); if (this.printLoading) { this.printLoading = false; } this.selectedIndex = 0; } submitPrintForm(event: Event) { if (event) { event.preventDefault(); } FormHelper.YGSubmitForm(this.printDto, this.printForm, (dto: RhSafeAny) => { // -----临时数据------// dto.SN = ''; dto.SerialNumber = ''; const date = new Date(Date.now()); dto.ProductDate = date; dto.Year = date.getFullYear(); dto.Month = date.getMonth(); dto.Week = 12; // ----------------- // const numbers = this.printForm.get('Numbers')?.value; const copies = this.printForm.get('Copies')?.value; this.getKeyComponentPrintDatas(dto, numbers, copies); }); } getKeyComponentPrintDatas(dto: JSDQkeyComponentPrintOutputDto, numbers: number, copies: number) { this.printLoading = true; const inPutDto = JSDQkeyComponentPrintInputDto.create(); inPutDto.Copies = copies; inPutDto.Number = numbers; inPutDto.Data = dto; this.operator.GetKeyComponentPrintDatas(inPutDto).subscribe( (result) => { if (result && result.Success) { this.print(result.Attach); this.closePrintTab(); } else { MsgHelper.ShowWarningMessage(`打印数据获取失败!${result.Message}`); } this.printLoading = false; }, () => { this.printLoading = false; } ); } print(dtos: JSDQkeyComponentPrintOutputDto[]) { const tempPrintDto = RhPrintDto.create(); tempPrintDto.PrintType = 'JSDQKeyComponentPrint'; tempPrintDto.PrintList = dtos; this.operator.TemplatePrint(tempPrintDto).subscribe((result) => { if (result && result.Success) { const userIp = result.Attach.toString(); location.href = FileHelper.getPrintLabelClientUrlLatest(userIp); } else { MsgHelper.ShowWarningModal(`打印失败!${result.Message}`); } }); } refreshSelectedDto(dto: RhSelectableDto) { if (dto) { this.selectedDto = dto; } else { this.selectedDto = null; } } confirmSelect(field: string) { switch (field) { case 'Material': return; case 'Supplier': return; default: return; } } // 物料选择 materialCodeChange() { setTimeout(() => { if (this.printDto.MaterialCode) { this.printForm.get('MaterialName')?.setValue(this.printDto.MaterialName); } }); } supplierCodeChange() { setTimeout(() => { if (this.printDto.SupplierCode) { this.printForm.get('SupplierName')?.setValue(this.printDto.SupplierName); } }); } //#endregion 关键件打印 // //#region 补打相关 setDatas(result: DataResultT) { if (result && result.Success) { this.dataresult = result; } else { MsgHelper.ShowWarningMessage(`搜索无数据!${result.Message}`); } } 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]; } exportInterfaceChange(item: RhDynamicInterfaceDto) { this.defaultExportInterface = item; } refreshDatas(option: RhTableQueryOptionDto) { this.queryOption = option; this.getDatas(option); } // 调用子组件中的接口 private getDatas(option?: RhTableQueryOptionDto) { option = option || this.queryOption; if (this.queryFormCmt) { this.queryFormCmt.submitDefaultForm(null, option); } } addPrint() { this.addPrintLoading = true; const tempPrintDto = RhPrintDto.create(); // 关键件补打 if (this.selectLableRuleDto.RuleId === 'KeyComponentBindLabel') { tempPrintDto.PrintType = 'JSDQKeyComponentPrint'; } else { tempPrintDto.PrintType = this.selectLableRuleDto.RuleId; } tempPrintDto.PrintList = this.selectedDatas; this.operator.TemplatePrint(tempPrintDto).subscribe( (result) => { if (result && result.Success) { this.addPrintLoading = false; const userIp = result.Attach.toString(); location.href = FileHelper.getPrintLabelClientUrlLatest(userIp); } else { MsgHelper.ShowWarningModal(`补打失败!${result.Message}`); } }, () => { this.addPrintLoading = false; } ); } //#endregion 补打相关 // }