Newer
Older
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {NzTreeNode} from 'ng-zorro-antd';
import {SystemService} from '../../system/system.service';
import {CommonService} from '../../shared/common/common.service';
selector: 'smart-select-person',
templateUrl: './select-person.component.html',
styles: []
isVisible = false;
title;
groupList;
userList;
selectList = [];
nodes: any[];
allChecked = false;
checkedNumber = 0;
disabledButton = true;
indeterminate = false;
displayData: Array<{ key1: string; key2: number; key3: string; key4: string; checked: boolean }> = [];
constructor(private systemSer: SystemService, private commonSer: CommonService) {
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
}
checkAll(value: boolean): void {
this.displayData.forEach(data => data.checked = value);
this.refreshStatus();
}
currentPageDataChange($event: Array<{ key1: string; key2: number; key3: string; key4: string; checked: boolean }>): void {
this.displayData = $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()
}
deleteSelect(index){
this.selectList.splice(index,1);
}
refreshStatus(): void {
const allChecked = this.displayData.every(value => value.checked === true);
const allUnChecked = this.displayData.every(value => !value.checked);
this.allChecked = allChecked;
this.indeterminate = (!allChecked) && (!allUnChecked);
this.disabledButton = !this.userList.some(value => value.checked);
this.checkedNumber = this.userList.filter(value => value.checked).length;
}
ngOnInit() {
}
init(){
this.selectList = [];
this.allChecked = false;
this.checkedNumber = 0;
this.disabledButton = true;
this.indeterminate = false;
}
showModal(title) {
this.getUser();
this.getGroup();
this.isVisible = true;
this.title = title;
}
getUser() {
const data = {
'name': '',
'orgId': '',
'pageNumber': '1',
'pageSize': '10'
};
this.systemSer.user(data).subscribe(
(res) => {
this.userList = res.data;
}
);
}
//组织信息
getGroup() {
this.systemSer.organization().subscribe(
(res) => {
this.groupList = res.data;
this.groupList.forEach(
res => {
res.title = res.name;
res.key = res.id;
}
);
this.nodeTree();
}
);
}
nodeTree() {
const tree = this.commonSer.listToTree('id', 'parentId', this.groupList,);
const list = tree.map(res => {
return new NzTreeNode(res);
});
this.nodes = list;
}
handleEditCancel(){
this.isVisible = false;
this.init();
}
handEditleOk(){
this.done.emit(this.selectList);
this.isVisible = false;
this.init();
}