layui.extend({
    common: 'js/common',
    region: 'layui/lay/mymodules/region'
}).use(['common', 'jquery', 'layer', 'element', 'laydate', 'form', 'region'], function () {
    var common = layui.common;
    var $ = layui.jquery;
    var layer = layui.layer;
    var element = layui.element;
    var laydate = layui.laydate;
    var form = layui.form;

    laydate.render({
        elem: '#laydate-range-year'
        ,type: 'year'
        ,value: new Date().getFullYear()
    });

    function statisticsAdPushSum() {
        //统计页面头部数据
        common.sendAsyncRequest("/statistics/statisticsAdPush/statisticsAdPushTotalNew", "POST", {}, function (result) {
            var resultMap = result.data;
            if (resultMap) {
                //线上广告数量
                var onlineAdCount = resultMap['onlineAdCount'];
                if (onlineAdCount) {
                    $("#onlineAdCount").text(onlineAdCount);
                }
                //线下广告数量
                var offlineAdCount = resultMap['offlineAdCount'];
                if (offlineAdCount) {
                    $("#offlineAdCount").text(offlineAdCount);
                }
                //视频广告数量
                var videoAdCount = resultMap['videoAdCount'];
                if (videoAdCount) {
                    $("#videoAdCount").text(videoAdCount);
                }
                //图片广告数量
                var pictureAdCount = resultMap['pictureAdCount'];
                if (pictureAdCount) {
                    $("#pictureAdCount").text(pictureAdCount);
                }

                //广告位数量
                var adsenseCount = resultMap['adsenseCount'];
                if (adsenseCount) {
                    $("#adsenseCount").text(adsenseCount);
                }
            }
        });
    }


    //地图
    var myCharts4 = echarts.init(document.getElementById('chinaMap'));

    function adPushMap() {
        var geoCoordMap = {
            "新疆": [84.9023, 41.748],
            "西藏": [88.7695, 31.6846],
            "内蒙古": [117.5977, 44.3408],
            "青海": [96.2402, 35.4199],
            "四川": [102.9199, 30.1904],
            "黑龙江": [128.1445, 48.5156],
            "甘肃": [95.7129, 40.166],
            "云南": [101.8652, 25.1807],
            "广西": [108.2813, 23.6426],
            "湖南": [111.5332, 27.3779],
            "陕西": [109.5996, 35.6396],
            "广东": [113.4668, 22.8076],
            "吉林": [126.4746, 43.5938],
            "河北": [115.4004, 37.9688],
            "湖北": [112.2363, 31.1572],
            "贵州": [106.6113, 26.9385],
            "山东": [118.7402, 36.4307],
            "江西": [116.0156, 27.29],
            "河南": [113.4668, 33.8818],
            "辽宁": [122.3438, 41.0889],
            "山西": [112.4121, 37.6611],
            "安徽": [117.2461, 32.0361],
            "福建": [118.3008, 25.9277],
            "浙江": [120.498, 29.0918],
            "江苏": [120.0586, 32.915],
            "重庆": [107.7539, 30.1904],
            "宁夏": [105.9961, 37.3096],
            "海南": [109.9512, 19.2041],
            "台湾": [121.0254, 23.5986],
            "北京": [116.4551, 40.2539],
            "天津": [117.4219, 39.4189],
            "上海": [121.4648, 31.2891],
            "香港": [114.2578, 22.3242],
            "澳门": [113.5547, 22.1484]
        }
        var data = [];
        var max = 1000000,
            min = 900; // todo
        var maxSize4Pin = 80,
            minSize4Pin = 40;

        var convertData = function (data) {
            var res = [];
            for (var i = 0; i < data.length; i++) {
                var geoCoord = geoCoordMap[data[i].name];
                if (geoCoord && data[i].value > 0) {
                    res.push({
                        name: data[i].name,
                        value: geoCoord.concat(data[i].value)
                    });
                }
            }
            return res;
        };

        var option4 = {
            // title: {
            //     text: '广告分布区域',
            //     // subtext: '销售面积区间',
            //     x: 'center',
            //     y:'10',
            //     textStyle: {
            //         color: 'rgb(44, 169, 225)',
            //         fontSize: 14
            //     }
            // },
            // grid: {
            //     left: '0',
            //     right: '0',
            //     top:'0',
            //     bottom:'0',
            //     containLabel: true
            // },
            legend: {
                orient: 'vertical',
                left: 'left',

            },
            tooltip: {
                trigger: 'item',
                formatter: function (params) {
                    if (typeof (params.value)[2] == "undefined") {
                        if (params.value) {
                            return params.name + ' : ' + params.value;
                        } else {
                            return '';
                        }

                    } else {
                        return params.name + ' : ' + params.value[2];
                    }
                }
            },
            legend: {
                orient: 'vertical',
                y: 'bottom',
                x: 'right',
                data: ['sell_area'],
                textStyle: {
                    color: '#fff'
                }
            },
            visualMap: {
                show: false,
                min: 0,
                max: 500,
                left: 'left',
                top: 'bottom',
                text: ['高', '低'], // 文本，默认为数值文本
                calculable: true,
                seriesIndex: [1],
                inRange: {
                    // color: ['#3B5077', '#031525'] // 蓝黑
                    // color: ['#ffc0cb', '#800080'] // 红紫
                    // color: ['#3C3B3F', '#605C3C'] // 黑绿
                    color: '#197ec4' // 黑紫黑
                    // color: ['#23074d', '#cc5333'] // 紫红
                    // color: ['#00467F', '#A5CC82'] // 蓝绿
                    // color: ['#1488CC', '#2B32B2'] // 浅蓝
                    // color: ['#00467F', '#A5CC82'] // 蓝绿
                    // color: ['#00467F', '#A5CC82'] // 蓝绿
                    // color: ['#00467F', '#A5CC82'] // 蓝绿
                    // color: ['#00467F', '#A5CC82'] // 蓝绿
                }
            },
            geo: {
                show: true,
                map: 'china',
                label: {
                    normal: {
                        show: false
                    },
                    emphasis: {
                        show: false,
                    }
                },
                roam: true,
                itemStyle: {
                    normal: {
                        areaColor: '#a9cef0',
                        borderColor: '#3B5077',
                        borderWidth: 1,
                        borderColor: '#051940',
                    },
                    emphasis: {
                        areaColor: '#197ec4',
                    }
                }
            },
            series: [{
                name: 'credit_pm2.5',
                type: 'scatter',
                coordinateSystem: 'geo',
                data: convertData(data),
                symbolSize: function (val) {
                    return val[2] / 10000;
                },
                label: {
                    normal: {
                        formatter: '{b}',
                        position: 'right',
                        show: true
                    },
                    emphasis: {
                        show: true
                    },

                },
                itemStyle: {
                    normal: {
                        color: '#fff'
                    }
                }
            },
                {
                    type: 'map',
                    map: 'zhongguo',
                    geoIndex: 0,
                    aspectScale: 1, //长宽比
                    showLegendSymbol: false, // 存在legend时显示
                    label: {
                        normal: {
                            show: false
                        },
                        emphasis: {
                            show: false,
                            textStyle: {
                                color: '#fff'
                            }
                        }
                    },
                    roam: true,
                    itemStyle: {
                        normal: {
                            areaColor: '#031525',
                            borderColor: '#3B5077',
                        },
                        emphasis: {
                            areaColor: '#2B91B7'
                        }
                    },
                    animation: false,
                    data: data
                },
                {
                    name: '点',
                    type: 'scatter',
                    coordinateSystem: 'geo',
                    symbol: 'pin',
                    symbolSize: function (val) {
                        return 40;
                    },
                    label: {
                        normal: {
                            formatter: '{@[2]}',
                            show: true,
                            textStyle: {
                                color: '#fff',
                                fontSize: 9,
                            }
                        }
                    },
                    itemStyle: {
                        normal: {
                            color: '#F62157', //标志颜色
                        }
                    },
                    zlevel: 6,
                    data: convertData(data),
                },
                {
                    name: 'Top 5',
                    type: 'effectScatter',
                    coordinateSystem: 'geo',
                    data: convertData(data.sort(function (a, b) {
                        return b.value - a.value;
                    }).slice(0, 1)),
                    symbolSize: function (val) {
                        return 15;
                    },
                    showEffectOn: 'render',
                    rippleEffect: {
                        brushType: 'stroke'
                    },
                    hoverAnimation: true,
                    label: {
                        normal: {
                            formatter: '{b}',
                            position: 'right',
                            show: false,

                        }
                    },
                    itemStyle: {
                        normal: {
                            color: '#F62157',
                            shadowBlur: 10,
                            shadowColor: '#F62157'
                        }
                    },
                    zlevel: 1
                },

            ]
        };
        var regionProvinceTemp = "";
        myCharts4.setOption(option4);
        //获取省份投放量
        $.ajax({
            url: '/statistics/data/cockpit/statisticsAdPushAndExposureByArea',
            type: 'POST',
            success: function (result) {
                var dataResult = result.data;
                if (result.code == "200" && dataResult) {
                    for (var i in dataResult) {
                        var watchData = dataResult[i];
                        var area = watchData.area;
                        var adExposureCount = watchData.adExposureCount;
                        data[i] = {'name': area, 'value': adExposureCount, 'regionProvince': watchData.regionProvince};
                    }
                    myCharts4.setOption({
                        title: {
                            text: '广告分布区域',
                            // subtext: '销售面积区间',
                            x: 'center',
                            y: '10',
                            textStyle: {
                                color: 'rgb(44, 169, 225)',
                                fontSize: 14
                            }
                        },

                        series: [{
                            name: 'credit_pm2.5',
                            type: 'scatter',
                            coordinateSystem: 'geo',
                            data: convertData(data),
                            symbolSize: function (val) {
                                return val[2] / 10000;
                            },
                            label: {
                                normal: {
                                    formatter: '{b}',
                                    position: 'right',
                                    show: true
                                },
                                emphasis: {
                                    show: true
                                },

                            },
                            itemStyle: {
                                normal: {
                                    color: '#fff'
                                }
                            }
                        },
                            {
                                type: 'map',
                                map: 'zhongguo',
                                geoIndex: 0,
                                aspectScale: 1, //长宽比
                                showLegendSymbol: false, // 存在legend时显示
                                label: {
                                    normal: {
                                        show: false
                                    },
                                    emphasis: {
                                        show: false,
                                        textStyle: {
                                            color: '#fff'
                                        }
                                    }
                                },
                                roam: true,
                                itemStyle: {
                                    normal: {
                                        areaColor: '#031525',
                                        borderColor: '#3B5077',
                                    },
                                    emphasis: {
                                        areaColor: '#2B91B7'
                                    }
                                },
                                animation: false,
                                data: data
                            },
                            {
                                name: '点',
                                type: 'scatter',
                                coordinateSystem: 'geo',
                                symbol: 'pin',
                                symbolSize: function (val) {
                                    return 40;
                                },
                                label: {
                                    normal: {
                                        formatter: '{@[2]}',
                                        show: true,
                                        textStyle: {
                                            color: '#fff',
                                            fontSize: 9,
                                        }
                                    }
                                },
                                itemStyle: {
                                    normal: {
                                        color: '#F62157', //标志颜色
                                    }
                                },
                                zlevel: 6,
                                data: convertData(data),
                            },
                            {
                                name: 'Top 5',
                                type: 'effectScatter',
                                coordinateSystem: 'geo',
                                data: convertData(data.sort(function (a, b) {
                                    return b.value - a.value;
                                }).slice(0, 1)),
                                symbolSize: function (val) {
                                    return 15;
                                },
                                showEffectOn: 'render',
                                rippleEffect: {
                                    brushType: 'stroke'
                                },
                                hoverAnimation: true,
                                label: {
                                    normal: {
                                        formatter: '{b}',
                                        position: 'right',
                                        show: false,

                                    }
                                },
                                itemStyle: {
                                    normal: {
                                        color: '#F62157',
                                        shadowBlur: 10,
                                        shadowColor: '#F62157'
                                    }
                                },
                                zlevel: 1
                            },

                        ]
                    });

                }
            }
        });
        //地图点击事件
        myCharts4.on("click", function (params) {
            if (params.name) {
                if (regionProvinceTemp != params.name) {
                    //获取省份
                    for (var i in data) {
                        var provinceName = data[i].name;
                        if (params.name == provinceName) {
                            regionProvinceTemp = provinceName;
                            $("#province-id").val(data[i].regionProvince);
                        }
                    }
                    statisticsInit();
                }
            } else {
                if (regionProvinceTemp) {
                    regionProvinceTemp = "";
                    $("#province-id").val("");
                    statisticsInit();
                }
            }
        });
    }

    //地图结束

    //饼图开始
    var pie = echarts.init(document.getElementById('pie'));

    function pieInit() {
        var data = [];
        var option = {
            title: {
                text: '同名数量统计',
                //subtext: '纯属虚构',
                left: 'center'
            },
            tooltip: {
                trigger: 'item',
                formatter: '{a} <br/>{b} : {c} ({d}%)'
            },
            legend: {
                type: 'scroll',
                orient: 'vertical',
                right: 10,
                top: 20,
                bottom: 20,
                data: data.legendData,

                selected: data.selected
            },
            series: [
                {
                    name: '姓名',
                    type: 'pie',
                    radius: '55%',
                    center: ['40%', '50%'],
                    data: data.seriesData,
                    emphasis: {
                        itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };

        pie.setOption(option);
        //获取省份投放量
        $.ajax({
            url: '/statistics/data/cockpit/statisticsAdPushAndExposureByArea',
            type: 'POST',
            success: function (result) {
                var dataResult = result.data;
                if (result.code == "200" && dataResult) {
                    for (var i in dataResult) {
                        var watchData = dataResult[i];
                        var area = watchData.area;
                        var adExposureCount = watchData.adExposureCount;
                        data[i] = {'name': area, 'value': adExposureCount, 'regionProvince': watchData.regionProvince};
                    }


                    // 指定图表的配置项和数据

                    option = {
                        title: {
                            text: '广告投放地区分布图',
                            // subtext: '纯属虚构',
                            x: 'center'
                        },
                        tooltip: {
                            trigger: 'item',
                            formatter: "{a} <br/>{b} : {c} ({d}%)"
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'left',
                            data: data
                        },
                        series: [
                            {
                                name: '广告数',
                                type: 'pie',
                                radius: '55%',
                                center: ['50%', '60%'],
                                data: data,
                                itemStyle: {
                                    emphasis: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }
                        ]
                    };
                    // 使用刚指定的配置项和数据显示图表。
                    pie.setOption(option);
                }
            }
        });


    }

    //饼图结束
    // 窗口大小改变事件
    window.addEventListener("resize", function () {
        myCharts4.resize();

    });


    //柱状图开始
    // var bar = echarts.init(document.getElementById('bar'));
    // function barInit() {
    //     var data = [];
    //     var option = {
    //         tooltip: {
    //             trigger: 'axis',
    //             axisPointer: {
    //                 type: 'cross',
    //                 crossStyle: {
    //                     color: '#999'
    //                 }
    //             }
    //         },
    //         grid: {
    //             left: '3%',
    //             right: '4%',
    //             bottom: '3%',
    //             containLabel: true
    //         },
    //         xAxis: {
    //             type: 'category',
    //             data: data
    //         },
    //         yAxis: {
    //             type: 'value'
    //         },
    //
    //         series: [{
    //             name: '线上广告',
    //             type: 'bar',
    //             smooth: true,
    //             barCategoryGap: 25,
    //             lineStyle: {
    //                 normal: {
    //                     width: 3,
    //                     shadowColor: 'rgba(0,0,0,0.4)',
    //                     shadowBlur: 10,
    //                     shadowOffsetY: 10
    //                 }
    //             },
    //             data: data,
    //         },
    //             {
    //                 name: '线下广告',
    //                 type: 'bar',
    //                 smooth: true,
    //                 barCategoryGap: 25,
    //                 lineStyle: {
    //                     normal: {
    //                         width: 3,
    //                         shadowColor: 'rgba(0,0,0,0.4)',
    //                         shadowBlur: 10,
    //                         shadowOffsetY: 10
    //                     }
    //                 },
    //                 data: data,
    //             }]
    //     };
    //
    //     bar.setOption(option);
    //     //获取省份投放量
    //     $.ajax({
    //         url: '/statistics/data/cockpit/statisticsAdPushAndExposureByAreaAndOffline',
    //         type: 'POST',
    //         success: function (result) {
    //             var dataResult = result.data;
    //             var provinceList = ["广东", "广西","新疆","西藏","内蒙古","青海","四川","黑龙江","甘肃","云南","湖南","陕西","吉林","河北","湖北","贵州","山东",
    //                 "江西","辽宁","河南","山西","安徽","福建","浙江", "江苏","重庆","宁夏","海南","台湾","北京","天津","上海","香港","澳门"];
    //             if (result.code == "200" && dataResult) {
    //                 // var data = eval('(' + data + ')');
    //                 // var data1 = new Array();
    //                 var data2 = new Array();
    //                 var data3 = new Array();
    //                 for(var i=0;i<provinceList.length;i++){
    //                     var flag = false;
    //                     for(var j = 0;j<dataResult.length;j++){
    //                         if(provinceList[i] == dataResult[j].area){
    //                             flag = true;
    //                             data2[i] = dataResult[j].adExposureCount;
    //                             data3[i] = dataResult[j].offlineCount;
    //                         }
    //                     }
    //                     if(!flag){
    //                         data2[i] = 0;
    //                         data3[i] = 0;
    //                     }
    //                 }
    //                 // for (var i = 0; i < dataResult.length; i++) {
    //                 //     data1[i] = dataResult[i].area;
    //                 //     data2[i] = dataResult[i].adExposureCount;
    //                 //     debugger;
    //                 //     data3[i] = dataResult[i].offlineCount;
    //                 // }
    //
    //
    //                 // 指定图表的配置项和数据
    //
    //                 option = {
    //                     tooltip: {
    //                         trigger: 'axis',
    //                         axisPointer: {
    //                             type: 'cross',
    //                             crossStyle: {
    //                                 color: '#999'
    //                             }
    //                         }
    //                     },
    //                     grid: {
    //                         left: '3%',
    //                         right: '4%',
    //                         bottom: '3%',
    //                         containLabel: true
    //                     },
    //                     xAxis: {
    //                         type: 'category',
    //                         data: provinceList
    //                     },
    //                     yAxis: {
    //                         type: 'value'
    //                     },
    //                     legend: {
    //                         data: ['线上广告', '线下广告']
    //                     },
    //                     series: [{
    //                         name: '线上广告',
    //                         type: 'bar',
    //                         smooth: true,
    //                         barCategoryGap: 25,
    //                         lineStyle: {
    //                             normal: {
    //                                 width: 3,
    //                                 shadowColor: 'rgba(0,0,0,0.4)',
    //                                 shadowBlur: 10,
    //                                 shadowOffsetY: 10
    //                             }
    //                         },
    //                         data: data2,
    //                     },
    //                         {
    //                             name: '线下广告',
    //                             type: 'bar',
    //                             smooth: true,
    //                             barCategoryGap: 25,
    //                             lineStyle: {
    //                                 normal: {
    //                                     width: 3,
    //                                     shadowColor: 'rgba(102,31,46,0.55)',
    //                                     shadowBlur: 10,
    //                                     shadowOffsetY: 10
    //                                 }
    //                             },
    //                             data: data3,
    //                         }
    //                     ]
    //                 };
    //                 // 使用刚指定的配置项和数据显示图表。
    //                 bar.setOption(option);
    //             }
    //         }
    //     });
    //
    //
    // }
    var myCharts3 = echarts.init(document.getElementById('bar'), myEchartsTheme);
    // var option3 = {
    //     tooltip: {
    //         trigger: "axis",
    //         backgroundColor:'rgba(255,255,255,0.8)',//通过设置rgba调节背景颜色与透明度
    //         color:'black',
    //         borderWidth:'1',
    //         borderColor:'#dadada',
    //         textStyle:{
    //             color:'#575757',
    //             fontSize:'12'
    //         },
    //         extraCssText:'line-height:26px;padding:10px;box-shadow:0 0 10px rgba(0,0,0,0.3)',
    //     },
    //     grid: {
    //         left: '0',
    //         right: '0',
    //         top:"10",
    //         containLabel: true
    //     },
    //     calculable: !0,
    //     legend: {
    //         icon: "rect ",
    //         itemWidth: 15,
    //         itemHeight: 4,
    //         data: ["广告投放", "广告条数"],
    //         x: 'center', // 'center' | 'left' | {number},
    //
    //         y: '90%', // 'center' | 'bottom' | {number}
    //     },
    //     xAxis: [{
    //         type: "category",
    //         axisPointer: {//指示线
    //             snap: true,
    //             lineStyle: {
    //                 show:false,
    //                 color: '#666',
    //                 opacity: 0.6,
    //                 width: .8
    //             },
    //
    //         },
    //         axisTick:{       //y轴刻度线
    //             show:false
    //         },
    //         axisLine: {
    //             lineStyle: {
    //                 color: '#5a5a5a'
    //             }
    //         },
    //         data: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]
    //         //data: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30"]
    //     }],
    //     yAxis: [{
    //         type: "value",
    //         name: "",
    //         splitArea:{show:false},
    //         axisLabel: {
    //             formatter: "{value}"
    //         },
    //         axisLine: {
    //             show: false,
    //             lineStyle: {
    //                 color: '#5a5a5a'
    //             }
    //         },
    //         splitLine :{    //网格线
    //             lineStyle:{
    //                 type:'dashed',    //设置网格线类型 dotted：虚线   solid:实线
    //                 width:'0.8',
    //
    //             },
    //             show:true //隐藏或显示
    //         }
    //     }],
    //     series: [{
    //         name: "广告投放",
    //         type: "line",
    //         //data: [900, 850, 950, 1e3, 1100, 1050, 1e3, 1150, 1250, 1370, 1250, 1100]
    //         data:[],
    //         itemStyle: {
    //             normal: { color: "#1f93ff" },
    //         }
    //
    //     }, {
    //         name: "广告条数",
    //         type: "line",
    //         //data: [870, 850, 850, 950, 1050, 1e3, 980, 1150, 1e3, 1300, 1150, 1e3]
    //         data:[],
    //         itemStyle: {
    //             normal: { color: "#2fc25b" },
    //         }
    //     }]
    // };
    // myCharts3

    var queryChartFu=function(){
        var  xAxisArra= new Array();
        var currentDate=new Date();
        var year=$("#laydate-range-year").val();
        var month=$("#select_month :selected").val();
        if(year==""){
            year=currentDate.getFullYear();
            $("#laydate-range-year").val(year);
        }
        var dateType=0;
        //月份统计
        if(!month){
            month=currentDate.getMonth()+1;
            xAxisArra=["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"];
        }else{
            //天数统计
            dateType=1;
            var day=laydate.getEndDate(month, year);
            xAxisArra== new Array();
            //初始化日期坐标
            for(var i=1;i<=day;i++){
                xAxisArra[i-1]=i+"";
            }
        }
        var adExposureSeries=new Array();
        var adPushSumSeries=new Array();
        // var deviceRegionProvince=$('input[name="regionProvince"]').val();
        // var deviceRegionCity=$('input[name="regionCity"]').val();
        // var deviceRegionArea=$('input[name="regionArea"]').val();
        var param={
            dateType:dateType,
            statisticsDate:year+"-"+month,
            // deviceRegionProvince:deviceRegionProvince,
            // deviceRegionCity:deviceRegionCity,
            // deviceRegionArea:deviceRegionArea,
            // taskType:1
        }
        var layerIndex = layer.load(1);
        //获取统计数据
        common.sendAsyncRequest("/statistics/statisticsAdPush/statisticsAdPushAndExposure","POST",param,function(result){
            layer.close(layerIndex);
            var resultList=result.data;
            //格式化数据成图形需要的
            for(var a=0;a<=xAxisArra.length;a++){
                for(var index in resultList){
                    var map=resultList[index];
                    var adExposureCount=map.adExposureCount;
                    var adPushCount=map.adPushCount;
                    if(dateType==1){
                        var day=map.day;
                        //图形x轴日期
                        var xDay=a+1;
                        if(xDay==day){
                            adExposureSeries[a]=adExposureCount;
                            adPushSumSeries[a]=adPushCount;
                            break;
                        }else{
                            adExposureSeries[a]=0;
                            adPushSumSeries[a]=0;
                        }
                    }else{
                        var month=map.month;
                        //图形x轴日期
                        var xMonth=a+1;
                        if(xMonth==month){
                            adExposureSeries[a]=adExposureCount;
                            adPushSumSeries[a]=adPushCount;
                            break;
                        }else{
                            adExposureSeries[a]=0;
                            adPushSumSeries[a]=0;
                        }
                    }
                }
            }
            //重新加载统计图形
            myCharts3.setOption({
                xAxis: {
                    data:xAxisArra
                },
                series: [{
                    name: "广告投放",
                    type: "line",
                    data: adExposureSeries
                }, {
                    name: "广告条数",
                    type: "line",
                    data: adPushSumSeries
                }]
            });
        });

    }





    //柱状图结束

    var  active = {
        query: function(){
            lineInit();
        },
        reset: function(){
            //清空条件
            var currentDate=new Date();
            $("#laydate-range-year").val(currentDate.getFullYear());
            $("#select_month").val("");
            $('input[name="regionProvince"]').val("");
            $('input[name="regionCity"]').val("");
            $('input[name="regionArea"]').val("");
            $("#region").val("");
            // 刷新select标签
            form.render('select');
            queryChartFu();
        }

    };
    $(document).on('click','.layui-btn', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
        return false;
    });

    //折线图开始
    var line = echarts.init(document.getElementById("line"));
    function lineInit(){
        lineOption = {

            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data: ['线上广告', '线下广告']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    name: '线上广告',
                    type: 'line',
                    stack: 'online',
                    data: []
                },
                {
                    name: '线下广告',
                    type: 'line',
                    stack: 'offline',
                    data: []
                }
            ]
        };
        line.setOption(lineOption);
        var  xAxisArra= new Array();
        var currentDate=new Date();
        var year=$("#laydate-range-year").val();
        var month=$("#select_month :selected").val();
        if(year==""){
            year=currentDate.getFullYear();
            $("#laydate-range-year").val(year);
        }
        var dateType=0;
        var param = {};
        //月份统计
        if(!month){
            param.year = year;
            // month=currentDate.getMonth()+1;
            xAxisArra=['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
        }else{
            //天数统计
            param.year = year;
            param.month = month;
            dateType=1;
            var day=laydate.getEndDate(month, year);
            xAxisArra== new Array();
            //初始化日期坐标
            for(var i=1;i<=day;i++){
                xAxisArra[i-1]=i+"";
            }
        }
        var onlineSeries=new Array();
        var offlineSeries=new Array();
        // var deviceRegionProvince=$('input[name="regionProvince"]').val();
        // var deviceRegionCity=$('input[name="regionCity"]').val();
        // var deviceRegionArea=$('input[name="regionArea"]').val();
        var param={
            year:year,
            statisticsDate:year+"-"+month,
        }
        var layerIndex = layer.load(1);
        //获取统计数据
        common.sendAsyncRequest("/statistics/data/cockpit/statisticsAdCountByDateType","POST",param,function(result){
            layer.close(layerIndex);
            var resultList=result.data;
            //格式化数据成图形需要的
            for(var a=0;a<=xAxisArra.length;a++){
                for(var index in resultList){
                    var map=resultList[index];
                    var onlineCount=map.onlineCount;
                    var offlineCount=map.offlineCount;
                    if(dateType==1){
                        var day=map.day;
                        //图形x轴日期
                        var xDay=a+1;
                        if(xDay==day){
                            offlineSeries[a]=onlineCount;
                            onlineSeries[a]=offlineCount;
                            break;
                        }else{
                            offlineSeries[a]=0;
                            onlineSeries[a]=0;
                        }
                    }else{
                        var month=map.month;
                        //图形x轴日期
                        var xMonth=a+1;
                        if(xMonth==month){
                            offlineSeries[a]=onlineCount;
                            onlineSeries[a]=offlineCount;
                            break;
                        }else{
                            offlineSeries[a]=0;
                            onlineSeries[a]=0;
                        }
                    }
                }
            }
            //重新加载统计图形
            line.setOption({
                xAxis: {
                    data:xAxisArra
                },
                series: [{
                    name: "线上广告",
                    type: "line",
                    data: onlineSeries
                }, {
                    name: "线下",
                    type: "line",
                    data: offlineSeries
                }]
            });
        });

    }


    //折线图结束





    var init = function () {

        queryChartFu();
        // chinaMap(mydata);
        pieInit();
        // barInit();
        lineInit();
        statisticsAdPushSum();
        //广告发布区域
        adPushMap();
        // active.statisticsAdPushSum();
    }
    //初始化数据
    init();


});
