import { RhSelectableDto, RhSafeAny } from 'rh-base/model'; import { Component, OnInit, Input, Output, EventEmitter, SimpleChanges } from '@angular/core'; /** * 点击可以重复选择,向上推送同一列表项目 */ @Component({ selector: 'rh-repeat-select-list', templateUrl: './repeat-select-list.component.html', styleUrls: ['./repeat-select-list.component.less'] }) export class RepeatSelectListComponent implements OnInit { @Input() rhData: RhSelectableDto[] = []; @Input() rhDataLoading = false; @Input() rhName!: string; @Input() rhDisplayName!: string; @Input() rhShowAdvancedSearchBtn = true; // @Input() rhSelectedData: RhSelectableDto[] | null = null; // @Output() rhSelectedDataChange = new EventEmitter(); @Output() rhClickDataChange = new EventEmitter(); @Output() rhClickAdvancedSearch = new EventEmitter(); searchString = ''; dataset: RhSelectableDto[] = []; constructor() { // } ngOnInit(): void { // } ngOnChanges(changes: SimpleChanges) { const { rhData } = changes; if (rhData && rhData.currentValue) { this.dataset = [...rhData.currentValue]; } } clickToSelect(item: RhSelectableDto) { this.rhClickDataChange.emit(item); } submit() { // 先置空 this.dataset = []; if (this.searchString.trim() !== '') { this.dataset = this.rhData.filter((item) => { return this.filterOption( this.searchString, item[this.rhName] + item[this.rhDisplayName] + (item['OrganizationDisplayName'] ? item['OrganizationDisplayName'] : '') ); }); } else { this.dataset = [...this.rhData]; } } setSearchString(ele: string) { this.searchString = ele; } // 前端搜索 private filterOption(inputValue: string, item: RhSafeAny): boolean { return item.indexOf(inputValue) > -1; } advancedSearch() { this.rhClickAdvancedSearch.emit(); } }