 var roletemp=null;
function loadRoleData(role) {
    $("#role_name").val("");
    $("#role_des").val("");
    $("#role_level").val("");

    if(role!=null && edittype=="edit"){
       $('#addRoleModal .modal-title').html('修改角色');
         $("#role_name").val(role.name);
        $("#role_des").val(role.des);
        $("#role_level").val(role.level);
        roletemp = role;
    }else{
        $('#addRoleModal .modal-title').html('添加角色');
    }

    $("#role_add_btn").off("click");
    $("#role_add_btn").on("click", function () {
        addrole();
    })


}


function addrole() {

    var role_name = $("#role_name").val();
    var role_des = $("#role_des").val();
    var role_level = $("#role_level").val();
    

    var data = {
        "name": role_name,
        "des": role_des,
        "level":role_level
    }

    if (edittype == "add") {

        RoleAdd(data, function (susd) {
            layer.msg('添加成功！', {
                time: 2000, //20s后自动关闭
            }, function () {
                $('#addRoleModal').modal('hide')
                getrole(pagesize, 1);
            });
        }, function (error) {

        });

    }

    if(edittype=="edit"){

        data.id = roletemp.id;
        RoleUpdate(data,function(params){
            layer.msg('修改成功！', {
                    time: 2000, //20s后自动关闭
                }, function () {
                    getrole(pagesize, 1);
                     $('#addRoleModal').modal('hide')
                });
        },function(error){

        });
    }


}