var picHeight;
$("#startTime").val(parent.$("start").val());
$("#endTime").val(parent.$("end").val());
$("#interval").val("月份");
var reachMark = parent.$("#reachMark").val();
$(function () {
    picHeight = ($(window).height() - 88);
    refresh();
});



//点击确定，去后台请求参数
$("#query").click(function () {
    refresh();
});

//获取表格数据
function refresh() {
    var startTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    var lineId = parent.$("#lineIndex").val();
    var i;
    $.ajax({
        type: "POST",
        url: "/pqs9900/inStrategy/getDataIntegralityStatis",
        dataType: "json",
        data: {
            startTime: startTime,
            endTime: endTime,
            lineId: lineId
        },
        beforeSend: function () {
            i = ityzl_SHOW_LOAD_LAYER();
        },
        success: function (data) {
            if (data.code === 500) {
                layer.msg(data.message, {icon: 2, time: 2000})
                //没有数据
                initTable(null);
            } else {
                initTable(data.body)
            }
            //***********关闭loading
            ityzl_CLOSE_LOAD_LAYER(i);
        }
    });
}

//实例化表格
function initTable(data) {
    console.log(data)
    var $bar = $("#flow_sta");
    $bar.css("height", picHeight);
    $bar.css("width", $(window).width() - 20);
    //绘制柱状图
    var barOption = echarts.init($("#flow_sta")[0]);
    var inte = [];
    var areas = [];
    var intervalNum;
    if (null != data) {
        if (data.length > 20) {
            intervalNum = 2;
        } else {
            intervalNum = 0;
        }
        for (var i = 0; i < data.length; i++) {
            areas[i] = data[i].timeId;
            var dataTemp = 0;
            var singleData = {};
            var item = {};
            if (data[i].reachMark < reachMark) {
                dataTemp = data[i].reachMark;
                singleData.value = dataTemp;
                item.color = yellow;
                singleData.itemStyle = item;
            } else if (data[i].reachMark > reachMark) {
                dataTemp = data[i].reachMark;
                singleData.value = dataTemp;
                item.color = green;
                singleData.itemStyle = item;
            }
            inte[i] = singleData;
        }
    }
    var option = {
        backgroundColor: canvasBG,//背景色
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            },
            formatter: function (params) {
                var color = params[0].color;
                var tips = "";
                tips += params[0].name;
                tips += '<br/>' + '完整性' + ' : ' + params[0].value + '%';
                return tips;
            }
        },
        //控制图标在dataroom中的位置大小
        grid: {
            top: '12%',
            left: '4%',
            right: '10%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: [{
            type: 'category',
            data: areas,
            splitLine: {
                show: false
            },
            name: '时间',
            axisLabel: {
                interval: intervalNum,
                show: true,
                fontSize: 10
            },
            boundaryGap: true

        }],
        yAxis: [{
            type: 'value',
            min: '0',
            nameLocation: 'center',
            nameTextStyle: {
                padding: [3, 7, 19, 1]
            },
            name: '完整性',
            max: 100,
        }],
        series: [{
            name: name,
            type: 'bar',
            barMaxWidth: barMax,
            data: inte,
            markLine: {
                itemStyle: {
                    normal: {
                        borderWidth: 1,
                        lineStyle: {
                            type: 'dash',
                            color: orange,
                            width: 2,
                        },
                        label: {
                            formatter: '达标线',
                            textStyle: {
                                fontSize: 16,
                                fontWeight: "bolder",
                            },
                        }
                    },
                },
                data: [
                    {yAxis:reachMark}
                ]
            },
        }]
    };

    barOption.setOption(option);
}

//稳态数据补招
$("#dataSuppleBidd").click(function () {
    var startTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    var lineId = parent.$("#lineIndex").val();
    $.ajax({
        type: "POST",
        url: "/pqs9900/inStrategy/socketonIntegrityData",
        dataType: "json",
        data: {
            type:101,
            startTime:startTime,
            endTime:endTime,
            LineId: lineId
        },
        beforeSend: function () {
            ia = ityzl_SHOW_LOAD_LAYER();
        },
        success: function (data) {
            if (data.code == 200) {

                layer.msg(data.message+",请大约一天后刷新确认",{
                    icon: 1,
                    time: 3000
                })

            } else {
                layer.msg(data.message, {
                    icon: 5,
                    time: 3000
                });
            }
            //***********关闭loading
            ityzl_CLOSE_LOAD_LAYER(ia);
        }
    })
});

