$("#addPloy").click(function () {
    layer.open({
        type: 2,
        title: '新增模板',
        shadeClose: true,
        resize: false,
        shade: 0.3,
        area: ['650px', '500px'],
        maxmin: false,
        content: 'addareaploy',
        scrollbar: false
    });
});

$('#addrpdata').click(function () {
    layer.open({
        type: 2,
        title: '区域字典管理',
        resize: false,
        maxmin: false,
        shadeClose: true, //点击遮罩关闭层
        area: ['100%', '100%'],
        content: 'arearpdata',
        scrollbar: false
    });
});

$(document).ready(function () {
    queryPloy();
});

function queryPloy() {
    jQuery.ajax({
        type: 'POST',
        dataType: "json",
        url: '/pqs9900/report/areaPloy',
        data: {},
        beforeSend: function () {
            i = ityzl_SHOW_LOAD_LAYER();
        },
        async: false,
        success: function (data) {
            var oTable = $('#example').DataTable({
                scrollX: true,
                lengthChange: false,
                bDestroy: true,
                ordering: false,
                columnDefs: [{
                    targets: [],
                    visible: false
                }],
                data: data.body,
                destroy: true,
                lengthMenu: [12],
                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 = $("#vdlist").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(oTable, {
                buttons: [
                    {
                        extend: 'csv',//导出格式
                        title: '区域报告列表',//导出csv名称
                        exportOptions: {
                            columns: [0, 1],//导出需要的列
                            format: {
                                body: function (data) {//对导出内容的筛选 data 表格内容 rid 行索引 cid 列索引
                                    return data;
                                }
                            }
                        }
                    }
                ]
            });
            modifyCss(oTable);
            //***********关闭loading
            ityzl_CLOSE_LOAD_LAYER(i);
        }
    })
}

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]);
}

function updateRpPloy(index) {
    layer.open({
        type: 2,
        title: '修改模板信息',
        shadeClose: true,
        resize: false,
        area: ['650px', '500px'],
        offset: '0px',
        maxmin: false,
        content: 'modarearpploy?rpIndex=' + index,
        scrollbar: false
    });
}

function deleteRpPloy(index) {
    layer.confirm('是否确认？', function () {
        $.ajax({
            method: "post",
            url: "/pqs9900/report/delRdPloy",
            data: {
                rpIndex: index
            },
            async: false,
            success: function (data) {
                if (data.code == 200) {
                    layer.msg('删除成功!', {icon: 1, time: 1000});
                    var tmp = 0;
                    queryPloy(tmp);
                } else {
                    layer.msg('删除失败！', {icon: 2, time: 1000});
                }
            }
        })
    })
}