var Option = {};

Option.getLastEnterpriseOption = function (type,data) {
    var myEcharts = echarts.init(document.getElementById('e1'),"macarons");
    var title = new Array();
    var detail = new Array();
    var max = 200;
    for(var key in data.obj){
        title.push(data.obj[key].time);
        detail.push(data.obj[key].count);
        if(max<parseInt(data.obj[key].count)){
            max = data.obj[key].count;
        }
    }
    var colors = ['#5793f3', '#d14a61', '#675bba'];
    var option = {
        color: colors,
        tooltip: {
            trigger: 'axis',
            axisPointer: {type: 'cross'}
        },
        grid: {
            right: '20%'
        },
        toolbox: {
            feature: {
                dataView: {show: true, readOnly: false},
                restore: {show: true},
                saveAsImage: {show: true}
            }
        },
        legend: {
            show:false
        },
        xAxis: [
            {
                type: 'category',
                axisTick: {
                    alignWithLabel: true
                },
                data: title
            }
        ],
        yAxis: [
            {
                type: 'value',
                name: type==1?'注册量':"认定数",
                min: 0,
                max: max,
                position: 'left',
                axisLine: {
                    lineStyle: {
                        color: colors[0]
                    }
                },
                axisLabel: {
                    formatter: '{value} '
                }
            },
        ],
        series: [
            {
                name:'注册量',
                type:'bar',
                data:detail
            },
        ]
    };
    myEcharts.setOption(option);
}

Option.talentIdentifyProOption = function (type,data) {
    var myEcharts = echarts.init(document.getElementById('e2'),"macarons");
    myEcharts.clear();
    var titleName = "";
    var title = new Array();
    var detail = new Array();
    var type2Detail = new Array();
    var pro = new Array();
    for(var key in data.obj.res){
        title.push(key);
        detail.push({value: data.obj.res[key], name: key});
        type2Detail.push(data.obj.res[key]);
        pro.push((Math.round(data.obj.res[key] / data.obj.total * 10000) / 100.00)+"%");
    }
    if(type == 1 || type == 4){

        var option = {
            // backgroundColor:"#0B1837",
            color: ["#EAEA26", "#906BF9", "#FE5656", "#01E17E", "#3DD1F9", "#FFAD05",'#95e1d3'],
            grid: {
                left: -100,
                top: 50,
                bottom: 10,
                right: 10,
                containLabel: true
            },
            tooltip: {
                trigger: 'item',
                formatter: "{b} : {c} ({d}%)"
            },
            legend: {
                type: "scroll",
                orient: "vartical",
                // x: "right",
                top: "center",
                right: "15",
                // bottom: "0%",
                itemWidth: 16,
                itemHeight: 8,
                itemGap: 16,
                textStyle: {
                    color: '#000000',
                    fontSize: 12,
                    fontWeight: 0
                },
                data: title
            },
            polar: {},
            angleAxis: {
                interval: 1,
                type: 'category',
                data: [],
                z: 10,
                axisLine: {
                    show: false,
                    lineStyle: {
                        color: "#0B4A6B",
                        width: 1,
                        type: "solid"
                    },
                },
                axisLabel: {
                    interval: 0,
                    show: true,
                    color: "#0B4A6B",
                    margin: 8,
                    fontSize: 16
                },
            },
            radiusAxis: {
                min: 40,
                max: 120,
                interval: 20,
                axisLine: {
                    show: false,
                    lineStyle: {
                        color: "#0B3E5E",
                        width: 1,
                        type: "solid"
                    },
                },
                axisLabel: {
                    formatter: '{value} %',
                    show: false,
                    padding: [0, 0, 20, 0],
                    color: "#0B3E5E",
                    fontSize: 16
                },
                splitLine: {
                    lineStyle: {
                        color: "#0B3E5E",
                        width: 2,
                        type: "solid"
                    }
                }
            },
            calculable: true,
            series: [{
                type: 'pie',
                radius: ["5%", "10%"],
                hoverAnimation: false,
                labelLine: {
                    normal: {
                        show: false,
                        length: 30,
                        length2: 55
                    },
                    emphasis: {
                        show: false
                    }
                },
                data: [{
                    name: '',
                    value: 0,
                    itemStyle: {
                        normal: {
                            color: "#0B4A6B"
                        }
                    }
                }]
            }, {
                type: 'pie',
                radius: ["90%", "95%"],
                hoverAnimation: false,
                labelLine: {
                    normal: {
                        show: false,
                        length: 30,
                        length2: 55
                    },
                    emphasis: {
                        show: false
                    }
                },
                name: "",
                data: [{
                    name: '',
                    value: 0,
                    itemStyle: {
                        normal: {
                            color: "#0B4A6B"
                        }
                    }
                }]
            },{
                stack: 'a',
                type: 'pie',
                radius: ['20%', '80%'],
                roseType: 'area',
                zlevel:10,
                label: {
                    normal: {
                        show: true,
                        formatter: "{c}人",
                        textStyle: {
                            fontSize: 12,
                        },
                        position: 'outside'
                    },
                    emphasis: {
                        show: true
                    }
                },
                labelLine: {
                    normal: {
                        show: true,
                        length: 20,
                        length2: 55
                    },
                    emphasis: {
                        show: false
                    }
                },
                data: detail
            }, ]
        }

        // var option = {
        //     title: {
        //         text: type==1?"人才认定人才层次分布":"人才认定人才来源分布",
        //         // subtext: '纯属虚构',
        //         left: 'center'
        //     },
        //     tooltip: {
        //         trigger: 'item',
        //         formatter: '{a} <br/>{b} : {c} ({d}%)'
        //     },
        //     legend: {
        //         left: 'center',
        //         top: 'bottom',
        //         show:true,
        //         data: data
        //     },
        //     xAxis: {
        //         show:false
        //     },
        //     yAxis:{
        //         show:false
        //     },
        //     toolbox: {
        //         show: true,
        //         feature: {
        //             mark: {show: true},
        //             dataView: {show: true, readOnly: false},
        //             magicType: {
        //                 show: true,
        //                 type: ['pie', 'funnel']
        //             },
        //             restore: {show: true},
        //             saveAsImage: {show: true}
        //         }
        //     },
        //     series: [
        //         {
        //             name: titleName,
        //             type: 'pie',
        //             radius: [30, 110],
        //             center: ['50%', '50%'],
        //             roseType: 'area',
        //             data: detail
        //         }
        //     ]
        // };
        myEcharts.setOption(option);
    }
    if(type == 2){
        var colorList = ['#f36c6c', '#e6cf4e', '#20d180', '#0093ff','#ca8622', '#bda29a', '#a8d8ea', '#aa96da', '#fcbad3', '#ffffd2'];
        var option = {
            title: {
                text: '人才认定行业领域',
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                },
                formatter: "行业领域"+'<br/>{b} : {c} '
            },
            legend: {
                show: false
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: {
                type: 'value',
                axisLine: {
                    show: true
                },
                axisTick: {
                    show: true,
                    interval:0
                },
            },
            yAxis: {
                inverse: true,
                type: 'category',
                data: title,
                axisLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                axisTick: {
                    show: false,
                    interval: 0
                },
            },
            series: [
                {
                    type: 'bar',
                    data: type2Detail.map((item, i) => {
                        itemStyle = {
                            color: colorList[i]
                        }
                        return {
                            value: item,
                            itemStyle: itemStyle
                        };
                    }),
                    label: {
                        show: true,
                        position: 'right',
                        color: '#333333',
                        fontSize: 14,
                        offset: [10, 0]
                    }
                }
            ]
        };
        myEcharts.setOption(option);
    }if(type == 3){
        var colorList = ['#f36c6c', '#e6cf4e', '#20d180', '#0093ff','#ca8622', '#bda29a', '#a8d8ea', '#aa96da', '#fcbad3', '#ffffd2'];
        var option = {
            title: {
                text: '人才认定最高学历分布',
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                },
                formatter: "最高学历"+'<br/>{b} : {c} '
            },
            legend: {
                show: false
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: {
                type: 'value',
                axisLine: {
                    show: true
                },
                axisTick: {
                    show: true,
                    interval:0
                },
            },
            yAxis: {
                inverse: true,
                type: 'category',
                data: title,
                axisLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                axisTick: {
                    show: false,
                    interval: 0
                },
            },
            series: [
                {
                    type: 'bar',
                    data: type2Detail.map((item, i) => {
                        itemStyle = {
                            color: colorList[i]
                        }
                        return {
                            value: item,
                            itemStyle: itemStyle
                        };
                    }),
                    label: {
                        show: true,
                        position: 'right',
                        color: '#333333',
                        fontSize: 14,
                        offset: [10, 0]
                    }
                }
            ]
        };
        myEcharts.setOption(option);
    }
}

Option.getCountByStreetOption = function (type,data) {
    var res = data.obj.data;
    var total = data.obj.total;
    var myEcharts = echarts.init(document.getElementById('e3'),"macarons");
    var years = new Array();
    var jdData = new Array();
    var resData = new Array();
    for(var key in res){
        years.push(key);
        var tmpData = new Array();
        var resTempData = new Array();
        for(var street in res[key]){
            tmpData.push(street);
            resTempData.push(res[key][street]);
        }
        jdData.push(tmpData);
        resData.push(resTempData);
    }
    var option = {
        baseOption: {
            // backgroundColor: '#2c343c', //背景颜色
            timeline: {
                data: years,
                axisType: 'category',
                autoPlay: true,
                playInterval: 3000, //播放速度
                left: '5%',
                right: '5%',
                bottom: '0%',
                width: '90%',
                //  height: null,
                label: {
                    normal: {
                        textStyle: {
                            color: 'red',
                        }
                    },
                    emphasis: {
                        textStyle: {
                            color: 'red'
                        }
                    }
                },
                symbolSize: 10,
                lineStyle: {
                    color: '#red'
                },
                checkpointStyle: {
                    borderColor: '#red',
                    borderWidth: 2
                },
                controlStyle: {
                    showNextBtn: true,
                    showPrevBtn: true,
                    normal: {
                        color: '#ff8800',
                        borderColor: '#ff8800'
                    },
                    emphasis: {
                        color: 'red',
                        borderColor: 'red'
                    }
                },

            },
            title: {
                text: '',
                right: '2%',
                bottom: '8%',
                textStyle: {
                    fontSize: 50,
                    color: 'black' //标题字体颜色
                }
            },
            tooltip: {
                'trigger': 'axis'
            },
            calculable: true,
            grid: {
                left: '8%',
                right: '2%',
                bottom: '6%',
                top: '0%',
                containLabel: true
            },
            label: {
                normal: {
                    textStyle: {
                        color: 'red'
                    }
                }
            },
            yAxis: [{

                nameGap: 50,
                offset: '37',
                'type': 'category',
                interval: 50,
                //inverse: ture,//图表倒叙或者正序排版
                data: '',
                nameTextStyle: {
                    color: 'red'
                },
                axisLabel: {
                    //rotate:45,
                    show: false,
                    textStyle: {
                        fontSize: 32,
                        color: function(params, Index) { // 标签国家字体颜色
                            //color:function(d){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);//随机生成颜色
                            var colorarrays = ['#6bc0fb', '#7fec9d', '#fedd8b', '#ffa597', '#84e4dd', '#749f83',
                                '#ca8622', '#bda29a', '#a8d8ea', '#aa96da', '#fcbad3', '#ffffd2',
                                '#f38181', '#fce38a', '#eaffd0', '#95e1d3', '#e3fdfd', '#749f83', '#ca8622'
                            ];
                            //console.log("111", Index, colorarrays[Index],params); //打印序列
                            return colorarrays[jdData[0].indexOf(params)];
                        },
                    }, //rotate:45,
                    interval: 50
                },
                axisLine: {
                    lineStyle: {
                        color: 'balck' //Y轴颜色
                    },
                },
                splitLine: {
                    show: false,
                    lineStyle: {
                        color: 'balck'
                    }
                },
            }],
            xAxis: [{
                'type': 'value',
                'name': '',
                splitNumber: 8, //轴线个数
                nameTextStyle: {
                    color: 'balck'
                },
                axisLine: {
                    lineStyle: {
                        color: '#ffa597' //X轴颜色
                    }
                },
                axisLabel: {
                    formatter: '{value} '
                },
                splitLine: {
                    show: true,
                    lineStyle: {
                        color: '#fedd8b'
                    }
                },
            }],
            series: [{
                'name': '',
                'type': 'bar',
                markLine: {
                    label: {
                        normal: {
                            show: false
                        }
                    },
                    lineStyle: {
                        normal: {
                            color: 'red',
                            width: 3
                        }
                    },
                },
                label: {
                    normal: {
                        show: true,
                        position: 'right', //数值显示在右侧
                        formatter: '{c}'
                    }
                },
                itemStyle: {
                    normal: {
                        color: function(params) {
                            // build a color map as your need.
                            //color:function(d){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);//随机生成颜色
                            var colorList = ['#6bc0fb', '#7fec9d', '#fedd8b', '#ffa597', '#84e4dd', '#749f83',
                                '#ca8622', '#bda29a', '#a8d8ea', '#aa96da', '#fcbad3', '#ffffd2',
                                '#f38181', '#fce38a', '#eaffd0', '#95e1d3', '#e3fdfd', '#749f83', '#ca8622'
                            ];
                            // return colorList[params.dataIndex]
                            return colorList[jdData[0].indexOf(params.name)];
                        },

                    }
                },
            },
                {
                    'name': '',
                    'type': 'bar',
                    markLine: {
                        label: {
                            normal: {
                                show: false
                            }
                        },
                        lineStyle: {
                            normal: {
                                color: 'red',
                                width: 3
                            }
                        },
                    },
                    barWidth: '50%',
                    barGap: '-100%',
                    label: {
                        normal: {
                            show: true,
                            position: 'left', //数值显示在右侧
                            formatter: function(p) {
                                return p.name;
                            }
                        }
                    },
                    itemStyle: {
                        normal: {
                            color: function(params) {
                                // build a color map as your need.
                                //color:function(d){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);//随机生成颜色
                                var colorList = ['#6bc0fb', '#7fec9d', '#fedd8b', '#ffa597', '#84e4dd', '#749f83',
                                    '#ca8622', '#bda29a', '#a8d8ea', '#aa96da', '#fcbad3', '#ffffd2',
                                    '#f38181', '#fce38a', '#eaffd0', '#95e1d3', '#e3fdfd', '#749f83', '#ca8622'
                                ];
                                // return colorList[params.dataIndex]
                                // console.log("111", params.name); //打印序列
                                return colorList[jdData[0].indexOf(params.name)];
                            },

                        }
                    },
                }
            ],
            animationEasingUpdate: 'quinticInOut',
            animationDurationUpdate: 1500, //动画效果
        },
        options: []
    };
    for (var n = 0; n < years.length; n++) {
        var res = [];
        for (j = 0; j < resData[n].length; j++) {
            res.push({
                name: jdData[n][j],
                value: resData[n][j]
            });
        }
        res.sort(function(a, b) {
            return b.value - a.value;
        }).slice(0, 6);
        res.sort(function(a, b) {
            return a.value - b.value;
        });
        var res1 = [];
        var res2 = [];
        var res3 = [];
        //console.log(res);
        for (t = 0; t < res.length; t++) {
            res1[t] = res[t].name;
            res2[t] = res[t].value;
            res3[t]  = (res[t].value/total[years[n]]*100).toFixed(2);
        }
        option.options.push({
            title: {
                text: years[n] + '年'
            },
            yAxis: {
                data: res1,
            },
            series: [{
                data: res2
            }, {
                data: res2
            }]
        });
    }
    myEcharts.setOption(option);
}


Option.talentIdentifyChangeOption = function (data) {
    var myEcharts = echarts.init(document.getElementById('e4'),"macarons");
    var xData = new Array();
    var totalData = new Array();
    var boyData = new Array();
    var girlData = new Array();
    for(var key in data.obj){
        xData.push(key);
        totalData.push(data.obj[key].total);
        boyData.push(data.obj[key].boy);
        girlData.push(data.obj[key].girl);
    }
    var option = {
        // backgroundColor: "#344b58",
        "title": {
            "text": "近几年人才认定数走势图",
            x: "4%",
            textStyle: {
                color: '#fff',
                fontSize: '22'
            },
            subtextStyle: {
                color: '#90979c',
                fontSize: '16',
            },
        },
        "tooltip": {
            "trigger": "axis",
            "axisPointer": {
                "type": "shadow",
                textStyle: {
                    color: "#fff"
                }

            },
        },
        "grid": {
            "borderWidth": 0,
            "top": 110,
            "bottom": 95,
            textStyle: {
                color: "#fff"
            }
        },
        "legend": {
            x: '4%',
            top: '8%',
            textStyle: {
                color: '#90979c',
            },
            "data": ['女', '男', '平均']
        },
        "calculable": true,
        "xAxis": [{
            "type": "category",
            "axisLine": {
                lineStyle: {
                    color: '#90979c'
                }
            },
            "splitLine": {
                "show": false
            },
            "axisTick": {
                "show": false
            },
            "splitArea": {
                "show": false
            },
            "axisLabel": {
                "interval": 0,

            },
            "data": xData,
        }],
        "yAxis": [{
            "type": "value",
            "splitLine": {
                "show": false
            },
            "axisLine": {
                lineStyle: {
                    color: '#90979c'
                }
            },
            "axisTick": {
                "show": false
            },
            "axisLabel": {
                "interval": 0,

            },
            "splitArea": {
                "show": false
            },

        }],
        "dataZoom": [{
            "show": true,
            "height": 30,
            "xAxisIndex": [
                0
            ],
            bottom: 30,
            "start": 10,
            "end": 80,
            handleIcon: 'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
            handleSize: '110%',
            handleStyle:{
                color:"#d3dee5",

            },
            textStyle:{
                color:"#fff"},
            borderColor:"#90979c"
        }, {
            "type": "inside",
            "show": true,
            "height": 15,
            "start": 1,
            "end": 35
        }],
        "series": [{
            "name": "女",
            "type": "bar",
            "stack": "总量",
            "barMaxWidth": 35,
            "barGap": "10%",
            "itemStyle": {
                "normal": {
                    "color": "rgba(255,144,128,1)",
                    "label": {
                        "show": true,
                        "textStyle": {
                            "color": "#fff"
                        },
                        "position": "inside",
                        formatter: function(p) {
                            return p.value > 0 ? (p.value) : '';
                        }
                    }
                }
            },
            "data": girlData,
        },

            {
                "name": "男",
                "type": "bar",
                "stack": "总量",
                "itemStyle": {
                    "normal": {
                        "color": "rgba(0,191,183,1)",
                        "barBorderRadius": 0,
                        "label": {
                            "show": true,
                            "position": "inside",
                            formatter: function(p) {
                                return p.value > 0 ? (p.value) : '';
                            }
                        }
                    }
                },
                "data":boyData
            }, {
                "name": "总数",
                "type": "line",
                symbolSize:10,
                symbol:'circle',
                "itemStyle": {
                    "normal": {
                        "color": "rgba(252,230,48,1)",
                        "barBorderRadius": 0,
                        "label": {
                            "show": true,
                            "position": "top",
                            formatter: function(p) {
                                return p.value > 0 ? (p.value) : '';
                            }
                        }
                    }
                },
                "data": totalData
            },
        ]
    }
    myEcharts.setOption(option);
}