import { RhSafeAny } from 'rh-base/model'; import { ChangeDetectorRef, Component, Input, OnInit, SimpleChanges } from '@angular/core'; import { RhControlValueAccessorComponent } from 'rh-base/shared'; import { RhAndonSystemService } from '../../../andon-system.service'; import { provideValueAccessor } from 'rh-base/core'; @Component({ selector: 'rh-andon-use-push-down-strategy', templateUrl: './andon-use-push-down-strategy.component.html', styleUrls: ['./andon-use-push-down-strategy.component.css'], providers: [provideValueAccessor(AndonUsePushDownStrategyComponent)] }) export class AndonUsePushDownStrategyComponent extends RhControlValueAccessorComponent implements OnInit { @Input() rhConfig!: { type: 'number' | 'string' | 'select'; data: []; key: string; display: boolean; associatedField: { key: string; value: string }[]; selectValue: 'Value'; selectKey: 'Text'; }; @Input() rhEditDto: RhSafeAny; @Input() rhPlaceHolder = ''; sub: RhSafeAny; selectItem: RhSafeAny = {}; constructor(cdk: ChangeDetectorRef, private andonSystemService: RhAndonSystemService) { super(cdk); } ngOnChanges(changes: SimpleChanges): void { // console.log(this.value, changes); // console.log('ngOnChanges中inputVal变更后值为:'+ changes['inputVal'].currentValue); if (changes['rhEditDto'] && changes['rhConfig']) { const dto: RhSafeAny = changes['rhEditDto'].currentValue; const config: RhSafeAny = changes['rhConfig'].currentValue; if (config?.associatedField?.length > 0) { const item: RhSafeAny = {}; item[config.selectKey] = dto[config.key]; config.associatedField.forEach((el: RhSafeAny) => { item[config.selectValue] = dto[el.key]; }); this.selectItem = this.rhConfig.data.find((f: RhSafeAny) => { return f.Text == item.Text && f.Value == item.Value; }); // console.log(this.selectItem); } } } ngOnInit(): void { this.sub = this.andonSystemService.getValueSource().subscribe((f) => { const arr = Object.keys(f); if (this.rhConfig.associatedField && this.rhConfig.associatedField.find((g) => arr.find((h) => g.key === h))) { this.selectItem = this.rhConfig.data.find((g) => JSON.stringify(g) == JSON.stringify(f[arr[0]])) || {}; } }); } change(event: RhSafeAny) { const obj: Record = {}; obj[`${this.rhConfig.key}`] = event; this.andonSystemService.sendMessage(JSON.stringify(obj)); } ngOnDestroy() { this.sub && this.sub.unsubscribe(); } }