/**
 * 系统配置
 */
var dataTable = null;
var i;
var sysSetIndex;
function load(){
    $.ajax({
        type: "POST",
        url: "/pqs9900/sysset/selectSys",
        beforeSend: function () {
            i = ityzl_SHOW_LOAD_LAYER();
        },
        success: function (data) {
            if(data.body==null){
                sysSetIndex=0;
                document.getElementById('updateSys').style.display='none';
                document.getElementById('addSys').style.display='block';
            }else{
                sysSetIndex=data.body[0][0];
                document.getElementById('updateSys').style.display='block';
                document.getElementById('addSys').style.display='none';
            }
            var height = $(window).height() - 155;
            var length = Math.floor(height / 28);
            if (length < 1) {
                length = 1;
            }
            // var heightTemp = screen.height;
            // var length;
            // if (heightTemp === 768) {
            //     length = 10;
            // } else if (heightTemp === 1024) {
            //     length = 20;
            // } else if (heightTemp === 960) {
            //     length = 15;
            // } else if (heightTemp === 1050) {
            //     length = 18;
            // } else {
            //     length = 15;
            // }
            dataTable = $("#sysId").DataTable();
            dataTable.clear().draw();
            dataTable = $('#sysId').DataTable({
                order:[],
                columnDefs : [
                    {
                        orderable : false,
                        visible:false,
                        targets : [0]
                    }
                ],
                info:false,
                paging:false,
                data: data.body,
                destroy: true,
                searching: true,
                dom: 'rtip',
                pageLength: length,
                language: {
                    url: '/pqs9900/json/chine.json',
                    "sEmptyTable": "没有内容"
                }
            });
            new $.fn.dataTable.Buttons(dataTable, {
                buttons: [
                    {
                        extend: 'csv',//导出格式
                        title: '基础信息列表',//导出csv名称
                        exportOptions: {
                            columns: [0, 1, 2, 3, 4, 5],//导出需要的列
                            format: {
                                body: function (data) {//对导出内容的筛选 data 表格内容 rid 行索引 cid 列索引
                                    return data;
                                }
                            }
                        }
                    }
                ]
            });
            modifyCss(dataTable);
            //***********关闭loading
            ityzl_CLOSE_LOAD_LAYER(i);
        }
    });
}
$(document).ready(function() {
    load();
    $("#addSys").click(function() {
        var username = $("#username").val();
        confirmIndentity(username, function () {
            $("#sysSetIndex").val(sysSetIndex);
            layer.open({
                type: 2,
                title: '新增配置',
                shadeClose: true,
                resize: false,
                shade: 0.3,
                area: ['30%', '100%'],
                content: 'addSys', //iframe的url
                scrollbar: false,
                end: function () {
                    layer.close();
                }
            });
        })
    })
    $("#updateSys").click(function() {
        var username = $("#username").val();
        confirmIndentity(username, function () {
            $("#sysSetIndex").val(sysSetIndex);
            layer.open({
                type: 2,
                title: '修改配置',
                shadeClose: true,
                resize: false,
                shade: 0.3,
                area: ['30%', '100%'],
                content: 'updateSys', //iframe的url
                scrollbar: false,
                end: function () {
                    layer.close();
                }
            });
        })
    })
});

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