import { RhSafeAny } from 'rh-base/model'; import { provideValueAccessor } from 'rh-base/core'; import { RhControlValueAccessorComponent } from 'rh-base/shared'; import { Component, ChangeDetectorRef, AfterViewInit } from '@angular/core'; import { isNil } from 'lodash'; @Component({ selector: 'rh-transfer-rule-input', templateUrl: './transfer-rule-input.component.html', styleUrls: ['./transfer-rule-input.component.less'], providers: [provideValueAccessor(TransferRuleInputComponent)] }) export class TransferRuleInputComponent extends RhControlValueAccessorComponent implements AfterViewInit { firstNumber = 0; lastNumber = 0; timer: RhSafeAny; constructor(cdk: ChangeDetectorRef) { super(cdk); } ngAfterViewInit(): void { if (!this.value) { this.value = '0-0'; } this.valueParser(this.value as string); } setValue() { if (this.timer) { clearTimeout(this.timer); } this.timer = setTimeout(() => { this.firstNumber = isNil(this.firstNumber) ? 0 : this.firstNumber; this.lastNumber = isNil(this.lastNumber) ? 0 : this.lastNumber; this.value = `${this.firstNumber}-${this.lastNumber}`; }, 200); } private valueParser(value: string) { const tempDatas = value.split('-'); this.firstNumber = Number.parseInt(tempDatas[0]) || 0; this.lastNumber = Number.parseInt(tempDatas[1]) || 0; this.value = `${this.firstNumber}-${this.lastNumber}`; } }