function destributeRole(index) {
    //先进行密码确认
    var username = $("#username").val();
    confirmIndentity(username, function () {
        $("#findex").val(index);
        var roleIndex = index;
        layer.open({
            type: 2,
            title: '角色分配',
            content: '角色分配',
            shade: 0.3,
            area: ['280px', '400px'],
            maxmin: false,
            content: 'destributerole', //iframe的url
            scrollbar: false,
            end: function () {
                layer.close();
            }
        });
    })
}

$('#rolelist').click(function () {
    layer.open({
        type: 2,
        title: '角色列表',
        maxmin: false,
        resize: false,
        shadeClose: true, //点击遮罩关闭层
        area: ['100%', '100%'],
        content: 'rolelist',
        scrollbar: false
    });
});
$(document).ready(function () {
    refresh();
});

function refresh() {
    $.ajax({
        type: "POST",
        url: "/pqs9900/role/getUserRole",
        dataType: "text",
        success: function (data) {
            //没有权限的请求
            if (data == 300) {
                location.href = '/pqs9900/auth/unauthorized';
                //没有登陆的请求
            } else if (data == 301) {
                location.href = '/pqs9900';
            } else {
                var info = $.parseJSON(data);
                if (info.code == 500) {
                    $('#example').DataTable({
                        columnDefs: [{
                            orderable: false,
                            targets: 3
                        }],
                        data: [],
                        destroy: true,
                        lengthMenu: [200],
                        language: {
                            url: '/pqs9900/json/chine.json'
                        }
                    });
                } else {
                    var dataTable = $('#example').DataTable({
                        columnDefs: [{
                            orderable: false,
                            targets: 3
                        }],
                        data: info.body,
                        destroy: true,
                        lengthMenu: [200],
                        language: {
                            url: '/pqs9900/json/chine.json'
                        },
                        'fnDrawCallback': function (oTable) {
                            $("#example_paginate").append("<div style='float:right;padding-top:4px;padding-left:10px'>到第 <input type='text' id='changePage' class='input-text' style='width:50px;height:28px;'> 页  <button class='btn btn-primary' id='dataTable-btn'>确定</button></div>");
                            var table = $("#example").dataTable();
                            $('#dataTable-btn').click(function (e) {
                                if ($("#changePage").val() && $("#changePage").val() > 0) {
                                    var redirectpage = $("#changePage").val() - 1;
                                } else {
                                    var redirectpage = 0;
                                }
                                table.fnPageChange(redirectpage);
                            });
                        }
                    });
                    new $.fn.dataTable.Buttons(dataTable, {
                        buttons: [
                            {
                                extend: 'csv',//导出格式
                                title: '角色分配列表',//导出csv名称
                                exportOptions: {
                                    columns: [0, 1, 2],//导出需要的列
                                    format: {
                                        body: function (data) {//对导出内容的筛选 data 表格内容 rid 行索引 cid 列索引
                                            return data;
                                        }
                                    }
                                }
                            }
                        ]
                    });
                    modifyCss(dataTable);
                }
            }
        }
    });
}

function modifyCss(dataTable) {
    dataTable.buttons().container().css("display", "inline-block");
    dataTable.buttons().container().css("float", "right");
    dataTable.buttons().container().css("top", "4px");
    dataTable.buttons().container().find("a").prepend("<i class='glyphicon glyphicon-share'></i>");
    dataTable.buttons().container().appendTo('.header');
    dataTable.buttons().container().after($("#fliteData")[0]);
}