Newer
Older
import {Component, OnInit, ViewChild} from '@angular/core';
import {NzMessageService, NzModalService, NzTreeNode, NzTreeNodeOptions} from 'ng-zorro-antd';
import {SystemService} from '../system.service';
import {GroupModalComponent} from '../modal/group-modal/group-modal.component';
import {SelectRoleComponent} from '../../modal/select-role/select-role.component';
import {CommonService} from '../../shared/common/common.service';
selector: 'jhi-group',
templateUrl: './group.component.html',
styles: []
@ViewChild('smartUser') smartUser: UserComponent;
@ViewChild('smartGroupModal') smartGroupModal: GroupModalComponent;
allChecked = false;
disabledButton = true;
indeterminate = false;
checkedNumber = 0;
nodes: any[];
isVisible = true;
constructor(private systemSer: SystemService, private message: NzMessageService,
private modalSer: NzModalService, private commonSer: CommonService) {
currentPageDataChange($event: Array<{ checked: boolean }>): void {
this.dataSet = $event;
selectItem(item,e){
if(e){
this.selectList.push(item);
}else{
this.selectList.forEach((value,index)=>{
if(value.id == item.id){
this.selectList.splice(index,1)
}
});
}
this.refreshStatus()
}
const allChecked = this.dataSet.every(value => value.checked === true);
const allUnChecked = this.dataSet.every(value => !value.checked);
this.allChecked = allChecked;
this.indeterminate = (!allChecked) && (!allUnChecked);
this.disabledButton = !this.dataSet.some(value => value.checked);
this.checkedNumber = this.dataSet.filter(value => value.checked).length;
}
mouseAction(name: string, e: any): void {
console.log(name, e);
}
ngOnInit() {
getOrg(e){
console.log(e);
this.organizationId = e.node.key;
this.getUser();
}
this.groupList.forEach(
res => {
res.title = res.name;
res.key = res.id;
}
);
this.nodeTree();
const tree = this.commonSer.listToTree('id', 'parentId', this.groupList,);
const list = tree.map(res => {
return new NzTreeNode(res);
});
this.nodes = list;
}
showModal(): void {
this.isVisible = true;
}
handleOk(): void {
this.isVisible = false;
}
handleCancel(): void {
this.isVisible = false;
}
this.modalSer.confirm({
nzTitle: '删除',
nzContent: '<b style="color: red">确定删除该用户吗</b>',
nzOkText: '确定',
nzCancelText: '取消',
nzOnOk: () => {
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//删除用户-- 批量
batchDelete(){
let bool = false;
this.dataSet.forEach(e=>{
if(e.checked){
bool = true;
}
});
if(!bool){
this.message.warning("请选择需要删除的用户");
return false;
}
let arr = [];
this.dataSet.forEach(e=>{
if(e.checked){
arr.push(e.user.id);
}
});
this.commonSer.deleteThing("确定删除选择的用户",()=>{
this.systemSer.batchDeleteUser(arr).subscribe(
(res) => {
if(res.errCode == 10000){
this.getUser();
}
}
);
})
}
showGroupModal() {
this.smartGroupModal.showModal(this.groupList);
//编辑部门
editGroup(item){}
//删除部门
deleteGroup(item){}
if(this.setType == "批量"){
const data = {
userId:this.selectList.map(
e=>{
return e.id;
}
),
roles:event.map(e=>{
return e.id;
}),
};
this.systemSer.batchUserToAuth(data).subscribe(
(res)=>{
if(res.errCode == 10000){
this.getUser();
this.message.success("授予角色成功");
}else{
this.message.error(res.errMsg);
}
)
}
if(this.setType == "单个"){
const data = {
userId:this.userId,
roles:event.map(e=>{
return e.id;
}),
};
this.systemSer.aloneUserToAuth(data).subscribe(
(res)=>{
if(res.errCode == 10000){
this.getUser();
this.message.success("授予角色成功");
}else{
this.message.error(res.errMsg);
}
}
)
}
}
selectRoleModal(){
this.setType = "批量";
this.smartSelectRole.showModal("选择角色",null);