var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
$("#cancleAdd").click(function () {
    parent.layer.close(index);
});
$("#addRole").click(function () {
    var roleName = $("#roleName").val();
    roleName = roleName.replace(/(^\s*)|(\s*$)/g, '');
    var re = roleNameRex;
    if (!re.test(roleName)) {
        layer.tips('角色名由字母、数字组成，且开头不可为数字', '#roleName', {
            tips: [1, 'red'] //还可配置颜色
        });
        $("#roleName").val("");
    } else {
        var roleD = $("#roleDescription").val();
        roleD = roleD.replace(/(^\s*)|(\s*$)/g, '');
        roleD = filterXSS(roleD);
        roleName = filterXSS(roleName);
        $.ajax({
            url: '/pqs9900/role/addRole',
            type: 'POST',
            dataType: "text",
            data: {
                roleName: roleName,
                roleD: roleD
            },
            success: function (data) {
                var info = $.parseJSON(data);
                if (info.code !== 200) {
                    layer.msg(info.message, {icon: 5});
                } else {
                    layer.msg(info.message, {
                        icon: 6,
                        time: 1000
                    }, function () {
                        parent.refresh();
                        parent.layer.close(index);
                    });
                }
            }
        });
    }
});