import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core'; import { MsgHelper, RhNavigatorService } from 'rh-base/core'; import { CodeClassModel, DataResultT, OpMode, RhBaseDto, RhDynamicComponentFieldType, RhDynamicTableFieldDto, RhSafeAny, RhSelectableDto, RhTableButtonInfoDto, RhTableQueryOptionDto } from 'rh-base/model'; import { DynamicFormComponent } from 'rh-base/shared'; import { ClassGroupManageDto, ClassGroupManageQueryDto, FullEmployeeInfoDto } from '../../mdp-model'; import { RhEmployeeManageService } from '../employee-manage.service'; @Component({ selector: 'rh-class-group-define', templateUrl: './class-group-define.component.html', styleUrls: ['./class-group-define.component.less'] }) export class RhClassGroupDefineComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; @ViewChild('employeeQueryForm', { static: false }) employeeQueryFormCmt!: DynamicFormComponent; selectedIndex = 0; isShowEdit = false; dataLoading = false; dataresult!: DataResultT; employeeDataresult!: DataResultT; defaultFieldDataset: RhDynamicComponentFieldType[] = []; editDto: RhBaseDto = {}; isShowEmployeeSelect = false; /** 选中的员工信息 */ selectedData: ClassGroupManageDto[] = []; /** 选中的班组信息 */ classGroupDatas!: ClassGroupManageDto; /**选中的员工 */ selectedDataset: FullEmployeeInfoDto[] = []; tempDatas: RhSafeAny; openClassGroupDefine = false; GroupdefineDataresult = { Attach: [] as ClassGroupManageDto[] } as DataResultT; groupdeData: RhSafeAny; rhModel: RhSelectableDto = {}; titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('new', '新建', 'primary', false, 'file', false, null, () => this.openEditTab(), true) ]; modalTitleButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto('bind', '绑定', 'primary', 'link', false, null, (data) => this.Bind(data as ClassGroupManageDto[]), false) ]; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('edit', '编辑', 'default', false, 'edit', false, null, (data) => this.openEditTab(data as RhBaseDto), true), new RhTableButtonInfoDto( 'bind', '员工班组配置', 'default', false, 'paper-clip', false, null, (data) => this.employeeBind(data as RhBaseDto), true ), new RhTableButtonInfoDto( 'config', '员工列表', 'default', false, 'eye', false, null, (data) => this.showClassGroupDefine(data as RhBaseDto), true ) ]; boundButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('backButton', '返回', 'default', false, 'rollback', false, null, () => this.ClassGroupDefine(), true) ]; constructor(private navigator: RhNavigatorService, private operator: RhEmployeeManageService, private cdr: ChangeDetectorRef) { // } 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.isShowEdit = true; this.selectedIndex = 1; } closeEditTab() { this.selectedIndex = 0; this.isShowEdit = false; } removeDatas() { //· } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(option); } setemployeeDatas(dataset: DataResultT) { this.employeeDataresult = dataset; } employeeRefreshDatas(option: RhTableQueryOptionDto) { this.getEmployeeDatas(option); } private getEmployeeDatas(option?: RhTableQueryOptionDto) { if (this.employeeQueryFormCmt) { this.employeeQueryFormCmt.submitDefaultForm(null, option); } } private getDatas(option?: RhTableQueryOptionDto) { if (this.queryFormCmt) { this.queryFormCmt.submitDefaultForm(null, option); } } onStoreDatas(result: DataResultT) { if (result && result.Success) { const msg = this.editDto.OpSign === OpMode.OpAdd ? '新增' : '编辑'; MsgHelper.ShowSuccessMessage(`数据${msg}成功`); this.selectedIndex = 0; this.isShowEdit = false; this.getDatas(); } else { MsgHelper.ShowWarningMessage(`数据线存储失败${result.Message}`); } } getGroupClassDataSource() { const queryDto = ClassGroupManageQueryDto.create(); queryDto.ClassGroupCode = this.groupdeData.ClassGroupCode; queryDto.ClassGroupName = this.groupdeData.ClassGroupName; this.operator.GetClassGroupManageDatas(queryDto).subscribe((result) => { if (result && result.Success) { this.GroupdefineDataresult.Attach = result.Attach; } else { this.GroupdefineDataresult.Attach = []; MsgHelper.ShowWarningMessage('暂无员工绑定'); } this.GroupdefineDataresult = { ...this.GroupdefineDataresult }; }); } GroupdefineRefreshDatas() { this.getGroupClassDataSource(); } // 跳转到班组配置 showClassGroupDefine(data: RhSafeAny) { this.groupdeData = data; this.openClassGroupDefine = true; this.selectedIndex = 1; this.isShowEdit = false; if (data) { this.getGroupClassDataSource(); } // console.log(data); // this.navigator.navigatorTrigger('RH_ClassGroupManage', { ClassGroupCode: data.ClassGroupCode, ClassGroupName: data.ClassGroupName }); } // 跳转到员工班组 navigateToClassGroupManage() { this.navigator.navigatorTrigger('RH_ClassGroupManage'); } //关闭员工班组tab页 ClassGroupDefine() { this.openClassGroupDefine = false; this.selectedIndex = 0; this.isShowEdit = false; this.GroupdefineDataresult.Attach = []; } // 批量绑定员工 employeeBind(data: RhSafeAny) { this.isShowEmployeeSelect = true; this.selectedIndex = 1; this.isShowEdit = false; this.classGroupDatas = data; this.getEmployeeDatas(); this.selectedDataset = []; // const queryDto=ClassGroupManageQueryDto.create(); // queryDto.ClassGroupCode=data.ClassGroupCode; // queryDto.ClassGroupName=data.ClassGroupName; // this.operator.GetClassGroupManageDatas(queryDto).subscribe(result=>{ // if(result&&result.Success){ // result.Attach.forEach(ele=>{ // const tempDtos={} as FullEmployeeInfoDto; // tempDtos.EmployeeCode=ele.EmployeeCode; // tempDtos.EmployeeName=ele.EmployeeName; // tempDtos.ClassGroupCode=this.classGroupDatas.ClassGroupCode; // tempDtos.ClassGroupName=this.classGroupDatas.ClassGroupName; // this.selectedDataset.push(tempDtos); // }); // }else{ // this.selectedDataset=[]; // MsgHelper.ShowWarningMessage('暂无员工绑定'); // } // }); } closeEmployeeSelect() { this.isShowEmployeeSelect = false; this.selectedIndex = 0; this.isShowEdit = false; this.selectedData = []; this.selectedDataset.forEach((ele) => { this.employeeDataresult.Attach.forEach((item) => { if (ele.EmployeeCode === item.EmployeeCode) { item.select = true; } }); }); } Bind(data: ClassGroupManageDto[]) { // data.forEach(ele=>{ // const temp={} as ClassGroupManageDto; // temp.EmployeeCode=ele.EmployeeCode; // temp.EmployeeName=ele.EmployeeName; // temp.ClassGroupCode=this.classGroupDatas.ClassGroupCode; // temp.ClassGroupName=this.classGroupDatas.ClassGroupName; // this.selectedData.push(temp); // }); // 利用语法糖map()映射 this.selectedData = data.map((ele) => { const temp = {} as ClassGroupManageDto; temp.EmployeeCode = ele.EmployeeCode; temp.EmployeeName = ele.EmployeeName; temp.ClassGroupCode = this.classGroupDatas.ClassGroupCode; temp.ClassGroupName = this.classGroupDatas.ClassGroupName; return temp; }); this.operator.StoreClassGroupManageDatas(this.selectedData).subscribe((result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage('绑定成功!'); this.closeEmployeeSelect(); } else { MsgHelper.ShowWarningMessage(`绑定失败!${result.Message}`); } }); } setSelectDatas(items: FullEmployeeInfoDto[]) { this.selectedDataset = items ? [...items.sort((a, b) => a['SortId'] - b['SortId'])] : []; } deleteItem(item: FullEmployeeInfoDto) { const temp = this.employeeDataresult.Attach.find((ele) => ele.EmployeeCode === item.EmployeeCode); if (temp) { temp.select = false; this.employeeDataresult.Attach = [...this.employeeDataresult.Attach]; } const index = this.selectedDataset.findIndex((ele) => ele.EmployeeCode === item.EmployeeCode); this.selectedDataset.splice(index, 1); this.selectedDataset = [...this.selectedDataset]; } BindSelected() { const queryDto = this.selectedDataset.map((ele) => { const selectDtos = {} as ClassGroupManageDto; selectDtos.EmployeeCode = ele.EmployeeCode; selectDtos.EmployeeName = ele.EmployeeName; selectDtos.ClassGroupCode = this.classGroupDatas.ClassGroupCode; selectDtos.ClassGroupName = this.classGroupDatas.ClassGroupName; return selectDtos; }); this.operator.StoreClassGroupManageDatas(queryDto).subscribe((result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage('绑定成功!'); this.closeEmployeeSelect(); } else { MsgHelper.ShowWarningMessage(`绑定失败!${result.Message}`); } }); } }