import { RhLabelService } from './../../../../label.service'; import { LabelRuleOutput, LabelPrintOutput, LabelRePrintInput, LabelPrintDataLibraryDto } from './../../../../label-model'; import { Component, OnInit, Input, Output, EventEmitter, ViewChild, SimpleChanges } from '@angular/core'; import { DynamicFormComponent } from 'rh-base/shared'; import { RhTableButtonInfoDto, RhBaseDto, DataResultT, CodeClassModel, RhDynamicTableFieldDto, RhTableQueryOptionDto } from 'rh-base/model'; import { MsgHelper } from 'rh-base/core'; @Component({ selector: 'rh-material-inventory-label-manage', templateUrl: './material-inventory-label-manage.component.html', styleUrls: ['./material-inventory-label-manage.component.less'] }) export class MaterialInventoryLabelManageComponent implements OnInit { @Input() rhLabelRuleDto!: LabelRuleOutput; @Input() rhRefreshSign!: number; @Output() rhLabelPrintOutput = new EventEmitter(); ruleType!: string; @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; dataresult!: DataResultT; defaultFieldDataset: RhDynamicTableFieldDto[] = []; dataLoading = false; /** 打印份数 */ currentPrintCopys = 1; titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'again', '补打', 'primary', false, 'sync', false, null, (datas) => this.labelRePrint(datas as RhBaseDto[]), false, true ), new RhTableButtonInfoDto( 'del', '报废', 'primary', true, 'delete', false, null, (datas) => this.abortedLabelPrintDatas(datas as RhBaseDto[]), false, true ) ]; defaultQueryDto = {}; constructor(private operator: RhLabelService) {} ngOnInit(): void { // } ngOnChanges(changes: SimpleChanges): void { const { rhLabelRuleDto, rhRefreshSign } = changes; if (rhLabelRuleDto && rhLabelRuleDto.currentValue) { this.ruleType = this.rhLabelRuleDto.RuleId.replace('Label', ''); this.defaultQueryDto = { LabelType: this.rhLabelRuleDto.RuleId ? `$${this.rhLabelRuleDto.RuleId}` : null }; if (rhRefreshSign && rhRefreshSign.currentValue && !rhRefreshSign.firstChange) this.getDatas(); } } setDatas(dataset: DataResultT) { this.dataresult = dataset; if (!this.dataresult?.Success) { MsgHelper.ShowWarningMessage(`搜索无数据!${this.dataresult?.Message}`); } } 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); } } /** 补打 */ labelRePrint(datas: RhBaseDto[]) { this.titleButtonDataset[0].loading = true; this.titleButtonDataset = [...this.titleButtonDataset]; const labelSpecifyCategorys = [...new Set(datas.map((f) => f['PrintTemplateSpecify']))]; if (labelSpecifyCategorys.length !== 1) { MsgHelper.ShowWarningMessage('必须选择打印模板规格相同的数据进行操作!'); this.titleButtonDataset[0].loading = false; this.titleButtonDataset = [...this.titleButtonDataset]; return; } const dto = LabelRePrintInput.create(); dto.LabelType = this.rhLabelRuleDto.RuleId; dto.LabelDatas = datas as LabelPrintDataLibraryDto[]; dto.RuleId = this.rhLabelRuleDto.RuleId; dto.LabelSpecify = labelSpecifyCategorys[0]; dto.PrintCopys = this.currentPrintCopys; this.operator.LabelRePrint(dto).subscribe( (result) => { if (result.Success) { this.rhLabelPrintOutput.emit(result.Attach); } else { MsgHelper.ShowWarningMessage(`标签补打失败!${result.Message}`); } this.titleButtonDataset[0].loading = false; this.titleButtonDataset = [...this.titleButtonDataset]; }, () => { this.titleButtonDataset[0].loading = false; this.titleButtonDataset = [...this.titleButtonDataset]; } ); } /** 作废 */ abortedLabelPrintDatas(datas: RhBaseDto[]) { this.titleButtonDataset[1].loading = true; this.titleButtonDataset = [...this.titleButtonDataset]; this.operator.AbortedLabelPrintDatas(datas as LabelPrintDataLibraryDto[]).subscribe( (result) => { if (result.Success) { MsgHelper.ShowInfoMessage('作废成功!'); this.getDatas(); } else { MsgHelper.ShowErrorMessage('作废失败!' + result.Message); } this.titleButtonDataset[1].loading = false; this.titleButtonDataset = [...this.titleButtonDataset]; }, () => { this.titleButtonDataset[1].loading = false; this.titleButtonDataset = [...this.titleButtonDataset]; } ); } }