var year = new Date().getFullYear();
var x_m_array = new Array();
var x_m_array_temp = new Array();
var date = new Date().getDate();
var array_year_score = new Array();
var array_points = new Array();
var array_points2 = new Array();

var array_road = new Array();
var array_road_score = new Array();
var array_road_score_temp = new Array();
var array_allStation = new Array();
var array_allStation_score = new Array();
var array_allStation_score_temp = new Array();
var array_check_type = new Array();

var map_per_data = new HashMap();
var map_month_data = new HashMap();
var array_all_name = new Array()
var array_all_deptname = new Array()



var array_points_name = new Array();
var array_points_pre = new Array();
var arrar_points_month = new Array();
var year_assess;
var points_assess;
var score_rank;
var stationAll_rank;
var check_type;
var people_points;
var flag = true;
var min_year;
var min_road;
var min_allStation;
var score_ranking = new Array();
$(function() {
    // 公用方法，根据当前年月动态将13个月push数组
    month_method();
    // 公用方法，月份下拉框
    // select_option();
    // 回显当前年月份
    // $(".div-month select").val(initDate);
    $.jeDate("#month_date", {
        isinitVal: true,
        format: 'YYYY/MM' // 分隔符可以任意定义，该例子表示只显示年月
    });
    $("#month_date").val(getCurrentTimeFormat());

    var p = $.zui.store.get('store_param_' + current_url);
    $.zui.store.set('store_param_' + current_url, null)
    if (p) {
        $("#month_date").val(p.time)
    }

    refresh(true);
    $(".query-company").click(function() {
        // var select_month = $("#month_date").val();
        // flag = false;
        // console.log(select_month);

        // // 加载图配置
        // echart();
        refresh(false);
    });


    function refresh(flag) {
        // 加载图配置
        echart(flag);
        var select_month = $("#month_date").val();
        // console.log(select_month);
        init_company_year_assess(select_month.split('/')[0], select_month.split('/')[1]);
        // 查询图二
        //	init_company_points_assess("statistics/lost/score/rate",select_month+'');
        init_company_points_assess("f/statistics/score/info", select_month.split('/')[0], select_month.split('/')[1]);
        // 查询图三
        init_road_manager_score_rank_three("f/statistics/score/center/manage/info", select_month + '');
        // 查询图四
        init_stationAll_rank_four("f/statistics/score/tollgate/info", select_month + '');
        // 查询图五
        init_server_check_type_five("f/statistics/lost/itemscore/rate", select_month + "");
        // 查询图六
        init_each_people_points_six("f/statistics/lost/twice/itemscore/rate", select_month + "");
    }
    /**
     * 初始化图一
     */
    function init_company_year_assess(y, m) {

        x_m_array = new Array();
        for (var i = 1; i <= 12; i++) {
            var month = parseInt(m) + i;
            var starty = parseInt(y) - 1
            if (month > 12) {
                month = month - 12;
                starty = y;
            }
            x_m_array.push(starty + "/" + (month >= 10 ? month : ("0" + month)));
        }


        var param = {
            "start_date": (parseInt(y) - 1) + "-" + m + "-25" + " 23:00:00",
            "end_date": y + "-" + (m) + "-25" + " 23:00:00"
        }


        initRqueset("f/statistics/score/year/info", param, 1);

    }
    // init_company_year_assess();
    /**
     * 初始化图二
     */
    function init_company_points_assess(url, y, mon) {
        var starty = y;
        var startm = parseInt(mon) - 1;

        if (startm <= 0) {
            startm = 12;
            starty = parseInt(y) - 1;
        }
        var param = {
            "start_date": starty + '-' + (startm >= 10 ? startm : ("0" + startm)) + '-25 23:00:00',
            "end_date": y + '-' + mon + '-25 23:00:00'
        }
        initRqueset(url, param, 2);
    }
    // init_company_points_assess("statistics/lost/score/rate",initDate+"");


    /**
     * 初始化图三
     */
    function init_road_manager_score_rank_three(url, mon) {
        var param = {
            "mth": mon
        };
        initRqueset(url, param, 3);
    }
    // init_road_manager_score_rank_three("statistics/score/center/manage/info",initDate+"");

    /**
     * 初始化图四
     */
    function init_stationAll_rank_four(url, mon) {
        var param = {
            "mth": mon
        };
        initRqueset(url, param, 4);
    }
    // init_stationAll_rank_four("statistics/score/tollgate/info",initDate+"");

    /**
     * 初始化图五
     */
    function init_server_check_type_five(url, mon) {
        var param = {
            "mth": mon,
            "queryType": 0
        };
        initRqueset(url, param, 5);
    }
    // init_server_check_type_five("statistics/lost/itemscore/rate",initDate+"");

    /**
     * 初始化图六
     */
    function init_each_people_points_six(url, mon) {
        var prev_mth;
        // 判断当前年月是否为一月
        if (parseInt((mon + '').substr(5)) == 1) {
            prev_mth = ((parseInt((mon + '').substr(0, 4))) - 1) + "/12";
        } else {
            var m = (parseInt((mon + '').substr(5)) - 1);
            if ((parseInt((mon + '').substr(5)) + '').length == 1) {
                prev_mth = (mon + '').substr(0, 4) + '/' + (m > 9 ? m : "0" + m);
            } else {
                prev_mth = (mon + '').substr(0, 4) + '/' + (m > 9 ? m : "0" + m);
            }

        }
        var param = {
            "mth": mon,
            "prev_mth": prev_mth,
            "queryType": 0
        };
        initRqueset(url, param, 6);
    }
    // init_each_people_points_six("statistics/lost/twice/itemscore/rate",initDate+"");

    /**
     * 请求
     * @param {*} url
     * @param {*} param
     * @param {*} type
     */
    function initRqueset(url, param, type) {
        post_common_service(url, param, function(data) {
            data_array(data, type);
            if (type == 1) {
                // 画图
                year_assess.setOption(company_year_assess_one());
            } else if (type == 2) {
                //array_points= [];
                // 画图
                points_assess.setOption(company_points_assess_two());
            } else if (type == 3) {
                // 画图
                score_rank.setOption(road_manager_score_rank_three());
            } else if (type == 4) {
                // 画图
                stationAll_rank.setOption(company_stationAll_rank_four());
            } else if (type == 5) {
                // 画图
                check_type.setOption(server_check_type_five());
            } else if (type == 6) {
                // 画图
                people_points.setOption(each_people_points_six());
            }
        }, function(error) {
            return "";
        });
    }


    function pushDate(data, organArray, names, appendname) {
        var temp = [0, 0, 0];
        for (var i = 0; i < data.list.length; i++) {
            if (i < organArray[0]) {
                temp[0] += data.list[i][names];
            } else if (i < organArray[1]) {
                temp[1] += data.list[i][names];
            } else if (i < organArray[2]) {
                temp[2] += data.list[i][names];
            }
        }

        var color1 = "red"
        var color2 = "red"
        var color3 = "red"
        if (appendname == "0-15分") {
            color1 = "#56A5EC"
            color2 = "#5CB3FF"
            color3 = "#82CAFA"

        }
        if (appendname == "15-50分") {
            color1 = "#FDD017"
            color2 = "#FBB917"
            color3 = "#FFA62F"

        }
        if (appendname == "50分以上") {
            color1 = "#8E35EF"
            color2 = "#8467D7"
            color3 = "#D462FF"
        }



        if (temp[0] != 0) {
            array_points2.push({ "value": temp[0], "name": '连云港道管', "itemStyle": { "normal": { "color": color1 } } });
        }
        if (temp[1] != 0) {
            array_points2.push({ "value": temp[1], "name": '盐城道管', "itemStyle": { "normal": { "color": color2 } } });
        }
        if (temp[2] != 0) {
            array_points2.push({ "value": temp[2], "name": '南通道管', "itemStyle": { "normal": { "color": color3 } } });
        }
    }

    /**
     * 数组数据
     * @param {*} data
     * @param {*} type
     */
    function data_array(data, type) {
        if (type == 1) {

            array_year_score.length = 0;
            if (data != '' && data.length != 0) {

                x_m_array_temp = new Array();
                for (var i = 0; i < x_m_array.length; i++) {

                    var index = -1;
                    for (var j = 0; j < data.length; j++) {
                        if (x_m_array[i] == data[j].mth) {
                            index = j;
                            break;
                        }
                    }
                    if (index < 0) {

                    } else {

                        x_m_array_temp.push(x_m_array[i]);
                        array_year_score.push(
                            (1000 - (filter_handler(data[index].all_check_score, data[index].checked_num, 1.0, 0))));
                    }
                }
            } else {
                array_year_score.length = 0;
                x_m_array = new Array();
                x_m_array_temp = new Array();
            }


            if (eval("Math.min(" + array_year_score.toString() + ")") == 0)
                min_year = 0;
            else
                min_year = eval("Math.min(" + array_year_score.toString() + ")").toFixed(0) - 10;
        } else if (type == 2) {
            // 获得各个道管下面所有服务区的数量
            debugger
            var organList = data.organList;
            var organArray = new Array();
            var organCount = 0;
            for (h=0;h<organList.length;h++) {
                organCount += organList[h].sacount;
                organArray.push(organCount);
            }

            array_points2 = [];
            array_points = [];
            // console.log(data);
            if (data != null) {
                array_points.push({ "value": (data.total0), "name": '满分', "itemStyle": { "normal": { "color": '#48CCCD' } } });
                array_points.push({ "value": data.total15, "name": '0-15分', "itemStyle": { "normal": { "color": '#38ACEC' } } });
                array_points.push({ "value": data.total50, "name": '15-50分', "itemStyle": { "normal": { "color": '#FFD801' } } });
                array_points.push({ "value": data.totalOver50, "name": '50分以上', "itemStyle": { "normal": { "color": '#7F38EC' } } });
                var temp = [0, 0, 0];

                // 满分
                for (var i = 0; i < data.list.length; i++) {
                    if (i < organArray[0]) {
                        temp[0] += data.list[i].checked_num - data.list[i].score_fifteen - data.list[i].score_fifty - data.list[i].score_over_fifty;
                    } else if (i < organArray[1]) {
                        temp[1] += data.list[i].checked_num - data.list[i].score_fifteen - data.list[i].score_fifty - data.list[i].score_over_fifty;
                    } else if (i < organArray[2]) {
                        temp[2] += data.list[i].checked_num - data.list[i].score_fifteen - data.list[i].score_fifty - data.list[i].score_over_fifty;
                    }
                }
                if (temp[0] != 0) {
                    array_points2.push({ "value": temp[0], "name": '连云港道管', "itemStyle": { "normal": { "color": '#7BCCB5' } } });
                }
                if (temp[1] != 0) {
                    array_points2.push({ "value": temp[1], "name": '盐城道管', "itemStyle": { "normal": { "color": '#3EA99F' } } });
                }
                if (temp[2] != 0) {
                    array_points2.push({ "value": temp[2], "name": '南通道管', "itemStyle": { "normal": { "color": '#008080' } } });
                }
                pushDate(data, organArray, 'score_fifteen', '0-15分');
                pushDate(data, organArray, 'score_fifty', '15-50分');
                pushDate(data, organArray, 'score_over_fifty', '50分以上');
            } else {
                array_points.length = 0;
            }
        } else if (type == 3) {
            array_road.length = 0;
            array_road_score.length = 0;
            for (var i = 0; i < data.length; i++) {
                if (data != '') {
                    array_road_score.push((1000 - (filter_handler(data[i].all_check_score, data[i].checked_num, 1.0, 0))));
                } else {
                    array_road.length = 0;
                    array_road_score.length = 0;
                }
            }
            if (eval("Math.min(" + array_road_score.toString() + ")") == 0)
                min_road = 0;
            else
                min_road = eval("Math.min(" + array_road_score.toString() + ")").toFixed(0) - 10;

            // 给道管中心排名次
            var rank = new Array();
            rank[0] = 1;
            for (var i = 1; i < array_road_score.length; i++) {
                if (array_road_score[i - 1] == array_road_score[i]) {
                    rank[i] = rank[i - 1];
                } else {
                    rank[i] = i + 1;
                }
            }
            array_road_score_temp = new Array();
            for (var i = 0; i < array_road_score.length; i++) {
                array_road.push(data[i].feeStationName + "\n" + (rank[i]));
                array_road_score_temp.push({ value: array_road_score[i], name: data[i].feeStationName })
            }
        } else if (type == 4) {
            array_allStation_score.length = 0;
            array_allStation.length = 0;
            for (var i = 0; i < data.length; i++) {
                if (data != '' && data.length != 0) {

                    array_allStation_score.push((1000 - (filter_handler(data[i].all_check_score, data[i].checked_num, 1.0, 0))));
                } else {
                    array_allStation_score.length = 0;
                    array_allStation.length = 0;
                }
            }

            if (eval("Math.min(" + array_allStation_score.toString() + ")") == 0)
                min_allStation = 0;
            else
                min_allStation = eval("Math.min(" + array_allStation_score.toString() + ")").toFixed(0) - 10;

            // 给收费站排名次
            var rank = new Array();
            rank[0] = 1;
            for (var i = 1; i < array_allStation_score.length; i++) {
                if (array_allStation_score[i - 1] == array_allStation_score[i]) {
                    rank[i] = rank[i - 1];
                } else {
                    rank[i] = i + 1;
                }
            }
            array_allStation_score_temp = new Array();
            for (var i = 0; i < array_allStation_score.length; i++) {
                array_allStation.push(data[i].feeStationName.substr(0, data[i].feeStationName.length - 3) + "\n" + (rank[i]));
                array_allStation_score_temp.push({ value: array_allStation_score[i], name: data[i].feeStationName })
            }
        } else if (type == 5) {
            array_check_type = [];
            if (data.length != 0) {
                var map = new HashMap();
                for (var i = 0; i < data.length; i++) {
                    if (map.get(data[i].name) == null) {
                        map.set(data[i].name, data[i].all_check_score)
                    } else {
                        map.set(data[i].name, data[i].all_check_score + map.get(data[i].name))
                    }

                }

                map.forEach(function(value, key) {
                    array_check_type.push({ "value": value, "name": key });
                });
            } else {
                array_check_type.length = 0;
            }
        } else if (type == 6) {
            array_all_deptname = new Array();
            map_month_data = new HashMap();
            map_per_data = new HashMap();

            // array_points_name.length = 0;
            // array_points_pre.length = 0;
            // arrar_points_month.length = 0;
            if (data != '' && data.list.Pmth.length != 0 || data.list.Tmth.length != 0) {
                data_each_people_points(data);
            } else {
                // array_points_name.length = 0;
                // array_points_pre.length = 0;
                // arrar_points_month.length = 0;
            }
        }
    }

    function data_each_people_points(data) {
        var flag = false;
        var name = data.itemList;
        array_all_name = name;
        // array_all_deptname = ["连云港道管", "盐城道管", "南通道管"];
        var Tmth = data.list.Tmth;
        var Pmth = data.list.Pmth;

        for (var i = 0; i < name.length; i++) {
            
            for (var j = 0; j < Tmth.length; j++) {
                flag = false;
                if (array_all_deptname.length > 0) {
                    for (var p = 0; p < array_all_deptname.length; p++) {
                        if (array_all_deptname[p] == Tmth[j].pfeeStationName) {
                            flag = true;
                            break;
                        }
                    }
                }
                if (!flag) {
                    array_all_deptname.push(Tmth[j].pfeeStationName);
                }

                if (name[i] == Tmth[j].name) {
                    if (map_month_data.get(Tmth[j].pfeeStationName) != null) {
                        var map = map_month_data.get(Tmth[j].pfeeStationName)
                        if (map.get(name[i]) != null) {
                            map.set(name[i], map.get(name[i]) + Tmth[j].all_check_score);
                        } else {
                            map.set(name[i], Tmth[j].all_check_score);
                        }
                        map_month_data.set(Tmth[j].pfeeStationName, map);
                    } else {
                        var map = new HashMap();
                        map.set(name[i], Tmth[j].all_check_score);
                        map_month_data.set(Tmth[j].pfeeStationName, map);
                    }
                }

            }

            for (var j = 0; j < Pmth.length; j++) {
                flag = false;
                if (array_all_deptname.length > 0) {
                    for (var p = 0; p < array_all_deptname.length; p++) {
                        if (array_all_deptname[p] == Pmth[j].pfeeStationName) {
                            flag = true;
                            break;
                        }
                    }
                }
                if (!flag) {
                    array_all_deptname.push(Pmth[j].pfeeStationName);
                }
                if (name[i] == Pmth[j].name) {
                    if (map_per_data.get(Pmth[j].pfeeStationName) != null) {
                        var map = map_per_data.get(Pmth[j].pfeeStationName)
                        if (map.get(name[i]) != null) {
                            map.set(name[i], map.get(name[i]) + Pmth[j].all_check_score);
                        } else {
                            map.set(name[i], Pmth[j].all_check_score);
                        }
                        map_per_data.set(Pmth[j].pfeeStationName, map);
                    } else {
                        var map = new HashMap();
                        map.set(name[i], Pmth[j].all_check_score);
                        map_per_data.set(Pmth[j].pfeeStationName, map);
                    }
                }
            }
        }       
    }

    /**
     * 除数为0处理
     * @param {*} num
     * @param {*} num1
     * @param {*} num2
     * @param {*} num4
     */
    function filter_handler(num, num1, num2, num4) {
        if (num1 == 0 || num2 == 0) {
            return num4;
        } else {
            return ((num / num1) / num2).toFixed(2);
        }
    }

    /**
     * 图配置
     */
    function echart(flag) {
        // 路径配置
        require.config({
            paths: {
                echarts: '/js/lib/echarts/build/dist'
            }
        });
        // 使用
        require(
            [
                'echarts',
                'echarts/theme/macarons',
                'echarts/chart/line',
                'echarts/chart/bar',
                'echarts/chart/pie',
                'echarts/config'
            ],
            function(ec, theme) {

                // 基于准备好的dom，初始化echarts图表
                if (flag) {
                    year_assess = ec.init(document.getElementById('company-year-assess'), theme);
                }
                points_assess = ec.init(document.getElementById('company-points-assess'), theme);
                score_rank = ec.init(document.getElementById('roadManager-score-rank'));
                stationAll_rank = ec.init(document.getElementById('company-stationAll-rank'));
                check_type = ec.init(document.getElementById('server-check-type'), theme);
                people_points = ec.init(document.getElementById('each-people-points'));

                // points_assess.on(ecConfig.EVENT.CLICK, point_c)
                // score_rank.on(ecConfig.EVENT.CLICK, score_c)
                // stationAll_rank.on(ecConfig.EVENT.CLICK, station_c)

            }
        );
    }

    /**
     * 图一
     */
    function company_year_assess_one() {
        //debugger;
        option = {
            color: ['#00ced1'],
            tooltip: {
                trigger: 'axis'
            },
            noDataLoadingOption: {
                text: '暂无数据',
                effect: 'bubble',
                effectOption: {
                    effect: {
                        n: 0 //气泡个数为0
                    }
                },
                textStyle: {
                    fontSize: 20,
                    fontFamily: 'cursive',
                    fontWeight: 'bold'
                }
            },
            legend: {
                data: ['公司得分']
            },
            toolbox: {
                show: true,
            },
            calculable: true,
            xAxis: [{
                type: 'category',
                boundaryGap: false,
                data: x_m_array_temp
            }],
            yAxis: [{
                type: 'value',
                min: min_year,
                max: 1000,
                axisLabel: {
                    formatter: '{value}'
                }
            }],
            series: [{
                    name: '公司得分',
                    type: 'line',
                    data: array_year_score,
                    markPoint: {
                        data: [
                            { type: 'max', name: '最大值' },
                            { type: 'min', name: '最小值' }
                        ]
                    },
                    markLine: {
                        data: [
                            { type: 'average', name: '平均值' }
                        ]
                    }
                },

            ]
        };
        return option;
    }


    /**
     * 图二
     */
    function company_points_assess_two() {
        option = {
            tooltip: {
                trigger: 'item',
                formatter: "公司考核扣分占比 <br/>{b} : {c}次 ({d}%)"
            },

            toolbox: {
                show: true,
            },
            calculable: false,
            series: [{
                    name: '访问来源',
                    type: 'pie',
                    selectedMode: 'single',
                    radius: [0, 80],

                    // for funnel
                    x: '20%',
                    width: '40%',
                    funnelAlign: 'right',
                    max: 1548,

                    itemStyle: {
                        normal: {
                            label: {
                                show: true,
                                formatter: '{b}:\n{c}次({d}%)',
                                textStyle: {
                                    alias: 'center',
                                    fontSize: 10,
                                    color: '#888'
                                }
                            },
                            labelLine: {
                                show: true,
                                length: 50,
                                lineStyle: {
                                    color: '#888'
                                }

                            }
                        }
                    },
                    data: array_points
                },
                {
                    name: '访问来源',
                    type: 'pie',
                    radius: [100, 125],

                    // for funnel
                    x: '60%',
                    width: '35%',
                    funnelAlign: 'left',
                    max: 1048,
                    itemStyle: {
                        normal: {
                            label: {
                                show: false,
                                formatter: '{b}:{c}次({d}%)'
                            },
                            labelLine: {
                                show: false
                            }
                        }
                    },
                    data: array_points2
                }
            ]
        };


        return option;
    }

    /**
     * 图三
     */
    function road_manager_score_rank_three() {
        option = {
            color: ['#00ced1'], // 条形图颜色
            tooltip: {
                trigger: 'axis'
            },
            noDataLoadingOption: {
                text: '暂无数据',
                effect: 'bubble',
                effectOption: {
                    effect: {
                        n: 0 //气泡个数为0
                    }
                },
                textStyle: {
                    fontSize: 20,
                    fontFamily: 'cursive',
                    fontWeight: 'bold'
                }
            },
            grid: {
                width: "75%",

            },
            calculable: true,
            xAxis: [{
                axisLabel: {
                    interval: 0
                },
                type: 'category',
                data: array_road
            }],
            yAxis: [{
                type: 'value',
                min: min_road,
                max: 1000
            }],
            series: [{

                type: 'bar',
                data: array_road_score_temp,
                itemStyle: {
                    normal: {
                        label: {
                            show: true,
                            position: 'insideTop'
                        }
                    }
                },
                markLine: {
                    data: [
                        { type: 'average', name: '平均值' }
                    ]
                }
            }]
        };

        return option;
    }

    /**
     * 图四
     */
    function company_stationAll_rank_four() {
        option = {
            color: ['#00ced1'], // 条形图颜色
            tooltip: {
                trigger: 'axis'
            },
            noDataLoadingOption: {
                text: '暂无数据',
                effect: 'bubble',
                effectOption: {
                    effect: {
                        n: 0 //气泡个数为0
                    }
                },
                textStyle: {
                    fontSize: 20,
                    fontFamily: 'cursive',
                    fontWeight: 'bold'
                }
            },
            legend: {
                data: ['公司全体服务区得分']
            },
            calculable: true,
            xAxis: [{
                axisLabel: {
                    interval: 0
                },
                type: 'category',
                data: array_allStation
            }],
            yAxis: [{
                type: 'value',
                min: min_allStation,
                max: 1000
            }],
            series: [{
                name: '公司全体服务区得分',
                type: 'bar',
                data: array_allStation_score_temp,
                itemStyle: {
                    normal: {
                        label: {
                            show: true,
                            position: 'insideTop'
                        }
                    }
                },
                markLine: {
                    data: [
                        { type: 'average', name: '平均值' }
                    ]
                }
            }]
        };

        return option;
    }

    /**
     * 图五
     */
    function server_check_type_five() {
        option = {
            tooltip: {
                trigger: 'item',
                formatter: "温馨服务检查占比 <br/>{b} : {c}分 ({d}%)"
            },
            noDataLoadingOption: {
                text: '暂无数据',
                effect: 'bubble',
                effectOption: {
                    effect: {
                        n: 0 //气泡个数为0
                    }
                },
                textStyle: {
                    fontSize: 20,
                    fontFamily: 'cursive',
                    fontWeight: 'bold'
                }
            },
            toolbox: {
                show: true,
                feature: {

                    magicType: {

                        type: ['pie', 'funnel'],
                        option: {
                            funnel: {
                                x: '25%',
                                width: '50%',
                                funnelAlign: 'left',
                                max: 1548
                            }
                        }
                    },
                }
            },
            calculable: true,
            series: [{
                name: '访问来源',
                type: 'pie',
                radius: '55%',
                center: ['50%', '50%'],
                data: array_check_type,
                itemStyle: {
                    normal: {
                        label: {
                            show: true,
                            formatter: '{b} :\n{c}分 ({d}%)'
                        },
                        labelLine: { show: true }
                    }
                }
            }]
        };
        return option;
    }

    /**
     * 图六
     */
    function each_people_points_six() {

        var t_map_p = new HashMap();
        var t_map_c = new HashMap();


        var sdata = new Array();

        for (var j = 0; j < array_all_deptname.length; j++) {
            var dept = array_all_deptname[j]

            if (map_per_data.get(dept) != null) {
                var data_a = new Array();
                var d_t = map_per_data.get(dept);
                for (var i = 0; i < array_all_name.length; i++) {
                    var name = array_all_name[i];
                    data_a.push(d_t.get(name) == null ? 0 : d_t.get(name));

                    if (t_map_p.get(name) == null) {
                        t_map_p.set(name, d_t.get(name) == null ? 0 : d_t.get(name))
                    } else {
                        t_map_p.set(name, t_map_p.get(name) + (d_t.get(name) == null ? 0 : d_t.get(name)));
                    }
                }
                var d_tt = {
                    name: dept,
                    type: 'bar',
                    stack: '上月',
                    barGap: 5,
                    barCategoryGap: 20,
                    data: data_a
                }
                if (j == array_all_deptname.length - 1) {
                    d_tt['itemStyle'] = {
                        normal: {
                            label: {
                                show: true,
                                position: 'top',
                                formatter: function(params) {
                                    var name = params.name
                                    if (name == '仪表') {
                                        name = '仪容仪表着装';
                                    }
                                    if (name == '行为') {
                                        name = '工作纪律及行为举止';
                                    }

                                    var v = t_map_p.get(name);
                                    if (isNaN(v)) v = 0;
                                    return '上月\n' + v;
                                },
                                textStyle: {
                                    color: 'blue'
                                }
                            }
                        }
                    }
                }
                sdata.push(d_tt);
            } else {
                var data_a = new Array();
                for (var i = 0; i < array_all_name.length; i++) {
                    var name = array_all_name[i];
                    data_a.push(0);

                    if (t_map_p.get(name) == null) {
                        t_map_p.set(name, 0)
                    } else {
                        t_map_p.set(name, t_map_p.get(i) + 0);
                    }
                }
                var d_tt = {
                    name: dept,
                    type: 'bar',
                    stack: '上月',
                    data: data_a
                }
                if (j == array_all_deptname.length - 1) {
                    d_tt['itemStyle'] = {
                        normal: {
                            label: {
                                show: true,
                                position: 'top',
                                formatter: function(params) {
                                    var name = params.name
                                    if (name == '仪表') {
                                        name = '仪容仪表着装';
                                    }
                                    if (name == '行为') {
                                        name = '工作纪律及行为举止';
                                    }
                                    var v = t_map_p.get(name);
                                    if (isNaN(v)) v = 0;
                                    return '上月\n' + v;
                                },
                                textStyle: {
                                    color: 'blue'
                                }
                            }
                        }
                    }
                }
                sdata.push(d_tt);
            }
            if (map_month_data.get(dept) != null) {
                var data_a = new Array();
                var d_t = map_month_data.get(dept);
                for (var i = 0; i < array_all_name.length; i++) {
                    var name = array_all_name[i];
                    data_a.push(d_t.get(name) == null ? 0 : d_t.get(name));

                    if (t_map_c.get(name) == null) {
                        t_map_c.set(name, d_t.get(name) == null ? 0 : d_t.get(name))
                    } else {
                        t_map_c.set(name, t_map_c.get(name) + (d_t.get(name) == null ? 0 : d_t.get(name)));
                    }
                }
                var d_tt = {
                    name: dept,
                    type: 'bar',
                    stack: '本月',
                    data: data_a
                }
                if (j == array_all_deptname.length - 1) {
                    d_tt['itemStyle'] = {

                        normal: {
                            label: {
                                show: true,
                                position: 'top',
                                formatter: function(params) {
                                    var name = params.name
                                    if (name == '仪表') {
                                        name = '仪容仪表着装';
                                    }
                                    if (name == '行为') {
                                        name = '工作纪律及行为举止';
                                    }

                                    var v = t_map_c.get(name);
                                    if (isNaN(v)) v = 0;
                                    return '本月\n' + v;
                                },
                                textStyle: {
                                    color: 'red'
                                }
                            }
                        }
                    }
                }
                sdata.push(d_tt);
            } else {
                var data_a = new Array();
                for (var i = 0; i < array_all_name.length; i++) {
                    var name = array_all_name[i];
                    data_a.push(0);
                    if (t_map_c.get(name) == null) {
                        t_map_c.set(name, 0)
                    } else {
                        t_map_c.set(name, t_map_c.get(name) + 0);
                    }
                }
                var d_tt = {
                    name: dept,
                    type: 'bar',
                    stack: '本月',
                    data: data_a
                }
                if (j == array_all_deptname.length - 1) {
                    d_tt['itemStyle'] = {
                        normal: {
                            label: {
                                show: true,
                                position: 'top',
                                formatter: function(params) {
                                    var name = params.name
                                    if (name == '仪表') {
                                        name = '仪容仪表着装';
                                    }
                                    if (name == '行为') {
                                        name = '工作纪律及行为举止';
                                    }
                                    var v = t_map_c.get(name);
                                    if (isNaN(v)) v = 0;

                                    return '本月\n' + v;
                                },
                                textStyle: {
                                    color: 'red'
                                }
                            }
                        }
                    }
                }
                sdata.push(d_tt);
            }
        }

        var maxvaluedata = 0;
        t_map_c.forEach(function(value, key) {
            if (value > maxvaluedata) maxvaluedata = value;
        })
        t_map_p.forEach(function(value, key) {
            if (value > maxvaluedata) maxvaluedata = value;
        })



        var namelist = new Array();
        for (var i = 0; i < array_all_name.length; i++) {
            var name = array_all_name[i];
            if (name == '仪容仪表着装') {
                name = '仪表';
            }
            if (name == '工作纪律及行为举止') {
                name = '行为';
            }
            namelist.push(name);
        }


        option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: { // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                },
                formatter: function(params, ticket, callback) {
                    var name = "";
                    var content = "";
                    if (params.length > 0) {
                        for (var i = 0; i < params.length; i++) {
                            var p = params[i];
                            name = p.name;
                            if (p.series.stack == "本月") {
                                content += "<br>本月 " + p.seriesName.replace("道管中心", "") + ":" + p.value + "分"
                            } else {
                                content += "<br>上月 " + p.seriesName.replace("道管中心", "") + ":" + p.value + "分"
                            }
                        }
                    }
                    return name + content;
                }
            },
            noDataLoadingOption: {
                text: '暂无数据',
                effect: 'bubble',
                effectOption: {
                    effect: {
                        n: 0 //气泡个数为0
                    }
                },
                textStyle: {
                    fontSize: 20,
                    fontFamily: 'cursive',
                    fontWeight: 'bold'
                }
            },
            grid: {
                width: "80%",
            },
            legend: {
                data: array_all_deptname
            },
            calculable: true,
            xAxis: [{
                type: 'category',
                data: namelist
            }],
            yAxis: [{
                type: 'value',
                max: (maxvaluedata + 200)
            }],
            series: sdata
        };
        return option;
    }


});

var ecConfig = require('echarts/config');


// var temp_time = null;
// var road_p = null;
// var station_p = null;

function point_c(param) {
    if (typeof param.seriesIndex == 'undefined') {
        return;
    }
    if (param.type == 'click') {

        var pdata = {
            time: $("#month_date").val()
        }

        $.zui.store.set('page_data_param_temp_time', $("#month_date").val());

        $.zui.store.set('store_param_' + current_url, pdata);
        isnew = false;
        changePage("/fwq/view/statistics/assess_situation.html");

    }
}

function score_c(param) {
    if (typeof param.seriesIndex == 'undefined') {
        return;
    }
    if (param.type == 'click') {

        var pdata = {
            time: $("#month_date").val()
        }

        $.zui.store.set('page_data_param_temp_time', $("#month_date").val());
        $.zui.store.set('page_data_param_road_p', param.data.name);

        $.zui.store.set('store_param_' + current_url, pdata);
        isnew = false;
        changePage("/fwq/view/statistics/road_manage_statistics.html");
    }
}

function station_c(param) {
    if (typeof param.seriesIndex == 'undefined') {
        return;
    }
    if (param.type == 'click') {
        var pdata = {
            time: $("#month_date").val()
        }
        $.zui.store.set('page_data_param_temp_time', $("#month_date").val());



        var stationlist = $.zui.store.get("cache_fee_station_list");
        var roadlist = $.zui.store.get("cache_road_manager_list");

        for (var i in stationlist) {
            if (stationlist[i].name == param.data.name) {
                for (var j in roadlist) {
                    if (roadlist[j].deptid == stationlist[i].parentid) {
                        $.zui.store.set('page_data_param_road_p', roadlist[j].name);
                        break;
                    }
                }
                break;
            }
        }
        $.zui.store.set('page_data_param_station_p', param.data.name);
        $.zui.store.set('store_param_' + current_url, pdata);
        isnew = false;
        changePage("/fwq/view/statistics/toll_station_statistics.html");
    }
}