import { MsgHelper, RhApiUrlsService, ArrayHelper } from 'rh-base/core'; import { IqcMaterialInspectOrderSNPoolQueryDto, IncomingInspectMaterialDataValueDto } from '../../../qmp-model'; import { Component, OnInit, Input, Output, EventEmitter, TemplateRef, OnChanges, SimpleChanges } from '@angular/core'; import { RhSelectableDto, RhSafeAny, RhSelectItem, RhDynamicInterfaceDto } from 'rh-base/model'; @Component({ selector: 'rh-product-mode-sn-pool', templateUrl: './product-mode-sn-pool.component.html', styleUrls: ['./product-mode-sn-pool.component.less'] }) export class RhProductModeSnPoolComponent implements OnInit, OnChanges { @Input() rhData!: { InspectOrderCode: string }; /** 当前正在检验的项目 */ @Input() rhInspectItem!: IncomingInspectMaterialDataValueDto; @Input() rhHeight = '640px'; @Output() rhDatasourceChange = new EventEmitter(); /** 用于sn录入区分。oba检验任务单选择的是箱号,其他模式选择的是sn */ @Input() rhSnInspectCategory: 'IQC' | 'OQC' | 'OBA' = 'IQC'; /** 定性模式模式下选中的sn */ @Input() rhSnList: string[] = []; @Input() rhSelectData!: RhSelectableDto[]; /** 是否可以拖动排序 */ @Input() rhDraggable = true; @Output() rhSelectDataChange = new EventEmitter(); @Input() rhContentTpl!: TemplateRef; @Input() rhExtraTpl!: TemplateRef; @Input() rhPrefixTpl!: TemplateRef; @Input() rhSnGetInterfaceInfo!: RhDynamicInterfaceDto; /** 代码对应的字段名称 */ @Input() rhValue = 'Value'; /** 文本对应的字段名称 */ @Input() rhText = 'Text'; /** 是否显示text */ @Input() rhTextVisible = false; dataset: RhSelectItem[] = []; dataLoading = false; constructor(public apiUrl: RhApiUrlsService) { // } ngOnInit() { this.rhInspectItem.InspectMode = this.rhInspectItem.InspectMode || 'Quantitative'; this.getSnDatas(); this.rhValue = this.rhValue || 'Value'; this.rhText = this.rhText || 'Text'; } ngOnChanges(changes: SimpleChanges) { const { rhInspectItem, rhSnList } = changes; // 根据当前的检验模式来设置sn的选中状态 if (rhInspectItem?.currentValue || rhSnList?.currentValue?.length) { this.updateItemSelectStatus(); } // 定量检测检测项目变更时需要重置disable状态 if (rhInspectItem?.currentValue) { if (this.rhInspectItem?.InspectMode === 'Qualitative') { this.dataset.forEach((ele) => { ele.disable = false; }); } else { this.updateItemDisabelStatus(); } } } // ngAfterViewInit() { // if (this.rhEnableDefaultSelect && this.rhDatasource?.length) { // this.rhDatasource[0].select = true; // this.rhSelectData = this.rhDatasource[0]; // this.rhSelectDataChange.emit(this.rhSelectData); // this.rhDatasource = [...this.rhDatasource]; // } // } onSelectItem(item: RhSelectableDto & { [propName: string]: string }) { if (item.disable) { return; } if (this.rhInspectItem.InspectMode === 'Quantitative') { this.dataset.forEach((ele) => (ele.select = ele === item)); } else { item.select = !item.select; } this.rhSelectData = this.dataset.filter((ele) => ele.select); this.rhSelectDataChange.emit(this.rhSelectData); } datasetArrayHandler(datas: RhSelectableDto[] | string[]): RhSelectableDto[] { datas = datas || []; return [...datas] as RhSelectableDto[]; } /** 只有IQC/OQC才需要做sn的限制,OBA选择的是箱条码 */ updateItemDisabelStatus() { // 定性不用更新disable状态 if (this.rhInspectItem?.InspectMode === 'Qualitative' || !this.dataset?.length || this.rhSnInspectCategory === 'OBA') { return; } if (!this.rhSnList?.length) { this.dataset.forEach((ele) => (ele.disable = false)); } this.dataset.forEach((ele) => { if (this.rhSnList.includes(ele.Value as string) && !ele.select) { ele.disable = true; } else { ele.disable = false; } }); } getSnDatas() { const queryDto = IqcMaterialInspectOrderSNPoolQueryDto.create(); queryDto.InspectOrderCode = this.rhData.InspectOrderCode; queryDto.Mode = 8; this.dataLoading = true; this.apiUrl.httpHandler(this.rhSnGetInterfaceInfo, queryDto).subscribe( (result) => { if (result.Success) { if (this.rhSnInspectCategory === 'OBA') { const tempDatas = result.Attach.map((ele: RhSafeAny) => new RhSelectItem(ele.ContainerSN, ele.ContainerSN)); this.dataset = ArrayHelper.uniqWith(tempDatas, (a, b) => a.Value === b.Value); } else { this.dataset = result.Attach.map((ele: RhSafeAny) => new RhSelectItem(ele.SN, ele.SN)); } this.updateItemSelectStatus(); this.updateItemDisabelStatus(); } else { this.dataset = []; MsgHelper.ShowWarningMessage(`查询无SN数据!${result.Message}`); } this.dataLoading = false; }, () => (this.dataLoading = false) ); } /** 根据检验模式设置sn的选中状态 */ private updateItemSelectStatus() { if (this.rhSnList?.length && this.rhInspectItem?.InspectMode === 'Qualitative') { this.dataset.forEach((ele) => { ele.select = this.rhSnList.find((data) => ele.Value === data) ? true : false; }); // this.rhSelectDataChange.emit([]); } else { this.dataset.forEach((ele) => (ele.select = false)); } if (this.rhInspectItem?.InspectMode === 'Quantitative') { this.dataset.forEach((ele) => { ele.select = ele.Value === this.rhInspectItem['SN']; }); } } }