import { RhQmpService } from './../../qmp.service'; import { EmployeeMessageNotifyGroupConfigDto, View_MessageNotifyGroupDto, EmployeeMessageNotifyGroupConfigQueryDto, View_MessageNotifyGroupQueryDto } from './../../qmp-model'; import { RhSafeAny, DataResultT, RhDynamicComponentFieldType } from 'rh-base/model'; import { provideValueAccessor, MsgHelper } from 'rh-base/core'; import { Component, OnInit, Input } from '@angular/core'; import { ControlValueAccessor } from '@angular/forms'; import { NzSizeLDSType } from 'ng-zorro-antd/core/types'; @Component({ selector: 'rh-inspector-selector', templateUrl: './inspector-selector.component.html', styleUrls: ['./inspector-selector.component.less'], providers: [provideValueAccessor(RhInspectorSelectorComponent)] }) export class RhInspectorSelectorComponent implements OnInit, ControlValueAccessor { // QualityInspectGroup QualityInspector /** 键值:设备管理或者质量管理 */ @Input() rhModuleKey: 'QualityManagement' | 'EquipmentManagement' = 'QualityManagement'; @Input() rhSize!: NzSizeLDSType; @Input() rhDisabled!: boolean; @Input() rhPlaceholder!: string; @Input() rhIcon!: string; /** 整个form的数据 */ @Input() rhData: RhSafeAny; // /** 选中的人员 */ // @Output() rhSelectedEmp = new EventEmitter(); selectedGroupDto: View_MessageNotifyGroupDto | null = null; _displayName!: string; get displayName() { return this._displayName; } set displayName(value: string) { this._displayName = value; } onChange!: (value: string) => void; onTouched!: (value: string) => void; isShowModal = false; messageNotifyGroups: EmployeeMessageNotifyGroupConfigDto[] = []; messageNotifyGroupsLoading = false; dataLoading = false; dataresult = { Attach: [] } as unknown as DataResultT; defaultFieldDataset: RhDynamicComponentFieldType[] = []; defaultQueryDto!: View_MessageNotifyGroupQueryDto; qualityInspector = 'QualityInspector'; qualityInspectGroup = 'QualityInspectGroup'; /** 设置默认的table显示字段 */ defaultTableFieldDataset = [ { name: 'EmployeeCode', displayName: '员工代码', width: 120 }, { name: 'EmployeeName', displayName: '员工名称', width: 140 }, { name: 'EmailAddress', displayName: '邮箱地址', width: 140 }, { name: 'TelPhone', displayName: '手机电话', width: 120 }, { name: 'EnterpriseWeChatId', displayName: '企业微信ID', width: 120 }, { name: 'DingDingChatId', displayName: '钉钉ID', width: 120 } ]; constructor(public operator: RhQmpService) { // } ngOnInit(): void { this.rhIcon = this.rhIcon || 'search'; this.rhPlaceholder = this.rhPlaceholder || '选择检验人'; this.getEmployeeMessageNotifyGroupConfigDatas(); } clearInputInfo() { this.rhData[this.qualityInspectGroup] = null; this.rhData[this.qualityInspector] = null; this.displayName = ''; this.onChange(''); } confirm() { this.rhData[this.qualityInspectGroup] = this.selectedGroupDto?.GroupKey; this.rhData[this.qualityInspector] = this.selectedGroupDto?.EmployeeCode; this.onChange(this.rhData[this.qualityInspector]); this.displayName = `${this.selectedGroupDto?.EmployeeCode}:${this.selectedGroupDto?.GroupName}`; this.closeModal(); } closeModal() { this.isShowModal = false; this.selectedGroupDto = null; } openModal() { if (this.rhDisabled) { MsgHelper.ShowWarningMessage(`该字段禁止编辑`); return; } this.isShowModal = true; } getEmployeeMessageNotifyGroupConfigDatas() { const queryDto = EmployeeMessageNotifyGroupConfigQueryDto.create(); queryDto.ModuleKey = this.rhModuleKey; queryDto.IsEnable = true; queryDto.Mode = 8; this.messageNotifyGroupsLoading = true; this.operator.GetEmployeeMessageNotifyGroupConfigDatas(queryDto).subscribe( (result) => { if (result.Success) { this.messageNotifyGroups = result.Attach; // if (this.selectedMessageNotifyGroup) { // const temp = this.messageNotifyGroups.find( // (f) => f.ModuleKey === this.selectedMessageNotifyGroup.ModuleKey && f.GroupKey === this.selectedMessageNotifyGroup.GroupKey // ); // if (temp) { // temp.select = true; // } // } } else { this.messageNotifyGroups = []; MsgHelper.ShowWarningMessage(`查询无数据!${result.Message}`); } this.messageNotifyGroupsLoading = false; }, () => { this.messageNotifyGroupsLoading = false; } ); } getCheckedData(data: EmployeeMessageNotifyGroupConfigDto) { // this.selectedMessageNotifyGroup = data; this.defaultQueryDto = { ModuleKey: this.rhModuleKey, GroupKey: data.GroupKey, GroupName: data.GroupName } as View_MessageNotifyGroupQueryDto; setTimeout(() => { this.getDatas(); }); } //选择中的人员 getSelectedEmp(data: View_MessageNotifyGroupDto) { //this.rhSelectedEmp.emit(data); this.selectedGroupDto = data; } refreshDatas() { this.getDatas(); } writeValue(obj: string): void { this.displayName = obj; } registerOnChange(fn: (value: string) => void): void { this.onChange = fn; } registerOnTouched(fn: (value: string) => void): void { this.onTouched = fn; } setDisabledState?(isDisabled: boolean): void { this.rhDisabled = isDisabled; } //调用子组件中的接口 private getDatas() { if (this.defaultQueryDto) { this.defaultQueryDto.Mode = 8; } this.operator.GetEmployeeMessageNotifyGroupViewDatas(this.defaultQueryDto).subscribe((result) => { if (result && result.Success) { this.dataresult = result; } else { this.dataresult.Attach = []; } this.dataresult = { ...this.dataresult }; }); } }