import { Component, OnInit, ViewChild } from '@angular/core'; import { CodeClassModel, DataResultT, OpMode, RhBaseDto, RhDynamicComponentFieldType, RhDynamicTableFieldDto, RhSafeAny, RhSelectableDto, RhTableButtonInfoDto, RhTableQueryOptionDto } from 'rh-base/model'; import { ExtResourceInfoDto, ExtResourceInfoQueryDto, ResourceInfoDto } from '../../mdp-model'; import { RhEmployeeManageService } from '../employee-manage.service'; import { MsgHelper, ObjectHelper } from 'rh-base/core'; import { DynamicFormComponent } from 'rh-base/shared'; @Component({ selector: 'rh-resource-info', templateUrl: './resource-info.component.html', styleUrls: ['./resource-info.component.less'] }) export class RhResourceInfoComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; selectedIndex = 0; dataLoading = false; dataresult!: DataResultT; defaultFieldDataset: RhDynamicComponentFieldType[] = []; editDto: RhBaseDto = {}; titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('new', '新建', 'primary', false, 'file', false, null, () => this.openEditTab(), true) ]; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('edit', '编辑', 'default', false, 'edit', false, null, (data) => this.openEditTab(data as RhBaseDto)) ]; extraButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('sync', '同步', 'primary', false, 'sync', false, null, () => this.openSyncModal(), true) ]; // 同步资源信息 isShowSyncModal = false; extDataLoading = false; syncResourceList: ExtResourceInfoDto[] = []; selectedSyncResource: ResourceInfoDto[] = []; constructor(private operator: RhEmployeeManageService) { // } ngOnInit(): void { // } dataLoadingChange(status: boolean) { this.dataLoading = status; } setDatas(dataset: DataResultT) { this.dataresult = dataset; } setInitFieldDataset(item: CodeClassModel) { const tempDatas: RhDynamicComponentFieldType[] = []; item.CodeProperties.forEach((ele) => { const temp = RhDynamicTableFieldDto.create(); temp.name = ele.PropertyName; temp.displayName = ele.Descirption; tempDatas.push(temp); }); this.defaultFieldDataset = [...tempDatas]; } openEditTab(data?: RhBaseDto) { if (data) { this.editDto = data; this.editDto.OpSign = OpMode.OpEdit; } else { this.editDto = {}; this.editDto.OpSign = OpMode.OpAdd; } this.selectedIndex = 1; } closeEditTab() { this.selectedIndex = 0; } refreshData(option: RhTableQueryOptionDto) { this.getDatas(option); } private getDatas(option?: RhTableQueryOptionDto) { if (this.queryFormCmt) { this.queryFormCmt.submitDefaultForm(null, option); } } onStoreData(result: DataResultT) { if (result && result.Success) { const msg = this.editDto.OpSign === OpMode.OpAdd ? '新增' : '编辑'; MsgHelper.ShowSuccessMessage(`数据${msg}成功`); if (this.editDto.OpSign === OpMode.OpEdit) { this.selectedIndex = 0; } this.editDto = ObjectHelper.createRhBaseDto(); this.getDatas(); } else { MsgHelper.ShowWarningMessage(`数据存储失败!${result.Message}`); } } // ************ 同步资源信息 ************** openSyncModal() { this.loadResourceFromOtherSystems(); this.isShowSyncModal = true; } closeSyncModal() { this.syncResourceList.forEach((ele) => (ele.select = false)); this.isShowSyncModal = false; } // 载入资源信息 loadResourceFromOtherSystems() { const queryDto = ExtResourceInfoQueryDto.create(); queryDto.Mode = 8; this.extDataLoading = true; this.operator.GetExtResourceInfo(queryDto).subscribe( (result) => { if (result && result.Success) { this.syncResourceList = result.Attach; } else { this.syncResourceList = []; MsgHelper.ShowWarningModal(`获取第三方用户数据失败!${result.Message}`); } this.extDataLoading = false; }, () => (this.extDataLoading = false) ); } // 获取所选资源信息 getSelectedDataset(dtos: ResourceInfoDto[]) { this.selectedSyncResource = dtos; } // 保存所选资源信息 saveResource() { this.operator.StoreResourceInfoDatas(this.selectedSyncResource).subscribe((result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage(`保存成功!`); this.syncResourceList = []; this.getDatas(); this.closeSyncModal(); } else { MsgHelper.ShowWarningModal(`保存失败!${result.Message}`); } }); } }