import { RhSharedService } from './../../shared.service'; import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output, SimpleChanges } from '@angular/core'; import { provideValueAccessor } from 'rh-base/core'; import { RhSafeAny } from 'rh-base/model'; import { EmployeeMessageNotifyGroupConfigDto, View_MessageNotifyGroupDto, View_MessageNotifyGroupQueryDto } from './../../../emp-model'; import { ControlValueAccessor } from '@angular/forms'; @Component({ selector: 'rh-equip-maintenance-staff-manage-selector', templateUrl: './maintenance-staff-manage.component.html', styleUrls: ['./maintenance-staff-manage.component.less'], providers: [provideValueAccessor(RhMaintenanceStaffManageSelectorComponent)] }) export class RhMaintenanceStaffManageSelectorComponent implements OnInit, ControlValueAccessor { @Input() rhMinSize = '300px'; @Input() rhSize = '500px'; @Input() rhChange!: number; @Input() rhTitle = '选择负责人'; @Input() rhModuleKey!: string; @Input() rhModuleName!: string; /** 选中的人员 */ @Output() rhSelectedEmp = new EventEmitter(); @Output() rhSelectedEmps = new EventEmitter(); /**清空选项 */ @Output() clearInputChange = new EventEmitter(); seletedEmp!: View_MessageNotifyGroupDto; //外部组件传过来的业务组 @Input() BusinessGroupValue!: EmployeeMessageNotifyGroupConfigDto; //选中的业务组 @Output() rhSelectedGroup = new EventEmitter(); selectedIndex = 0; editGroupDto!: EmployeeMessageNotifyGroupConfigDto; @Input() EmpPersonName: View_MessageNotifyGroupDto | null = null; @Input() isShowDataModal = false; @Input() rhPlaceholder!: string; /** 是否启用多选 */ @Input() rhEnableMultiple!: boolean; empPersonNames: RhSafeAny[] = []; _value!: string | number | Date | null; _oldValue!: string | number | Date | null; get value() { return this._value; } set value(value: string | number | Date | null) { this._oldValue = this._value; this._value = value; if (this._oldValue !== this._value) { this.onChange(value); // this.getBoolDisplayInfo(); } } onChange = (value: RhSafeAny) => { if (Array.isArray(value)) { this.empPersonNames = value; } }; onTouched: () => RhSafeAny = () => { // }; constructor(private cdr: ChangeDetectorRef, private operator: RhSharedService) {} ngOnInit() { // } ngOnChanges(changes: SimpleChanges) { const { EmpPersonName, rhEnableMultiple } = changes; if (EmpPersonName && EmpPersonName.currentValue) { const emp = EmpPersonName.currentValue; if (emp.EmployeeName) { this.EmpPersonName = View_MessageNotifyGroupDto.create(); this.EmpPersonName.EmployeeName = emp.EmployeeName; } else if (!emp.EmployeeName && emp.EmployeeCode) { const queryDto = View_MessageNotifyGroupQueryDto.create(); queryDto.EmployeeCode = '$' + emp.EmployeeCode; this.operator.GetEmployeeMessageNotifyGroupViewDatas(queryDto).subscribe((result) => { if (result && result.Success) { this.EmpPersonName = result.Attach[0]; } // else { // this.EmpPersonName = null; // } }); } else if (!emp.EmployeeName && !emp.EmployeeCode) { this.EmpPersonName = null; } } } openEmpPersonModal(event?: Event) { if (event) { event.stopImmediatePropagation(); event.preventDefault(); } this.isShowDataModal = true; } closeDataModal() { this.isShowDataModal = false; } getDataChange(data: RhSafeAny) { if (!Array.isArray(data)) { this.EmpPersonName = data; this.rhSelectedEmp.emit(data); } else { this.empPersonNames = data.map((e) => e.EmployeeName); this.rhSelectedEmps.emit(data); } } getGroupChange(data: EmployeeMessageNotifyGroupConfigDto) { this.rhSelectedGroup.emit(data); } writeValue(obj: RhSafeAny): void { this.value = obj; if (!this.value) { this.EmpPersonName = null; this.empPersonNames = []; this.clearInputChange.emit(); } this.cdr.markForCheck(); } registerOnChange(fn: (value: RhSafeAny) => void): void { this.onChange = fn; } registerOnTouched(fn: () => RhSafeAny): void { this.onTouched = fn; } clearEmpPerson() { this.value = null; this.EmpPersonName = null; this.empPersonNames = []; this.clearInputChange.emit(); } }