import { Component, OnInit, ViewChild } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { MsgHelper } 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 { ClassGroupDefineDto, ClassGroupDefineQueryDto, ClassGroupManageDto, ClassGroupManageQueryDto, EmployeeClassGroupBatchStoreDto } from '../../mdp-model'; import { RhEmployeeManageService } from '../employee-manage.service'; // 班组管理 @Component({ selector: 'rh-class-group-manage', templateUrl: './class-group-manage.component.html', styleUrls: ['./class-group-manage.component.less'] }) export class RhClassGroupManageComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; selectedIndex = 0; dataLoading = false; dataresult!: DataResultT; defaultFieldDataset: RhDynamicComponentFieldType[] = []; editDto: RhBaseDto = {}; defaultQueryDto: RhSafeAny = {}; defaultEditDto: RhSafeAny = {}; isShowBindClassGroup = false; classGropDatas: ClassGroupDefineDto[] = []; classGropDataset: ClassGroupDefineDto[] = []; selectedDataset: ClassGroupDefineDto[] = []; selectEmployee: RhSafeAny; selectEmployeeName = '绑定员工'; classGropBoundDataset = { Attach: [] as ClassGroupManageDto[] } as DataResultT; groupdeData: RhSafeAny; // 查看绑定的班组 openClassGroupBound = false; searchString = ''; isAllCheck = false; titleButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto('newButton', '新建', 'primary', 'file', false, null, () => this.openEditTab(), true) ]; boundButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('backButton', '返回', 'default', false, 'rollback', false, null, () => this.closeClassGroupBound(), true) ]; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'bind', '绑定班组', 'primary', false, 'link', false, null, (data) => this.BindClassGroup(data as RhBaseDto), false ), new RhTableButtonInfoDto( 'config', '所属班组', 'default', false, 'eye', false, null, (data) => this.showClassGroupBound(data as RhBaseDto), true ) // new RhTableButtonInfoDto('edit', '编辑', 'default', 'edit', false, null, (data) => this.openEditTab(data as RhBaseDto), true) ]; constructor( private route: ActivatedRoute, public operator: RhEmployeeManageService, // private navigator: RhNavigatorService, private router: Router ) { // } ngOnInit(): void { this.initQueryDto(); } initQueryDto() { // 要在html中自定义表单组件里传值给rhValue this.route.queryParamMap.subscribe((result) => { this.defaultQueryDto.ClassGroupCode = result.get('ClassGroupCode'); this.defaultQueryDto.ClassGroupName = result.get('ClassGroupName'); // 编辑form给员工信息赋值 this.defaultEditDto.ClassGroupCode = result.get('ClassGroupCode'); this.defaultEditDto.ClassGroupName = result.get('ClassGroupName'); }); } 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; } removeDatas() { //· } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(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.getDatas(); } else { MsgHelper.ShowWarningMessage(`数据线存储失败${result.Message}`); } } BindClassGroup(data: RhBaseDto) { this.selectedDataset = []; this.selectEmployee = data; this.selectEmployeeName = '绑定员工: ' + this.selectEmployee.EmployeeCode + ' (' + this.selectEmployee.EmployeeName + ')'; this.isShowBindClassGroup = true; const queryDto = ClassGroupDefineQueryDto.create(); queryDto.Mode = 8; this.operator.GetClassGroupDefineDatas(queryDto).subscribe((result) => { if (result && result.Success) { this.classGropDatas = result.Attach; this.classGropDataset = [...this.classGropDatas]; } else { this.classGropDatas = []; this.classGropDataset = []; } }); } closeBindClassGroup() { this.isShowBindClassGroup = false; } submit() { // 先置空 this.classGropDataset = []; if (this.searchString.trim() !== '') { this.classGropDataset = this.classGropDatas.filter((item) => { return this.filterOption(this.searchString, (item['ClassGroupCode'] as string) + item['ClassGroupName'] + item['ClassGroupType']); }); } else { this.classGropDataset = [...this.classGropDatas]; } } setSearchString(ele: string) { // console.log(ele); this.searchString = ele; } allCheckChange(status: boolean) { this.classGropDataset.forEach((ele) => (ele.select = status)); this.ngModelChange(null); } // 前端搜索 private filterOption(inputValue: string, item: RhSafeAny): boolean { return item.indexOf(inputValue) > -1; } ngModelChange(item: RhSafeAny) { let tempDatas = {} as ClassGroupDefineDto; if (item.select === true) { tempDatas = item; this.selectedDataset.push(tempDatas); this.selectedDataset = [...this.selectedDataset.sort((a, b) => (a.Id as number) - (b.Id as number))]; } else if (item.select === false) { this.selectedDataset.forEach((ele) => { if (ele.select === false) { this.deleteItem(ele); } }); } } deleteItem(item: ClassGroupDefineDto) { const temp = this.classGropDataset.find((ele) => ele.ClassGroupCode === item.ClassGroupCode); if (temp) { temp.select = false; this.classGropDataset = [...this.classGropDataset]; } const index = this.selectedDataset.findIndex((ele) => ele.ClassGroupCode === item.ClassGroupCode); this.selectedDataset.splice(index, 1); this.selectedDataset = [...this.selectedDataset]; } BindSelected() { const queryDto = EmployeeClassGroupBatchStoreDto.create(); queryDto.EmployeeCode = this.selectEmployee.EmployeeCode; queryDto.EmployeeName = this.selectEmployee.EmployeeName; queryDto.ClassGroupDefineDtos = this.selectedDataset; this.operator.StoreEmployeeClassGroupDatas(queryDto).subscribe((result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage('班组绑定成功!'); this.closeBindClassGroup(); this.getDatas(); } else { MsgHelper.ShowWarningMessage(`绑定失败${result.Message}`); } }); } showClassGroupBound(data: RhBaseDto) { this.groupdeData = data; this.openClassGroupBound = true; this.selectedIndex = 1; if (data) { this.getGroupClassDataSource(); } } closeClassGroupBound() { this.openClassGroupBound = false; } getGroupClassDataSource() { const queryDto = ClassGroupManageQueryDto.create(); queryDto.EmployeeCode = this.groupdeData.EmployeeCode; queryDto.EmployeeName = this.groupdeData.EmployeeName; this.operator.GetClassGroupManageDatas(queryDto).subscribe((result) => { if (result && result.Success) { this.classGropBoundDataset.Attach = result.Attach; } else { this.classGropBoundDataset.Attach = []; MsgHelper.ShowWarningMessage('暂无绑定班组'); } this.classGropBoundDataset = { ...this.classGropBoundDataset }; }); } GroupdefineRefreshDatas() { this.getGroupClassDataSource(); } // // 跳转到班组维护 // navigateToClassGroupConfig(){ // // RhRouteHelper.navigateToUrl('main/FactoryModelling/ClassGroupDefine'); // // this.navigator.navigatorTrigger('RH_ClassGroupDefine'); // this.router.navigate(['/main/FactoryModelling/ClassGroupDefine'], {relativeTo: this.route}); // } // 跳转到班组维护 navigateToClassGroupConfig() { // this.navigator.navigatorTrigger('RH_ClassGroupDefine'); this.router.navigate(['../ClassGroupDefine'], { relativeTo: this.route }); } }