Skip to content
select-person.component.ts 3.43 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {NzTreeNode} from 'ng-zorro-antd';
import {SystemService} from '../../system/system.service';
wangqinghua's avatar
wangqinghua committed
import {CommonService} from '../../shared/common/common.service';
wangqinghua's avatar
wangqinghua committed

@Component({
wangqinghua's avatar
wangqinghua committed
    selector: 'smart-select-person',
    templateUrl: './select-person.component.html',
    styles: []
wangqinghua's avatar
wangqinghua committed
})
export class SelectPersonComponent implements OnInit {
wangqinghua's avatar
wangqinghua committed
    @Output() done = new EventEmitter();
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
    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 }> = [];
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
    constructor(private systemSer: SystemService, private commonSer: CommonService) {
wangqinghua's avatar
wangqinghua committed
    }

    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() {
wangqinghua's avatar
wangqinghua committed
        const tree = this.commonSer.listToTree('id', 'parentId', this.groupList,);
wangqinghua's avatar
wangqinghua committed
        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();
    }
wangqinghua's avatar
wangqinghua committed

}