/**
 * 下载资源
 */
var allData,getSubData,getReportData;
$(document).ready(function() {
    $.ajax({
        method: "post",
        async: false,
        url: "/pqs9000/manage/getBasemang",
        data: "",
        success: function (data) {
            if(data.code===500){
                allData=null;
            }else{
                allData=data.body;
            }

        }
    })
    $.ajax({
        method: "post",
        async: false,
        url: "/pqs9000/manage/getReport",
        data: "",
        success: function (data) {
            if(data.code===500){
                getReportData=null;
            }else{
                getReportData=data.body;
            }

        }
    })
    $.ajax({
        method: "post",
        async: false,
        url: "/pqs9000/manage/getSub",
        data: "",
        success: function (data) {
            if(data.code===500){
                getSubData=null;
            }else{
                getSubData=data.body;
            }
        }
    })
    startQuery();
});
//基本资源
function getBaseMang(baseList){
    if(baseList==null){
        baseList=[];
    }
    $("#areaTable").DataTable({
        data: baseList,
        autoWidth:false,
        order:[1,"desc"],
        columnDefs : [ {
            orderable : false,
            targets : [0]
        } ,
            { "width": "33%", "targets": 0 },
            { "width": "33%", "targets": 1 },
            { "width": "33%", "targets": 2 }
        ],
        paging:true,
        lengthChange: false,
        searching:false,
        destroy : true,
        pageLength:10,
        language : {
            url:'/pqs9000/json/chine.json',
        }
    })
}
//报告发布
function getReport(reportList) {
    if(reportList==null){
        reportList=[];
    }

    $("#subTable").DataTable({
        data: reportList,
        autoWidth:false,
        columnDefs : [
            { "width": "33%", "targets": 0 },
            { "width": "33%", "targets": 1 },
            { "width": "33%", "targets": 2 }
        ],
        order:[1,"desc"],
        paging:true,
        lengthChange: false,
        searching:false,
        destroy : true,
        pageLength:10,
        language : {
            url:'/pqs9000/json/chine.json',
        }
    })
}
//辅助资源
function getSub(subList) {
    if(subList==null){
        subList=[];
    }
    $("#monitorTable").DataTable({
        data: subList,
        autoWidth:false,
        columnDefs : [
            { "width": "33%", "targets": 0 },
            { "width": "33%", "targets": 1 },
            { "width": "33%", "targets": 2 }
        ],
        order:[1,"desc"],
        paging:true,
        lengthChange: false,
        searching:false,
        destroy : true,
        pageLength:10,
        language : {
            url:'/pqs9000/json/chine.json',
        }
    })
}
//特殊处理，表头紧缩问题--start
var it = null;

function startQuery() {
    //实时刷新时间单位为毫秒
    it = setInterval('refreshQuery()', 100);

}

/* 刷新查询 */
function refreshQuery() {
    var width = $("#areaTable").width();
    if (width > 100) {
        getBaseMang(allData);
        getReport(getReportData);
        getSub(getSubData);

        window.clearInterval(it)
    }
}
//特殊处理，表头紧缩问题--end
function sourceManageByIndex(index){
    var res_Index=index;
    $.ajax({
        type:"POST",
        url:"/pqs9000/user/foundChrome",
        data:{
            res_Index:res_Index
        },
        success : function(data) {
            if(data==null){
            }
            //没有权限的请求
            if (data == 300) {
                location.href = '/pqs9000/auth/unauthorized';
                //没有登陆的请求
            } else if (data == 301) {
                location.href = '/pqs9000';
            } else {
                if(data.code==500){
                    layer.msg(data.message, {icon: 5});
                }else{
                    self.location.href="/pqs9000/user/downloadChrome?res_Index="+res_Index;
                }
            }
        }
    });
}
