var lianyungang_Station = new Array;
var yancheng_Station = new Array;
var nantong_Station = new Array;
var r1 = new Array();
var r2 = new Array();
var r3 = new Array();
var rank = new Array();
/**
 * 点击查询
 */
function queryTypeClick() {
    //每次点击前清空表格数据
    $(".table-tbody").empty('');
    var t = getTimeByMonth($("#start-time").val());
    var start_date = getMomentTimeFormat(t.starttime);
    var end_date = getMomentTimeFormat(t.endtime);
   
    var param = {
        "dept_id": $("#fsList").val(),
        "start_date": start_date,
        "end_date": end_date,
    }
    var url = "f/statistics/operation/manage/integration";
    var strTbody = '';
    post_common_service(url, param, function(data) {
        // 运营管理综合检查情况
        check_operation_avg(data);
    }, function(error) {
        return "";
    });
}

/**
 * 表格初始化
 */
function initQueryType() {
    var t = getTimeByMonth($("#start-time").val());
    var start_date = getMomentTimeFormat(t.starttime);
    var end_date = getMomentTimeFormat(t.endtime);
    var param = {
        "start_date": start_date,
        "end_date": end_date,
    }
    var url = "f/statistics/operation/manage/integration";
    var strTbody = '';

    post_common_service(url, param, function(data) {
        // 运营管理综合检查情况
        check_operation_avg(data);
    }, function(error) {
        return "";
    });

}

/**
 * 表格拼接及数据传入
 * @param {*} data
 * @param {*} i
 * @param {*} avg
 */
function gethtml(data, i, avg, lists) {
    var strTbody = "";

    strTbody += "<tr><td width='8%'>" + data.company_ranking2 + "</td>";
    strTbody += "<td width='8%'>" + data.name + "</td><td width='6%'>" + data.company_check_num +
        "</td><td width='6%'>" + data.company_total_score + "</td><td width='6%'>" + data.third_check_num +
        "</td><td width='6%'>" + data.third_total_score + "</td><td width='6%'>" + data.onsite_check_num +
        "</td><td width='6%'>" + data.onsite_total_score + "</td><td width='8%'>" +
        data.check_total_avg + "</td>" +
        "<td width='8%'>" + data.score_avg + "</td>";
    strTbody += "</tr>";
    return strTbody;
}

function getTotalHtml(data) {
    var html = "<tr><td>合计</td><td></td><td>" + data.totalCompanyNum + "</td><td>" + data.totalCompanyScore + "</td><td>" +
        data.totalThirdNum + "</td><td>" + data.totalThirdScore + "</td><td>" + data.totalOnsiteNum + "</td><td>" + data.totalOnsiteScore +
         "</td><td>-</td><td>-</td></tr>";
    return html;
}

/**
 * 管道中心受检人平均每人次扣分
 * @param {*} data
 */
function check_operation_avg(data) {
    var list = data.list;
    var dataArray = new Array();
    var sum = 0;
    var sum1 = 0;
    for (k = 0; k < list.length; k++) {
        sum = parseFloat(sum) + parseFloat(list[k].check_total_avg);
        sum1++;
        if (k == 6) {
            dataArray.push(filterJudge(sum, sum1));
            sum = 0;
            sum1 = 0;
        }
        if (k == 12) {
            dataArray.push(filterJudge(sum, sum1));
            sum = 0;
            sum1 = 0;
        }
        if (k == 20) {
            dataArray.push(filterJudge(sum, sum1));
            sum = 0;
            sum1 = 0;
        }
    }

    for (i = 0; i < list.length; i++) {
        $(".table-tbody").append(gethtml(list[i], i, dataArray[0], dataArray));
    }
    $(".table-tbody").append(getTotalHtml(data));
}

/**
 * 过滤undefined
 * @param {*} value
 * @param {*} default_display_value
 */
function filter(value, default_display_value) {
    if (value != '' && value != undefined) {
        return value;
    } else if (default_display_value != undefined) {
        return default_display_value;
    } else {
        return "";
    }
}

/**
 * 过滤除数为0和保留二位小数时出现的0.00
 * @param {*} value
 * @param {*} default_display_value
 */
function filterByZeroHandle(value, default_display_value) {
    if (isNaN(value)) {
        return default_display_value;
    } else {
        if ((value + '').endsWith('.00')) {
            return value.substring(0, value.length - 3);
        }
        return value;
    }
}

function filterJudge(num1, num2) {
    if (num2 == 0) {
        return 0;
    } else {
        return (num1 / num2).toFixed(2);
    }
}

function exportExcel() {
    var t = getTimeByMonth($("#start-time").val());
    var start_date = getMomentTimeFormat(t.starttime);
    var end_date = getMomentTimeFormat(t.endtime);
    window.open(getExcelServeraddr() + "f/file/operation/manage/integration?start_date=" + start_date + "&end_date=" + end_date);
}