import {Component, OnInit, ViewChild} from '@angular/core';
import {SystemService} from '../system.service';
import {RoleComponent} from '../modal/role/role.component';
import {NzModalService} from 'ng-zorro-antd';

@Component({
    selector: 'jhi-power',
    templateUrl: './power.component.html',
    styles: []
})
export class PowerComponent implements OnInit {
    @ViewChild('smartRole') smartRole: RoleComponent;
    dataSet: any[];
    isVisible = false;

    constructor(private systemSer: SystemService,
                private modalSer:NzModalService) {
    }

    ngOnInit() {
        this.dataSet = [
            {
                key1: '角色名称',
                key2: '说明',
                key3: '权限模块',
                key4: '资源权限',
                key5: '有效'
            },
            {
                key1: '角色名称',
                key2: '说明',
                key3: '权限模块',
                key4: '资源权限',
                key5: '有效'
            },
            {
                key1: '角色名称',
                key2: '说明',
                key3: '权限模块',
                key4: '资源权限',
                key5: '有效'
            },
            {
                key1: '角色名称',
                key2: '说明',
                key3: '权限模块',
                key4: '资源权限',
                key5: '有效'
            },
            {
                key1: '角色名称',
                key2: '说明',
                key3: '权限模块',
                key4: '资源权限',
                key5: '有效'
            },
            {
                key1: '角色名称',
                key2: '说明',
                key3: '权限模块',
                key4: '资源权限',
                key5: '有效'
            },
        ];
        this.getRole();
    }

    getRole() {
        this.systemSer.role().subscribe(
            (res) => {
                this.dataSet = res.data;
            }
        );
    }

    //新增角色
    showAddRoleModal() {
        this.smartRole.showModal();
    }

    //删除角色
    deleteRole(data) {
        this.modalSer.confirm({
            nzTitle:'删除',
            nzContent:'<b style="color: red">确定删除该角色</b>',
            nzOkText:'确定',
            nzOkType:'danger',
            nzOnOk:()=>{
                this.systemSer.deleteRole(data.id).subscribe(
                    (res) => {
                    }
                );
            },
            nzCancelText:'取消',
            nzOnCancel:()=>{}
        })

    }

    getCaptcha(e: MouseEvent): void {
        e.preventDefault();
    }

    hello() {
    }

}
