import { RhApiUrlsService } from 'rh-base/core'; import { RhSelectItem, RhSafeAny } from 'rh-base/model'; import { Component, Input, Output, EventEmitter, OnChanges, SimpleChanges, TemplateRef, OnInit } from '@angular/core'; @Component({ selector: 'rh-inspect-group-radio', templateUrl: './inspect-group-radio.component.html', styleUrls: ['./inspect-group-radio.component.less'] }) export class RhInspectGroupRadioComponent implements OnInit, OnChanges { @Input() rhDatasource: RhSelectItem[] = []; @Output() rhSelectedDataChange = new EventEmitter(); @Input() rhSelectedData = ''; @Input() rhSampleQty = []; @Input() rhIsShowBadge = true; @Input() rhContentTpl!: TemplateRef; @Input() rhAttachFile!: TemplateRef; dataset: RhSelectItem[] = []; SampleQty!: number; inspectGroupDataset: RhSelectItem[] = []; constructor(public apiurl: RhApiUrlsService) { // } ngOnInit() { this.dataset = this.datasetHandler(this.rhDatasource); } ngOnChanges(changes: SimpleChanges) { const { rhDatasource } = changes; if (rhDatasource && !rhDatasource.firstChange && rhDatasource?.currentValue?.length) { this.dataset = this.datasetHandler(this.rhDatasource); } } onSelctedDataChange(item: string) { // for (let i = 0; i < this.rhSampleQty.length; i++) { // if (item == this.rhDatasource[i].Value) { // this.SampleQty = this.rhSampleQty[i]; // } // } this.rhSelectedData = item; this.rhSelectedDataChange.emit(item); } datasetHandler(datas: RhSelectItem[]) { // const temp = new RhSelectItem('全部', 'all'); // temp.select = true; // this.rhSelectedData = temp; // datas.unshift(temp); if (datas.every((ele) => !ele.select)) { datas[0].select = true; this.rhSelectedData = datas[0].Value as string; this.rhSelectedDataChange.emit(datas[0]?.Value as string); this.SampleQty = this.rhSampleQty[0]; } return [...datas]; } }