import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core'; import { CodeClassModel, DataResultT, RhDynamicTableFieldDto, RhSafeAny, RhSelectableDto, RhTableQueryOptionDto } from 'rh-base/model'; import { DynamicFormComponent } from 'rh-base/shared'; @Component({ selector: 'rh-emp-general-unit', templateUrl: './emp-general-unit.component.html', styleUrls: ['./emp-general-unit.component.less'] }) export class RhEmpGeneralUnitComponent implements OnInit, OnChanges { /** 是否打开单位Modal */ @Input() rhIsShowUnitModal = false; /** 选中的单位 */ @Output() rhSelectedUnit = new EventEmitter(); @ViewChild('UnitQueryForm', { static: false }) UnitQueryForm!: DynamicFormComponent; selectedIndex = 0; dataLoading = false; unitDataresult!: DataResultT; defaultFieldDataset: RhDynamicTableFieldDto[] = []; selectedUnit: RhSafeAny; constructor() { // } ngOnInit(): void { // } ngOnChanges(changes: SimpleChanges) { if (changes['rhIsShowUnitModal'].currentValue) { if (this.unitDataresult && this.unitDataresult.Attach.length) { this.unitDataresult.Attach.forEach((ele) => { ele.select = false; }); } else { // } this.unitDataresult = { ...this.unitDataresult }; this.selectedUnit = null; } } dataLoadingChange(status: boolean) { this.dataLoading = status; } setDatas(dataset: DataResultT) { this.unitDataresult = dataset; } setInitFieldDataset(item: CodeClassModel) { const tempDatas: RhDynamicTableFieldDto[] = []; item.CodeProperties.forEach((ele) => { const temp = RhDynamicTableFieldDto.create(); temp.name = ele.PropertyName; temp.displayName = ele.Descirption; tempDatas.push(temp); }); this.defaultFieldDataset = [...tempDatas]; } refreshData(option: RhTableQueryOptionDto) { this.getDatas(option); } private getDatas(option?: RhTableQueryOptionDto) { if (this.UnitQueryForm) { this.UnitQueryForm.submitDefaultForm(null, option); } } getSelectedUnit(data: RhSafeAny) { this.selectedUnit = data; } confirmSelect() { this.rhSelectedUnit.emit(this.selectedUnit); this.closeDataModal(); } closeDataModal() { this.rhIsShowUnitModal = false; } }