var year = new Date().getFullYear();
var month = new Date().getMonth();
var x_m_array = new Array();
var x_m_array_temp = new Array();
var date = new Date().getDate();
var year_assess;
var score_rank;
var points_assess;
var check_type;
var select_road = $(".div-roadManage select").val();
var array_year_score = new Array();
var array_points = new Array();
var array_points2 = 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 array_score_order = new Array();
var array_score_data = new Array();
var array_score_last = new Array();
var array_get_score = new Array();
var array_get_score_temp = new Array();
var array_score_pie = new Array();
var year_assess;
var score_rank;
var points_assess;
var check_type;
var people_points;
var rank_pre;
var rank_suf;
var min_year;
var min_station;
var min_pre
var min_suff;
var flag = false;
$(function() {
    setVisit();
    // 公用方法，根据当前年月动态将13个月push数组
    month_method();
    // 公用方法，月份下拉框
    // select_option();
    // 回显当前年月份
    // $(".div-month select").val(initDate);
    $.jeDate("#month_date", {
        isinitVal: true,
        format: 'YYYY/MM' // 分隔符可以任意定义，该例子表示只显示年月
    });

    var road_manager;
    if (roleContains("STATION")) {
        road_manager = getCurrentUser().road_manager_id;
    }
    if (roleContains("ROAD_MANAGER")) {
        road_manager = getCurrentUser().organid;
    }
    setRoadManagerSelect(".div-roadManage select", road_manager);

    var temp_time = $.zui.store.get('page_data_param_temp_time');
    var road_p = $.zui.store.get('page_data_param_road_p');

    console.log(temp_time)

    if (temp_time) {
        $("#month_date").val(temp_time);
        setRoadManagerSelect_1(".div-roadManage select", road_p);

        $.zui.store.set('page_data_param_temp_time', null);
        $.zui.store.set('page_data_param_road_p', null);
    }


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



    //加载数据
    refresh(true);

    $(".div-button button").click(function() {
        // var select_month = $("#month_date").val();
        // console.log("fffffff"+select_month);
        // var select_road = $(".div-roadManage select").val();
        // 加载图配置
        // echart();
        refresh(flag);
        // if(flag ==true){
        // 	init_company_year_assess("statistics/score/year/info",select_road);
        // }
        flag = false;
    });

    // 如果道管中心下拉框改变，点击时加载图一
    $(".div-roadManage").change(function() {
        flag = true;
    });

    // 加载图配置
    // echart();
    function refresh(flag) {
        echart(flag);
        var select_month = $("#month_date").val();
        var select_road = $(".div-roadManage select").val();

        init_company_year_assess("statistics/score/year/info", select_road, select_month.split('/')[0], select_month.split('/')[1]);

        // 查询图二
        // init_company_points_assess("statistics/lost/score/rate",select_month+'',select_road);
        init_company_points_assess("statistics/score/info", select_month.split('/')[0], select_month.split('/')[1]);
        // 查询图三
        init_stationAll_rank("statistics/score/manage/tollgate/info", select_month + '', select_road);
        // 查询图四
        //init_people_rank_pre("statistics/stuff/score/info",select_month+'',select_road);
        // 查询图五
        init_people_rank_suf("statistics/stuff/score/info", select_month + '', select_road);
        // 查询图六
        init_server_check_type("statistics/lost/itemscore/rate", select_month + "", select_road);
        // 查询图七
        init_each_people_points("statistics/lost/twice/itemscore/rate", select_month + "", select_road);
    }

    /**
     * 初始化图一
     */
    function init_company_year_assess(url, select_road, 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",
            "dept_id": select_road,
            "queryType": 1
        }
        initRqueset(url, param, 1);
    }

    /**
     * 初始化图二
     */
    function init_company_points_assess(url, y, mon, select_road) {
        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": year + '-' + mon + '-25 23:00:00'
        }
        initRqueset(url, param, 2);
    }

    /**
     * 初始化图三
     */
    function init_stationAll_rank(url, mon, select_road) {
        var param = {
            "mth": mon,
            "dept_id": select_road
        };
        initRqueset(url, param, 3);
    }

    /**
     * 初始化图四
     */
    function init_people_rank_pre(url, mon, select_road) {
        var param = {
            mth: mon,
            "dept_id": select_road,
            "queryType": 1,
            "order_type": 0
        }
        initRqueset(url, param, 4);
    }

    /**
     * 初始化图五
     */
    function init_people_rank_suf(url, mon, select_road) {
        var param = {
            mth: mon,
            "dept_id": select_road,
            "queryType": 1,
            "order_type": 1
        }
        initRqueset(url, param, 5);
    }

    /**
     * 初始化图六
     */
    function init_server_check_type(url, mon, select_road) {
        var param = {
            "mth": mon,
            "dept_id": select_road,
            "queryType": 1
        };
        initRqueset(url, param, 6);
    }

    /**
     * 初始化图七
     */
    function init_each_people_points(url, mon, select_road) {
        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);
            }
        }

        console.log(prev_mth);

        var param = {
            "mth": mon,
            "prev_mth": prev_mth,
            "dept_id": select_road,
            "queryType": 1
        };
        initRqueset(url, param, 7);
    }
    /**
     * 请求
     * @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(roadManager_year_assess());
            } else if (type == 2) {
                // 画图
                points_assess.setOption(roadManager_points_assess());
            } else if (type == 3) {
                // 画图
                score_rank.setOption(tollStation_score_rank());
            } else if (type == 4) {
                // 画图
                rank_pre.setOption(people_rank_pre());
            } else if (type == 5) {
                // 画图
                rank_suf.setOption(people_rank_suf());
            } else if (type == 6) {
                // 画图
                check_type.setOption(server_check_type());
            } else if (type == 7) {
                // 画图
                people_points.setOption(each_people_points());
            }
        }, function(error) {
            return "";
        });
    }

    function push_data(data, names, propertyname, center_id, color_t) {
        for (var i = 0; i < data.list.length; i++) {
            if (i < 7 && center_id == 30) {
                var p = i - 7;
                var color = new $.zui.Color(color_t.r + p * 10, color_t.g, color_t.b);
                if (data.list[i][propertyname] != 0)
                    array_points2.push({
                        "value": (data.list[i][propertyname]),
                        "name": data.list[i].name,
                        "itemStyle": { "normal": { "color": color.hexStr() } }
                    });
            } else if (i > 6 && i < 13 && center_id == 31) {
                var p = i - 6;
                var color = new $.zui.Color(color_t.r + p * 10, color_t.g - p * 10, color_t.b - p * 10);
                if (data.list[i][propertyname] != 0)
                    array_points2.push({
                        "value": (data.list[i][propertyname]),
                        "name": data.list[i].name,
                        "itemStyle": { "normal": { "color": color.hexStr() } }
                    });
            } else if (i > 12 && i < 21 && center_id == 32) {
                var p = i - 12;
                var color = new $.zui.Color(color_t.r + p * 10, color_t.g - p * 10, color_t.b - p * 10);
                if (data.list[i][propertyname] != 0)
                    array_points2.push({
                        "value": (data.list[i][propertyname]),
                        "name": data.list[i].name,
                        "itemStyle": { "normal": { "color": color.hexStr() } }
                    });
            }
        }
    }

    /**
     * 数组数据
     * @param {*} data
     * @param {*} type
     */
    function data_array(data, type) {
        if (type == 1) {
            array_year_score.length = 0;
            if (data != null && 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) {
            array_points = [];
            array_points2 = [];
            if (data != null) {
                var temp = [0, 0, 0, 0];
                // array_points.push({"value": (data.people_num-(data.score_fifteen+data.score_fifty+data.score_over_fifty)),"name":'满分'});
                // array_points.push({"value": data.score_fifteen,"name":'0-15分'});
                // array_points.push({"value": data.score_fifty,"name":'15-50分'});
                // array_points.push({"value": data.score_over_fifty,"name":'50分以上'});
                // 过滤出道管的数据

                var center_id = $(".div-roadManage select").val();

                for (var i = 0; i < data.list.length; i++) {
                    if (i < 7 && center_id == 30) {
                        temp[0] += data.list[i].checked_people_num - data.list[i].score_fifteen - data.list[i].score_fifty - data.list[i].score_over_fifty;
                        temp[1] += data.list[i].score_fifteen;
                        temp[2] += data.list[i].score_fifty;
                        temp[3] += data.list[i].score_over_fifty;
                    } else if (i > 6 && i < 13 && center_id == 31) {
                        temp[0] += data.list[i].checked_people_num - data.list[i].score_fifteen - data.list[i].score_fifty - data.list[i].score_over_fifty;
                        temp[1] += data.list[i].score_fifteen;
                        temp[2] += data.list[i].score_fifty;
                        temp[3] += data.list[i].score_over_fifty;
                    } else if (i > 12 && i < 21 && center_id == 32) {
                        temp[0] += data.list[i].checked_people_num - data.list[i].score_fifteen - data.list[i].score_fifty - data.list[i].score_over_fifty;
                        temp[1] += data.list[i].score_fifteen;
                        temp[2] += data.list[i].score_fifty;
                        temp[3] += data.list[i].score_over_fifty;
                    }
                }
                var color1 = new $.zui.Color('#48CCCD');
                var color2 = new $.zui.Color('#38ACEC');
                var color3 = new $.zui.Color('#FFD801');
                var color4 = new $.zui.Color('#7F38EC');

                array_points.push({ "value": (temp[0]), "name": '满分', "itemStyle": { "normal": { "color": color1.hexStr() } } });
                array_points.push({ "value": temp[1], "name": '0-15分', "itemStyle": { "normal": { "color": color2.hexStr() } } });
                array_points.push({ "value": temp[2], "name": '15-50分', "itemStyle": { "normal": { "color": color3.hexStr() } } });
                array_points.push({ "value": temp[3], "name": '50分以上', "itemStyle": { "normal": { "color": color4.hexStr() } } });

                for (var i = 0; i < data.list.length; i++) {
                    if (i < 7 && center_id == 30) {
                        var p = i;
                        var color = new $.zui.Color(color1.r - p * 10, color1.g - p * 10, color1.b - p * 10);
                        array_points2.push({
                            "value": (data.list[i].checked_people_num - data.list[i].score_fifteen -
                                data.list[i].score_fifty - data.list[i].score_over_fifty),
                            "name": data.list[i].name,
                            "itemStyle": { "normal": { "color": color.hexStr() } }
                        });
                    } else if (i > 6 && i < 13 && center_id == 31) {
                        var p = i - 6;
                        var color = new $.zui.Color(color1.r - p * 10, color1.g - p * 10, color1.b - p * 10);
                        array_points2.push({
                            "value": (data.list[i].checked_people_num - data.list[i].score_fifteen -
                                data.list[i].score_fifty - data.list[i].score_over_fifty),
                            "name": data.list[i].name,
                            "itemStyle": { "normal": { "color": color.hexStr() } }
                        });
                    } else if (i > 12 && i < 21 && center_id == 32) {
                        var p = i - 12;
                        var color = new $.zui.Color(color1.r - p * 10, color1.g - p * 10, color1.b - p * 10);
                        array_points2.push({
                            "value": (data.list[i].checked_people_num - data.list[i].score_fifteen -
                                data.list[i].score_fifty - data.list[i].score_over_fifty),
                            "name": data.list[i].name,
                            "itemStyle": { "normal": { "color": color.hexStr() } }
                        });
                    }
                }
                push_data(data, '0-15分', "score_fifteen", center_id, color2);

                push_data(data, '15-50分', "score_fifty", center_id, color3);

                push_data(data, '50分以上', "score_over_fifty", center_id, color4);

            } else {
                array_points = [];
            }

        } else if (type == 3) {
            array_allStation_score.length = 0;
            array_allStation.length = 0;
            if (data != null && data.length != 0) {
                for (var i = 0; i < data.length; i++) {
                    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_station = 0;
            else
                min_station = 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 == 4) {
            array_score_order.length = 0;
            array_score_data.length = 0;
            if (data != null && data.length != 0) {
                for (var i = 0; i < data.length; i++) {
                    array_score_order.push(data[i].user.truename + "\n" + "(" + data[i].user.fee_station_name.substr(0, data[i].user.fee_station_name.length - 3) + ")");
                    array_score_data.push((1000 - filter(data[i].all_check_score, 1.0, 0)));

                }
            } else {
                array_score_order.length = 0;
                array_score_data.length = 0;
            }
            if (eval("Math.min(" + array_score_data.toString() + ")") == 0)
                min_pre = 0;
            else
                min_pre = eval("Math.min(" + array_score_data.toString() + ")").toFixed(0) - 10;
        } else if (type == 5) {
            array_score_last.length = 0;
            array_get_score.length = 0;

            // 已有收费站数组 和 对象
            var feeStationTemp = [];
            var feeStationTempObj = {};

            if (data != '' && data.length != 0) {
                for (var i = 0; i < data.length; i++) {
                    array_get_score.push((1000 - filter(data[i].all_check_score, data[i].checked_num, 0)));
                    // 处理data
                    if (feeStationTempObj[data[i].user.fee_station_name] != null) {
                        feeStationTempObj[data[i].user.fee_station_name] += 1;
                    } else {
                        feeStationTempObj[data[i].user.fee_station_name] = 1;
                        feeStationTemp.push(data[i].user.fee_station_name);
                    }
                }
                array_score_pie = [];
                for (var x = 0; x < feeStationTemp.length; x++) {
                    array_score_pie.push({ 'name': feeStationTemp[x], 'value': feeStationTempObj[feeStationTemp[x]] });
                }
                // console.log(feeStationTemp);
                // console.log(feeStationTempObj);
            } else {
                array_score_last.length = 0;
                array_get_score.length = 0;
            }
            if (eval("Math.min(" + array_get_score.toString() + ")") == 0)
                min_suff = 0;
            else
                min_suff = eval("Math.min(" + array_get_score.toString() + ")").toFixed(0) - 10;

            // 给道管中心人员考核得分后20名
            var rank = new Array();
            rank[0] = 1;
            for (var i = 1; i < array_get_score.length; i++) {
                if (array_get_score[i - 1] == array_get_score[i]) {
                    rank[i] = rank[i - 1];
                } else {
                    rank[i] = i + 1;
                }
            }

            array_get_score_temp = new Array();

            for (var i = 0; i < array_get_score.length; i++) {
                array_score_last.push(data[i].user.truename + "\n" + "(" + data[i].user.fee_station_name.substr(
                    0, data[i].user.fee_station_name.length - 3) + ")" + "\n" + (rank[i]));

                array_get_score_temp.push({ value: array_get_score[i], name: data[i].user.id + "_" + data[i].user.organid })

            }
        } else if (type == 6) {
            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 == 7) {
            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 != null && data.Pmth.length != 0) || (data != null && data.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 = ['环境卫生', '仪容仪表着装', '表情', '动作', '文明用语', '工作纪律及行为举止', '便民服务', '安全管理']
        array_all_name = name;
        // array_all_deptname = ["连云港道管", "盐城道管", "南通道管"];
        var Tmth = data.Tmth;
        var Pmth = data.Pmth;
        // var Ntemp = new Array();
        // var Ptemp = new Array();
        // var Ttemp = new Array();

        for (var i = 0; i < name.length; i++) {
            //     var temp_map_m = new HashMap();
            //     var temp_map_p = new HashMap();

            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].feeStationName) {
                            flag = true;
                            break;
                        }
                    }
                }
                if (!flag) {
                    array_all_deptname.push(Tmth[j].feeStationName);
                }

                if (name[i] == Tmth[j].name) {
                    if (map_month_data.get(Tmth[j].feeStationName) != null) {
                        var map = map_month_data.get(Tmth[j].feeStationName)
                        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].feeStationName, map);
                    } else {
                        var map = new HashMap();
                        map.set(name[i], Tmth[j].all_check_score);
                        map_month_data.set(Tmth[j].feeStationName, 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].feeStationName) {
                            flag = true;
                            break;
                        }
                    }
                }
                if (!flag) {
                    array_all_deptname.push(Pmth[j].feeStationName);
                }
                if (name[i] == Pmth[j].name) {
                    if (map_per_data.get(Pmth[j].feeStationName) != null) {
                        var map = map_per_data.get(Pmth[j].feeStationName)
                        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].feeStationName, map);
                    } else {
                        var map = new HashMap();
                        map.set(name[i], Pmth[j].all_check_score);
                        map_per_data.set(Pmth[j].feeStationName, map);
                    }
                }
            }

            //     map_month_data.set(name[i], temp_map_m)
            //     map_pre_data.set(name[i], temp_map_p)
        }
    }

    /**
     * 除数为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 filter(num, num1, num2) {
        if (num1 == 0) {
            return num2;
        } else {
            return (num / num1).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'
            ],
            function(ec, theme) {
                // 基于准备好的dom，初始化echarts图表
                if (flag) {
                    year_assess = ec.init(document.getElementById('roadManager-year-assess'), theme);
                }
                points_assess = ec.init(document.getElementById('roadManager-points-assess'), theme);
                score_rank = ec.init(document.getElementById('tollStation-score-rank'));
                rank_pre = ec.init(document.getElementById('people-rank-pre'));
                rank_suf = ec.init(document.getElementById('people-rank-suf'), theme);
                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)
                rank_suf.on(ecConfig.EVENT.CLICK, station_c)
            }
        );
    }

    /**
     * 图一
     */
    function roadManager_year_assess() {

        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 roadManager_points_assess() {
        // 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_points,
        // 			itemStyle:{
        // 			normal:{
        // 				label:{
        // 					show: true,
        // 					formatter: '{b} :\n{c}人 ({d}%)'
        // 				},
        // 				labelLine :{show:true}
        // 				}
        // 			}
        // 		}
        // 	]
        // };

        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 tollStation_score_rank() {
        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: [{
                type: 'category',
                axisLabel: {
                    interval: 0 // 显示x轴所有信息，不隐藏部分
                },
                data: array_allStation
            }],
            yAxis: [{
                type: 'value',
                min: min_station,
                max: 1000
            }],
            series: [{

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

        return option;
    }

    /**
     * 图四
     */
    function people_rank_pre() {

        option = {
            color: ['#00ced1'], // 条形图颜色
            tooltip: {
                trigger: 'axis'
            },
            noDataLoadingOption: {
                text: '暂无数据',
                effect: 'bubble',
                effectOption: {
                    effect: {
                        n: 0 //气泡个数为0
                    }
                },
                textStyle: {
                    fontSize: 20,
                    fontFamily: 'cursive',
                    fontWeight: 'bold'
                }
            },
            grid: {
                width: "80%",
            },
            legend: {
                data: ['平均分']
            },
            calculable: true,
            xAxis: [{
                type: 'category',
                axisLabel: {
                    interval: 0 // 显示x轴所有信息，不隐藏部分
                },
                data: array_score_order
            }],
            yAxis: [{
                type: 'value',
                min: min_pre,
                max: 1000
            }],
            series: [{
                name: '平均分',
                type: 'bar',
                data: array_score_data,
                itemStyle: {
                    normal: {
                        label: {
                            show: true,
                            position: 'insideTop'
                        }
                    }
                },
                markPoint: {
                    data: [
                        { type: 'max', name: '最大值' },
                        { type: 'min', name: '最小值' }
                    ]
                },
                markLine: {
                    data: [
                        { type: 'average', name: '平均值' }
                    ]
                }
            }]
        };

        return option;
    }


    /**
     * 图五
     */
    function people_rank_suf() {

        option = {
            tooltip: {
                trigger: 'axis'
            },
            toolbox: {
                show: true,
                y: 'bottom',

            },
            calculable: true,
            grid: {
                width: "88%",
            },
            xAxis: [{
                type: 'category',
                axisLabel: {
                    interval: 0 // 显示x轴所有信息，不隐藏部分
                },
                splitLine: { show: false },
                data: array_score_last
            }],
            yAxis: [{
                type: 'value',
                min: min_suff,
                max: 1000
            }],
            series: [{
                    name: '平均分',
                    type: 'bar',
                    data: array_get_score_temp,
                    itemStyle: {
                        normal: {
                            color: '#00ced1',
                            label: {
                                show: true,
                                position: 'insideTop'
                            }
                        }
                    },
                    markPoint: {
                        data: [
                            { type: 'max', name: '最大值' },
                            { type: 'min', name: '最小值' }
                        ]
                    },
                },
                {
                    name: '搜索引擎细分',
                    type: 'pie',
                    tooltip: {
                        trigger: 'item',
                        formatter: '{b} : {c} ({d}%)'
                    },
                    center: ['80%', '20%'],
                    radius: [0, 40],
                    itemStyle: 　{
                        normal: {
                            label: {
                                show: true,
                                formatter: '{b} :\n{c}人 ({d}%)'
                            },
                            labelLine: {
                                length: 20
                            }
                        }
                    },
                    data: array_score_pie
                }
            ]
        };

        return option;
    }

    /**
     * 图六
     */
    function server_check_type() {
        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() {

        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: '本月',
                                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;
    }
});

function setVisit() {
    if (roleContains("ROAD_MANAGER") || roleContains("STATION")) {
        $(".div-roadManage select").attr("disabled", "disabled");
    }
}




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



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

        var pdata = {
            time: $("#month_date").val(),
            road_p: $(".div-roadManage select").val()
        }

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

        $.zui.store.set('store_param_' + current_url, pdata);
        isnew = false;
        changePage("/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(),
            road_p: $(".div-roadManage select").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("/view/statistics/toll_station_statistics.html");
    }
}

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


        var pdata = {
            time: $("#month_date").val(),
            road_p: $(".div-roadManage select").val()
        }
        $.zui.store.set('page_data_param_temp_time', $("#month_date").val());


        //获取站名+用户名
        var namelist = param.data.name.split("_")
        var userid = namelist[0];
        var deptid = namelist[1];

        $.zui.store.set('store_param_' + current_url, pdata);
        isnew = false;
        changePage("/view/statistics/personal_data_statistics.html?userid=" + userid + "&deptid=" + deptid + "&jump=1");
    }
}