import {Component, OnInit, ViewChild} from '@angular/core';
import {SystemService} from '../system.service';
import {RoleComponent} from '../modal/role/role.component';
import {NzMessageService, 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 message:NzMessageService,
                private modalSer:NzModalService) {
    }

    ngOnInit() {
        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) => {
                        if(res.errCode == 10000){
                            this.message.success("删除成功");
                            this.getRole();
                        }else{
                            this.message.error(res.errMsg);
                        }
                    }
                );
            },
            nzCancelText:'取消',
            nzOnCancel:()=>{}
        })

    }

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

    hello() {
    }

}
