Newer
Older
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {SystemService} from '../../system/system.service';
selector: 'smart-select-role',
templateUrl: './select-role.component.html',
styles: []
dataSet: any = [];
title;
selectList = [];
isVisible = false;
allChecked = false;
checkedNumber = 0;
disabledButton = true;
indeterminate = false;
displayData: Array<{ key1: string; key2: number; key3: string; key4: string; checked: boolean }> = [];
constructor(private systemSer: SystemService) {
}
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(event,item){
if(event){
this.selectList.push(item);
}else{
this.selectList.forEach((value,index)=>{
if(value.id == item.id){
this.selectList.splice(index,1)
}
})
}
this.refreshStatus()
}
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
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.dataSet.some(value => value.checked);
this.checkedNumber = this.dataSet.filter(value => value.checked).length;
}
ngOnInit() {
}
showModal(title) {
this.title = title;
this.isVisible = true;
this.getRole();
}
getRole() {
this.systemSer.role().subscribe(
(res) => {
this.dataSet = res.data;
}
);
}
handleEditCancel(){
this.isVisible = false;
}
handEditleOk(){
console.log(this.selectList);
this.done.emit(this.selectList);
this.isVisible = false;
}