
layui.use(['layer', 'element','laydate'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;

    //广告类别观看分布
    var myCharts1 = echarts.init(document.getElementById('ad-classify'), myEchartsTheme);
    function adWatchAdType() {
        var colorList = ['#7c93eb', '#c4a2b9', '#ebd2cc'];
        var option1 = {
            tooltip: {},
            grid: {
                left: '0',
                top: '0',
                right: '0',
                bottom: '20',
                containLabel: true
            },
            series: [{
                type: 'wordCloud',
                gridSize: 12,
                sizeRange: [15, 45],
                rotationRange: [0, 0],
                shape: 'circle',
                textStyle: {
                    normal: {
                        color: function (v) {

                            if (v.value > 2000) {
                                //alert(v.value)
                                return colorList[0];
                            } else if (v.value > 1000) {
                                return colorList[1];
                            } else {
                                return '#278fb7';
                            }
                        },
                    },
                    emphasis: {
                        shadowBlur: 10,
                        shadowColor: '#333'
                    }
                },

                data: []
            }]
        };
        myCharts1.setOption(option1);
        //获取广告类别观看量
        $.ajax({
            url     :   '/statistics/data/cockpit/statisticsAdWatchRankForAdType',
            type:'POST',
            success :   function(result){
                var data=result.data;
                if(result.code=="200"&&data){
                    var dataArray=new Array();
                    for(var i in data){
                        if(i==0){
                            dataArray[i]={'name':data[i].adTypeName,
                                value: data[i].adWatchCount,textStyle: {
                                    normal: {
                                        color: '#be6ce6'
                                    },
                                    emphasis: {
                                        color: '#4995d0'
                                    }
                                }}
                        }else{
                            dataArray[i]={'name':data[i].adTypeName,value: data[i].adWatchCount}
                        }
                    }
                    myCharts1.setOption({
                        series: [{
                            data:dataArray
                        }]
                    });
                }
            }
        });
    }
    //观看量top10排行
    var myCharts2 = echarts.init(document.getElementById('watch-ranking'));
    function adWatchCityRankTopTen() {
        var option2 = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            grid: {
                left: '30',
                top: '0',
                bottom: '-20',
                containLabel: true
            },

            xAxis: {
                type: 'value',
                "show": false,
                axisLine: {
                    show: false,
                    lineStyle: {
                        color: '#d6e0dc'
                    }
                },

                axisTick: {
                    show: false
                },
                splitLine: {
                    show: false,

                },

            },
            yAxis: {
                type: 'category',
                data: [],
                splitLine: {show: false},
                axisLine: {
                    show: false, //隐藏y轴
                    lineStyle: {
                        color: 'rgba(125,132,255,0.15)' //坐标轴的颜色
                    }
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    textStyle: {
                        color: '#d6e0dc',//坐标值的具体的颜色
                    },

                },
                offset: 10,
                nameTextStyle: {
                    fontSize: 15
                }
            },
            series: [
                {
                    name: '数量',
                    type: 'bar',
                    data: [],
                    barWidth: 14,
                    barGap: 10,
                    smooth: true,
                    label: {
                        normal: {
                            show: true,
                            position: 'right', //数值的位置
                            offset: [-20, 0],
                            textStyle: {
                                color: '#d6e0dc',
                                fontSize: 12
                            }
                        }
                    },

                    itemStyle: {

                        normal: {
                            barBorderRadius: [3, 3, 3, 3],
                            color: new echarts.graphic.LinearGradient(
                                0, 0, 1, 0,
                                [
                                    {offset: 0, color: '#1778c3'},
                                    {offset: 1, color: '#2bb3d5'}

                                ]
                            )
                        }
                    }
                }
            ]
        };
        myCharts2.setOption(option2);

        //获取城市观看量
        $.ajax({
            url     :   '/statistics/data/cockpit/statisticsAdWatchRankForArea',
            type:'POST',
            data:'areaType=1',
            success :   function(result){
                var data=result.data;
                if(result.code=="200"&&data){
                    var category2=new Array(data.length);
                    var barData2=new Array(data.length);
                    var z=0;
                    for(var i=(data.length-1);i>=0;i--){
                        var watchData=data[i];
                        var area=watchData.area;
                        category2[z]=area;
                        var adWatchCount=watchData.adWatchCount;
                        barData2[z]=adWatchCount;
                        if(z==(data.length-1)){
                            barData2[z]={value:adWatchCount,
                                itemStyle: {

                                    color: new echarts.graphic.LinearGradient(
                                        0, 0, 1, 0,
                                        [
                                            {offset: 0, color: '#1778c3'},
                                            {offset: 1, color: '#d0826e'}

                                        ]
                                    ),
                                }}
                        }else{
                            barData2[z]=adWatchCount;
                        }
                        z++;
                    }
                    myCharts2.setOption({
                        yAxis: {
                            data: category2
                        },
                        series: [
                            {
                                name: '次数',
                                type: 'bar',
                                data: barData2
                            }]
                    });
                }
            }
        });

    }

    // 广告每日观看趋势
    var myCharts3 = echarts.init(document.getElementById('data-view'), myEchartsTheme);
    function adEverydayWatchTrend() {
        //获取当月天数
        var dayArray=new Array();
        var dataArray1=new Array();
        var dataArray2=new Array();
        var currentDate=new Date();
        var dayCount=layui.laydate.getEndDate(currentDate.getMonth()+1, currentDate.getFullYear());
        for(var i=1;i<=dayCount;i++){
            dayArray[i-1]=i;
            dataArray1[i-1]=0;
            dataArray2[i-1]=0;
        }
        var option3 = {
            tooltip: {
                trigger: 'axis',
            },
            legend: {
                top: '0%',
                data: ['广告观看人数', '设备开门次数'],
                textStyle: {
                    color: '#fff',
                    fontSize: '12',
                }
            },
            grid: {
                left: '10',
                top: '30',
                right: '10',
                bottom: '10',
                containLabel: true
            },

            xAxis: [{
                type: 'category',
                boundaryGap: false,
                axisLabel: {
                    textStyle: {
                        color: '#fff',//坐标值得具体的颜色
                    },

                },
                axisLine: {
                    lineStyle: {
                        color: 'rgba(255,255,255,.2)'
                    }

                },

                data: dayArray

            }, {

                axisPointer: { show: false },
                axisLine: { show: false },
                position: 'bottom',
                offset: 20,
            }],

            yAxis: [{
                type: 'value',
                axisTick: { show: false },
                splitArea: { show: false },
                axisLine: {
                    lineStyle: {
                        color: 'rgba(255,255,255,.1)'
                    }
                },
                axisLabel: {
                    textStyle: {
                        color: "#fff",
                        fontSize: 12,
                    },
                },

                splitLine: {
                    lineStyle: {
                        color: 'rgba(255,255,255,.1)'
                    }
                }
            }],
            series: [
                {
                    name: '广告观看人数',
                    type: 'line',
                    symbol: 'circle',
                    symbolSize: 5,
                    showSymbol: false,
                    lineStyle: {

                        normal: {
                            color: '#2bb2d5',
                            width: 2
                        }
                    },
                    areaStyle: {
                        normal: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: 'rgba(1, 132, 213, 0.4)'
                            }, {
                                offset: 0.8,
                                color: 'rgba(1, 132, 213, 0.1)'
                            }], false),
                            shadowColor: 'rgba(0, 0, 0, 0.1)',
                        }
                    },
                    itemStyle: {
                        normal: {
                            color: '#2bb2d5',
                            borderColor: 'rgba(221, 220, 107, .1)',
                            borderWidth: 12
                        }
                    },
                    data: []

                },
                {
                    name: '设备开门次数',
                    type: 'line',
                    symbol: 'circle',
                    symbolSize: 5,
                    showSymbol: false,
                    lineStyle: {

                        normal: {
                            color: '#c08175',
                            width: 2
                        }
                    },
                    areaStyle: {
                        normal: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: 'rgba(0, 216, 135, 0.4)'
                            }, {
                                offset: 0.8,
                                color: 'rgba(0, 216, 135, 0.1)'
                            }], false),
                            shadowColor: 'rgba(0, 0, 0, 0.1)',
                        }
                    },
                    itemStyle: {
                        normal: {
                            color: '#c08175',
                            borderColor: 'rgba(221, 220, 107, .1)',
                            borderWidth: 12
                        }
                    },
                    data: []

                },

            ]

        };
        myCharts3.setOption(option3);
        $.ajax({
            url     :   '/statistics/data/cockpit/homeAdWatchDay',
            type:'POST',
            success :   function(result){
                var data=result.data;
                if(result.code=="200"&&data){
                    //统计某月每天数据
                    //广告观看人数
                    var adWatchPersonForDay=data.adWatchPersonForDay;
                    if(adWatchPersonForDay){
                        for(var i in dataArray1){
                            var dayChart=Number(i)+1;
                            for( var z in adWatchPersonForDay){
                                var day=adWatchPersonForDay[z].day;
                                var adWatchCount=adWatchPersonForDay[z].adWatchCount;
                                if(day==dayChart){
                                    dataArray1[i]=adWatchCount;
                                }
                            }
                        }
                    }
                    //设备开门次数
                    var accessCountForDay=data.accessCountForDay;
                    if(accessCountForDay){
                        for(var i in dataArray2){
                            var dayChart=Number(i)+1;
                            for( var z in accessCountForDay){
                                var day=accessCountForDay[z].day;
                                var accessCount=accessCountForDay[z].accessCount;
                                if(day==dayChart){
                                    dataArray2[i]=accessCount;
                                }
                            }
                        }
                    }
                        //初始化图形数据
                        myCharts3.setOption({
                            series: [
                                {
                                    name: '广告观看人数',
                                    type: 'line',
                                    symbol: 'circle',
                                    symbolSize: 5,
                                    showSymbol: false,
                                    lineStyle: {

                                        normal: {
                                            color: '#2bb2d5',
                                            width: 2
                                        }
                                    },
                                    areaStyle: {
                                        normal: {
                                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                                offset: 0,
                                                color: 'rgba(1, 132, 213, 0.4)'
                                            }, {
                                                offset: 0.8,
                                                color: 'rgba(1, 132, 213, 0.1)'
                                            }], false),
                                            shadowColor: 'rgba(0, 0, 0, 0.1)',
                                        }
                                    },
                                    itemStyle: {
                                        normal: {
                                            color: '#2bb2d5',
                                            borderColor: 'rgba(221, 220, 107, .1)',
                                            borderWidth: 12
                                        }
                                    },
                                    data: dataArray1

                                },
                                {
                                    name: '设备开门次数',
                                    type: 'line',
                                    symbol: 'circle',
                                    symbolSize: 5,
                                    showSymbol: false,
                                    lineStyle: {

                                        normal: {
                                            color: '#c08175',
                                            width: 2
                                        }
                                    },
                                    areaStyle: {
                                        normal: {
                                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                                offset: 0,
                                                color: 'rgba(0, 216, 135, 0.4)'
                                            }, {
                                                offset: 0.8,
                                                color: 'rgba(0, 216, 135, 0.1)'
                                            }], false),
                                            shadowColor: 'rgba(0, 0, 0, 0.1)',
                                        }
                                    },
                                    itemStyle: {
                                        normal: {
                                            color: '#c08175',
                                            borderColor: 'rgba(221, 220, 107, .1)',
                                            borderWidth: 12
                                        }
                                    },
                                    data: dataArray2

                                },

                            ]
                        });
                }
            }
        });
    }

    //地图
    var myCharts4 = echarts.init(document.getElementById('earth_echar'));
    function deviceMap() {
        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 = 100000,
            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) {
                    res.push({
                        name: data[i].name,
                        value: geoCoord.concat(data[i].value)
                    });
                }
            }
            return res;
        };

        option4 = {
            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,
                max: 500,
                left: 'left',
                top: 'bottom',
                text: ['高', '低'], // 文本，默认为数值文本
                calculable: true,
                seriesIndex: [1],
                inRange: {
                    color: '#197ec4' // 黑紫黑
                }
            },
            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) {
                        var a = (maxSize4Pin - minSize4Pin) / (max - min);
                        var b = minSize4Pin - a * min;
                        b = maxSize4Pin - a * max;
                        return a * val[2] + b;
                    },
                    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, 5)),
                    symbolSize: function (val) {
                        return 10;
                    },
                    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.setOption(option4);

        //加载设备分布区域数据
        $.ajax({
            url     :   '/statistics/data/cockpit/homeDeviceCountDistribution',
            type:'POST',
            success :   function(result){
                var dataResult=result.data;
                if(result.code=="200"&&dataResult){
                    for(var i in dataResult){
                        var watchData=dataResult[i];
                        var regionProvince=watchData.regionProvince;
                        var deviceCount=watchData.deviceCount;
                        data[i]={'name':regionProvince,'value':deviceCount};
                    }
                    myCharts4.setOption({
                        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) {
                                    var a = (maxSize4Pin - minSize4Pin) / (max - min);
                                    var b = minSize4Pin - a * min;
                                    b = maxSize4Pin - a * max;
                                    return a * val[2] + b;
                                },
                                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, 5)),
                                symbolSize: function (val) {
                                    return 10;
                                },
                                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 myCharts5 = echarts.init(document.getElementById('openWay'));
    function openWay(){
        var total = 50;//最大温度数据单独出来定义，方便环形总数的修改
        placeHolderStyle = {
            normal: {
                label: {
                    show: false,
                },
                labelLine: {
                    show: false,
                }
            }
        };
        option5 = {

            color: ['#187cc4', '#5ab1ef', '#c08175','#2ec7c9','#b6a2de'],
            series: [{
                name: '开门方式',
                type: 'pie',
                radius: ['60%', '75%'],
                avoidLabelOverlap: false,
                label: {
                    normal: {
                        show: false,
                        position: 'center',
                        formatter: "{c}\n\n{b}",
                    },
                    emphasis: {
                        show: true,
                        textStyle: {
                            fontSize: '12',
                            color:'#fff',
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                data: [{
                    value: 0,
                    name: '人脸识别'
                }, {
                    value: 0,
                    name: '密码开门'
                }, {
                    value: 0,
                    name: '卡开门'
                }, {
                    value: 0,
                    name: '远程开门'
                }],
                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }]
        };
        var count = 0;
        var timeTicket = null;
        var dataLength = option5.series[0].data.length;
        timeTicket && clearInterval(timeTicket);
        timeTicket = setInterval(function() {
            myCharts5.dispatchAction({
                type: 'downplay',
                seriesIndex: 0,
            });
            myCharts5.dispatchAction({
                type: 'highlight',
                seriesIndex: 0,
                dataIndex: (count) % dataLength
            });
            myCharts5.dispatchAction({
                type: 'showTip',
                seriesIndex: 0,
                dataIndex: (count) % dataLength
            });
            count++;
        }, 3000);

        myCharts5.on('mouseover', function(params) {
            clearInterval(timeTicket);
            myCharts5.dispatchAction({
                type: 'downplay',
                seriesIndex: 0
            });
            myCharts5.dispatchAction({
                type: 'highlight',
                seriesIndex: 0,
                dataIndex: params.dataIndex
            });
            myCharts5.dispatchAction({
                type: 'showTip',
                seriesIndex: 0,
                dataIndex: params.dataIndex,
            });
        });
        myCharts5.on('mouseout', function(params) {
            timeTicket && clearInterval(timeTicket);
            timeTicket = setInterval(function() {
                myCharts5.dispatchAction({
                    type: 'downplay',
                    seriesIndex: 0,
                });
                myCharts5.dispatchAction({
                    type: 'highlight',
                    seriesIndex: 0,
                    dataIndex: (count) % dataLength
                });
                myCharts5.dispatchAction({
                    type: 'showTip',
                    seriesIndex: 0,
                    dataIndex: (count) % dataLength
                });
                count++;
            }, 3000);
        });
        myCharts5.setOption(option5);
        //获取动态数据
        $.ajax({
            url     :   '/statistics/data/cockpit/homeOpenWay',
            type:'POST',
            success :   function(result){
                var data=result.data;
                if(result.code=="200"&&data){
                    myCharts5.setOption({
                        series: [{
                            data: [{
                                value: data.faceOpenCount,
                                name: '人脸识别'
                            }, {
                                value: data.passWordOpenCount,
                                name: '密码开门'
                            }, {
                                value: data.cardOpenCount,
                                name: '卡开门'
                            }, {
                                value: data.telnetOpenCount,
                                name: '远程开门'
                            }]
                        }]
                    });
                }
            }
        });
    }
    var myCharts6 = echarts.init(document.getElementById('authWay'));
    function authWay() {
        var total = 50;//最大温度数据单独出来定义，方便环形总数的修改
        placeHolderStyle = {
            normal: {
                label: {
                    show: false,
                },
                labelLine: {
                    show: false,
                }
            }
        };
        option6 = {
            color: ['#187cc4', '#5ab1ef', '#c08175'],
            series: [{
                name: '住户认证',
                type: 'pie',
                radius: ['60%', '75%'],
                avoidLabelOverlap: false,
                label: {
                    normal: {
                        show: false,
                        position: 'center',
                        formatter: "{c}\n\n{b}"
                    },
                    emphasis: {
                        show: true,
                        textStyle: {
                            fontSize: '12',
                            color:'#fff',
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                data: [{
                    value: 0,
                    name: '认证通过'
                }, {
                    value: 0,
                    name: '认证中'
                }, {
                    value: 0,
                    name: '认证失败'
                }],
                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }]
        };

        var count = 0;
        var timeTicket = null;
        var dataLength = option6.series[0].data.length;
        timeTicket && clearInterval(timeTicket);
        timeTicket = setInterval(function() {
            myCharts6.dispatchAction({
                type: 'downplay',
                seriesIndex: 0,
            });
            myCharts6.dispatchAction({
                type: 'highlight',
                seriesIndex: 0,
                dataIndex: (count) % dataLength
            });
            myCharts6.dispatchAction({
                type: 'showTip',
                seriesIndex: 0,
                dataIndex: (count) % dataLength
            });
            count++;
        }, 3000);

        myCharts6.on('mouseover', function(params) {
            clearInterval(timeTicket);
            myCharts6.dispatchAction({
                type: 'downplay',
                seriesIndex: 0
            });
            myCharts6.dispatchAction({
                type: 'highlight',
                seriesIndex: 0,
                dataIndex: params.dataIndex
            });
            myCharts6.dispatchAction({
                type: 'showTip',
                seriesIndex: 0,
                dataIndex: params.dataIndex,
            });
        });
        myCharts6.on('mouseout', function(params) {
            timeTicket && clearInterval(timeTicket);
            timeTicket = setInterval(function() {
                myCharts6.dispatchAction({
                    type: 'downplay',
                    seriesIndex: 0,
                });
                myCharts6.dispatchAction({
                    type: 'highlight',
                    seriesIndex: 0,
                    dataIndex: (count) % dataLength
                });
                myCharts6.dispatchAction({
                    type: 'showTip',
                    seriesIndex: 0,
                    dataIndex: (count) % dataLength
                });
                count++;
            }, 3000);
        });
        myCharts6.setOption(option6);
        //获取动态数据
        $.ajax({
            url     :   '/statistics/data/cockpit/homeAuthWay',
            type:'POST',
            success :   function(result){
                var data=result.data;
                if(result.code=="200"&&data){
                    myCharts6.setOption({
                        series: [{
                            data: [{
                                value: data.passCheckCount,
                                name: '认证通过'
                            }, {
                                value: data.waitCheckCount,
                                name: '认证中'
                            }, {
                                value: data.noPassCheckCount,
                                name: '认证失败'
                            }]
                        }]
                    });
                }
            }
        });
    }

    var myCharts7 = echarts.init(document.getElementById('userType'));
    function userType() {
        var total = 50;//最大温度数据单独出来定义，方便环形总数的修改
        placeHolderStyle = {
            normal: {
                label: {
                    show: false,
                },
                labelLine: {
                    show: false,
                }
            }
        };
        option7 = {
            color: ['#187cc4', '#5ab1ef', '#c08175',],
            series: [{
                name: '移动端用户',
                type: 'pie',
                radius: ['60%', '75%'],
                avoidLabelOverlap: false,
                label: {
                    normal: {
                        show: false,
                        position: 'center',
                        formatter: "{c}\n\n{b}"
                    },
                    emphasis: {
                        show: true,
                        textStyle: {
                            fontSize: '12',
                            color:'#fff',
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                data: [{
                    value: 0,
                    name: '业主'
                }, {
                    value: 0,
                    name: '家庭成员'
                }, {
                    value: 0,
                    name: '服务人员'
                }],
                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }]
        };

        var count = 0;
        var timeTicket = null;
        var dataLength = option7.series[0].data.length;
        timeTicket && clearInterval(timeTicket);
        timeTicket = setInterval(function() {
            myCharts7.dispatchAction({
                type: 'downplay',
                seriesIndex: 0,
            });
            myCharts7.dispatchAction({
                type: 'highlight',
                seriesIndex: 0,
                dataIndex: (count) % dataLength
            });
            myCharts7.dispatchAction({
                type: 'showTip',
                seriesIndex: 0,
                dataIndex: (count) % dataLength
            });
            count++;
        }, 3000);

        myCharts7.on('mouseover', function(params) {
            clearInterval(timeTicket);
            myCharts7.dispatchAction({
                type: 'downplay',
                seriesIndex: 0
            });
            myCharts7.dispatchAction({
                type: 'highlight',
                seriesIndex: 0,
                dataIndex: params.dataIndex
            });
            myCharts7.dispatchAction({
                type: 'showTip',
                seriesIndex: 0,
                dataIndex: params.dataIndex,
            });
        });
        myCharts7.on('mouseout', function(params) {
            timeTicket && clearInterval(timeTicket);
            timeTicket = setInterval(function() {
                myCharts7.dispatchAction({
                    type: 'downplay',
                    seriesIndex: 0,
                });
                myCharts7.dispatchAction({
                    type: 'highlight',
                    seriesIndex: 0,
                    dataIndex: (count) % dataLength
                });
                myCharts7.dispatchAction({
                    type: 'showTip',
                    seriesIndex: 0,
                    dataIndex: (count) % dataLength
                });
                count++;
            }, 2000);
        });
        myCharts7.setOption(option7);
        //获取动态数据
        $.ajax({
            url     :   '/statistics/data/cockpit/homeUserType',
            type:'POST',
            success :   function(result){
                var data=result.data;
                if(result.code=="200"&&data){
                    myCharts7.setOption({
                        series: [{
                            data: [{
                                value: data.proprietorUserCount,
                                name: '业主'
                            }, {
                                value: data.memberUserCount,
                                name: '家庭成员'
                            }, {
                                value: data.serverUserCount,
                                name: '服务人员'
                            }]
                        }]
                    });
                }
            }
        });
    }


    var myCharts8 = echarts.init(document.getElementById('mobileUser'));
    function mobileUser() {
        var total = 50;//最大温度数据单独出来定义，方便环形总数的修改
        placeHolderStyle = {
            normal: {
                label: {
                    show: false,
                },
                labelLine: {
                    show: false,
                }
            }
        };
        option8 = {
            color: ['#187cc4', '#5ab1ef'],
            series: [{
                name: '移动端用户',
                type: 'pie',
                radius: ['60%', '75%'],
                avoidLabelOverlap: false,
                label: {
                    normal: {
                        show: false,
                        position: 'center',
                        formatter: "{c}\n\n{b}"
                    },
                    emphasis: {
                        show: true,
                        textStyle: {
                            fontSize: '12',
                            color:'#fff',
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                data: [{
                    value: 0,
                    name: '小程序'
                }, {
                    value: 0,
                    name: 'APP'
                }],
                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }]
        };
        var count = 0;
        var timeTicket = null;
        var dataLength = option8.series[0].data.length;
        timeTicket && clearInterval(timeTicket);
        timeTicket = setInterval(function() {
            myCharts8.dispatchAction({
                type: 'downplay',
                seriesIndex: 0,
            });
            myCharts8.dispatchAction({
                type: 'highlight',
                seriesIndex: 0,
                dataIndex: (count) % dataLength
            });
            myCharts8.dispatchAction({
                type: 'showTip',
                seriesIndex: 0,
                dataIndex: (count) % dataLength
            });
            count++;
        }, 3000);

        myCharts8.on('mouseover', function(params) {
            clearInterval(timeTicket);
            myCharts8.dispatchAction({
                type: 'downplay',
                seriesIndex: 0
            });
            myCharts8.dispatchAction({
                type: 'highlight',
                seriesIndex: 0,
                dataIndex: params.dataIndex
            });
            myCharts8.dispatchAction({
                type: 'showTip',
                seriesIndex: 0,
                dataIndex: params.dataIndex,
            });
        });
        myCharts8.on('mouseout', function(params) {
            timeTicket && clearInterval(timeTicket);
            timeTicket = setInterval(function() {
                myCharts8.dispatchAction({
                    type: 'downplay',
                    seriesIndex: 0,
                });
                myCharts8.dispatchAction({
                    type: 'highlight',
                    seriesIndex: 0,
                    dataIndex: (count) % dataLength
                });
                myCharts8.dispatchAction({
                    type: 'showTip',
                    seriesIndex: 0,
                    dataIndex: (count) % dataLength
                });
                count++;
            }, 2000);
        });
        myCharts8.setOption(option8);
        //获取动态数据
        $.ajax({
            url     :   '/statistics/data/cockpit/homeMobileUser',
            type:'POST',
            success :   function(result){
                if(result.code == "200"&&result.data){
                    myCharts8.setOption({
                        series: [{
                            data: [{
                                value: result.data.wxAppletCount,
                                name: '小程序'
                            }, {
                                value: result.data.appCount,
                                name: 'APP'
                            }]
                        }]
                    });
                }
            }
        });
    }

    // 窗口大小改变事件
    window.addEventListener("resize", function () {
        myCharts1.resize();
        myCharts2.resize();
        myCharts3.resize();
        myCharts4.resize();
        myCharts5.resize();
        myCharts6.resize();
        myCharts7.resize();
        myCharts8.resize();

    });


    //TOP城市物业明细
    var MyMarhq = '';
    function cityEstateDetail() {
        $.ajax({
            url     :   '/statistics/data/cockpit/homeCityEstateDetail',
            type:'POST',
            success :   function(result){
                $('.tbl-body tbody').empty();
                $('.tbl-header tbody').empty();
                var data=result.data;
                if(result.code=="200"&&data){
                    for(var i in data){
                        var item=data[i];
                        i=Number(i)+1;
                        var regionCity=item.regionCity;
                        if(regionCity){
                            var deviceCount=item.deviceCount?item.deviceCount:0;
                            var residentialCount=item.residentialCount?item.residentialCount:0;
                            var userCount=item.userCount?item.userCount:0;
                            var str = '<tr>'+
                                '<td>'+i+'</td>'+
                                '<td>'+regionCity+'</td>'+
                                '<td>'+deviceCount+'</td>'+
                                '<td>'+residentialCount+'</td>'+
                                '<td>'+userCount+'</td>'+
                                '</tr>'
                            $('.tbl-body tbody').append(str);
                            $('.tbl-header tbody').append(str);
                        }

                    }
                }
                if(data.length > 10){
                    $('.tbl-body tbody').html($('.tbl-body tbody').html()+$('.tbl-body tbody').html());
                    $('.tbl-body').css('top', '0');
                    var tblTop = 0;
                    var speedhq = 50; // 数值越大越慢
                    var outerHeight = $('.tbl-body tbody').find("tr").outerHeight();
                    function Marqueehq(){
                        if(tblTop <= -outerHeight*data.length){
                            tblTop = 0;
                        } else {
                            tblTop -= 1;
                        }
                        $('.tbl-body').css('top', tblTop+'px');
                    }

                    MyMarhq = setInterval(Marqueehq,speedhq);
                    // 鼠标移上去取消事件
                    $(".tbl-header tbody").hover(function (){
                        clearInterval(MyMarhq);
                    },function (){
                        clearInterval(MyMarhq);
                        MyMarhq = setInterval(Marqueehq,speedhq);
                    })
                }else{
                    clearInterval(MyMarhq);
                    //取消绑定hover事件
                    $(".tbl-header tbody").off('mouseenter').unbind('mouseleave');
                    $('.tbl-body').css('top', '0px');
                }
            }
        });
    }
    //广告数量统计
    function adDataCockpitCount(){
        $.ajax({
            url     :   '/statistics/data/cockpit/homeAdDataCockpitCount',
            type:'POST',
            success :   function(result){
                if(result.code=="200"&&result.data){
                    $("#ad-type-count").text(result.data.adTypeCount);
                    $("#ad-exposure-count").text(result.data.adExposureCount);
                    $("#ad-watch-count").text(result.data.adWatchCount);
                }
            }
        });
    }

    //物业数量统计
    function homeEstateDataCockpitCount(){
        $.ajax({
            url     :   '/statistics/data/cockpit/homeEstateDataCockpitCount',
            type:'POST',
            success :   function(result){
                if(result.code=="200"&&result.data){
                    $("#org-count").text(result.data.orgCount);
                    $("#residential-count").text(result.data.residentialCount);
                    $("#unit-count").text(result.data.unitCount);
                    $("#user-count").text(result.data.userCount);
                    $("#guest-count").text(result.data.guestCount);
                    $("#online-device-count").text(result.data.onlineDeviceCount);

                    //设备数量
                    var deviceCount=result.data.deviceCount;
                    if(deviceCount){

                        var deviceCountArray=deviceCount.split("");
                        var deviceCountSpan="";
                        for(var a in deviceCountArray){
                            deviceCountSpan+="<span>"+deviceCountArray[a]+"</span>"
                        }
                        $("#device-count-distribution").html(deviceCountSpan);
                    }
                }
            }
        });
    }

    //定时更新
    var timer = setInterval(function () {
        //物业数量统计
        homeEstateDataCockpitCount();
        //广告数量统计
        adDataCockpitCount();
    },"3000");

    //window 监听页面离开
    window.onbeforeunload = function(e){
        clearInterval(timer);
    }





    //全屏模式
    $(".screen-btn").click(function(){
        var parentDocument=window.parent.document;
        $(parentDocument).find("iframe").attr("allowFullScreen",true);
        //全屏
        var docElm = document.documentElement;
        if($(this).find('i').hasClass('reduce')){
            $(this).find('i').removeClass('reduce').attr('title','全屏');

            if (window.ActiveXObject)
            {
                iefull();
            }else{
                exitScreen();
            }

        }else{
            $(this).find('i').addClass('reduce').attr('title','退出全屏');
            if (window.ActiveXObject)
            {
                iefull();
            }else{
                fullScreen();
            }
        }
    });

    //初始化
    (function(){
        //物业数量统计
        homeEstateDataCockpitCount();
        //广告数量统计
        adDataCockpitCount();
        //观看量top10排行
        adWatchCityRankTopTen();
        //广告类别观看分布
        adWatchAdType();
        //广告每日观看趋势
        adEverydayWatchTrend();
        //地图
        deviceMap();
        //TOP城市物业明细
        cityEstateDetail();
        //开门方式
        openWay();
        //住户认证
        authWay();
        //用户类型
        userType();
        //移动端用户
        mobileUser();
    })();
});
//全屏
function fullScreen(){
    var el = document.documentElement;
    var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullscreen;
    if(typeof rfs != "undefined" && rfs) {
        rfs.call(el);
    };
    return;
}
//退出全屏
function exitScreen(){
    if (document.exitFullscreen) {
        document.exitFullscreen();
    }
    else if (document.mozCancelFullScreen) {
        document.mozCancelFullScreen();
    }
    else if (document.webkitCancelFullScreen) {
        document.webkitCancelFullScreen();
    }
    else if (document.msExitFullscreen) {
        document.msExitFullscreen();
    }
    if(typeof cfs != "undefined" && cfs) {
        cfs.call(el);
    }
}
//ie低版本的全屏，退出全屏都这个方法
function iefull(){
    if(typeof window.ActiveXObject != "undefined") {
        //这的方法 模拟f11键，使浏览器全屏
        var wscript = new ActiveXObject("WScript.Shell");
        if(wscript != null) {
            wscript.SendKeys("{F11}");
        }
    }
}
