var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
$(document).ready(function () {
    var parentId = parent.$("#findex").val();
    $.ajax({
        type: "POST",
        url: "/pqs9900/role/backRole",
        data: {
            roleGPIndex: parentId
        },
        success: function (data) {
            if (data.code === 500) {
                $("#loadCheck").empty();
                $("#loadCheck").append("暂无角色");
            } else {
                $("#loadCheck").empty();
                for (var i = 0; i < data.body.length; i++) {
                    if (data.body[i].checkbox == "true") {
                        $("#loadCheck").append("<label class='am-checkbox'> <input type='checkbox' checked='checked' value=" + data.body[i].index + " data-am-ucheck checked> " + data.body[i].name + "</label>");
                    } else {
                        $("#loadCheck").append("<label class='am-checkbox'> <input type='checkbox'  value=" + data.body[i].index + " data-am-ucheck > " + data.body[i].name + "</label>");
                    }
                }
            }
        }
    });
});
$("#cancleD").click(function () {
    parent.layer.close(index);
});
//根据用户的选择去分配角色
$("#disRole").click(function () {
    var roleIndex = "";
    var roleGPIndex = parent.$("#findex").val();
    $(":checkbox").each(function () {
        var check = $(this).prop("checked");
        if (check) {
            roleIndex = roleIndex + $(this).val() + ",";
        }
    });
    if (roleIndex == "") {
        layer.msg('请至少选中一个角色', {icon: 5});
    } else {
        $.ajax({
            type: "POST",
            url: "/pqs9900/role/disRole",
            data: {
                roleIndex: roleIndex,
                roleGPIndex: roleGPIndex
            },
            success: function (data) {
                if (data.code !== 200) {
                    layer.msg(data.message, {icon: 5});
                } else {
                    layer.msg(data.message, {
                        icon: 6,
                        time: 1000
                    }, function () {
                        parent.refresh();
                        parent.layer.close(index);
                    });
                }
            }
        });
    }
});