var role_selectinput;
var permision_id;
var roletemp = null;
function loadPermisionRoleData(nodedata, roleid) {
    var pnode = nodedata;
    permision_id = pnode[0].id
    $("#permission_mod").val("");
    if (roleid != 0) {
        roletemp = RoleMap.get(parseInt(roleid));
        $("#permission_mod").val(roletemp.mod);
    }

    getRole();


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

        addroleper();
    })
}



function getRole() {

    RoleGetALLNoData(function (data) {

        roles = [];
        for (var i = 0; i < data.length; i++) {
            var m = data[i];
            var zdataItem = {};
            zdataItem["id"] = m.id;
            zdataItem["name"] = m.des;
            roles.push(zdataItem);
        }
        var enabbleedit = true;
        if (edittype == "edit") {
            enabbleedit = false;
        }


        role_selectinput = new TreeSelect({
            element: '#role_select',
            data: roles,
            valueKey: "id",
            placeholder: "选择角色",
            enable: enabbleedit,
            selectvalue: roletemp == null ? null : roletemp.id
        });
    }, function (error) {

    });



}

function addroleper() {
    var permision_id1 = permision_id;
    var role_id = role_selectinput.value;
    var mod = $("#permission_mod").val();
    var data = {
        "role_id": role_id,
        "permission_id": permision_id1,
        "permission_type": mod
    }
    if (edittype == "edit") {
        PermisionRoleEDIT(data, function (data) {
            layer.msg('更新成功！', {
                time: 2000, //20s后自动关闭
            }, function () {
                $('#addRoleModal').modal('hide')
                updateRole(permision_id);
            });
        }, function (error) {

        })

    } else {
        PermisionRoleAdd(data, function (data) {
            layer.msg('添加成功！', {
                time: 2000, //20s后自动关闭
            }, function () {
                $('#addRoleModal').modal('hide')
                updateRole(permision_id);
            });
        }, function (error) {

        })
    }


}