/**
 * 呼叫数据图形分析
 * */

var token = $.cookie("token");
var tabIndex = 0;
var endyear = helper.DateFormat.getNowYear(); //初始化当前年份	
var beginyear = endyear - 1;
var hjCompaer; //图形
var legendCon; //图形legend

$(document).ready(function() {
	$('#chooseTime').val(beginyear + ' ~ ' + endyear);
	layui.use('laydate', function() {
		var laydate = layui.laydate;
		laydate.render({
			elem: '#startTime',
			range: '~',
			//value: stime + ' ~ ' + endtime,
			theme: '#1ab394',
			calendar: 'true'
		});
	});

	//tab切换
	$('.hu-tab li').click(function() {
		$(this).addClass('active')
			.siblings().removeClass('active');

		tabIndex = $(this).index();
		$('.hu-content >div').eq(tabIndex).show()
			.siblings().hide();
		// loadDatas();
	});
	//初始化图形
	//加载数据
	// loadDatas();
	//搜索事件
	$(".sear").click(function() {
		// loadDatas();
		getDataList();
	});

	//导出
	$('.export').click(function() {
		dcexcel(this);
	})
});


	$("#save_ssss").click(function  () {
	    partpaat()
	})
	var bigdataList = null;

	partpaat();

	function partpaat() {
		var myCha = echarts.init(document.getElementById('Bitiur'));
		var myChart = echarts.init(document.getElementById('hjCompaer'));
		
		$.ajax({
			type: "get",
			url: huayi.config.callcenter_url + "WOReport/GetZLReport",
			async: true,
			dataType: "json",
			data: {
				stime:$('#time3').val() && $('#time3').val().split(' ~ ')[0], 
				endtime:$('#time3').val() && $('#time3').val().split(' ~ ')[1],//开始时间
			},
			success: function(data) {
				if (data.state.toLowerCase() == "success") {
					//bigdataList = data.rows;
					var con = data.data;
           
					myChart.setOption({
						color: ['#95FFD7'],
						// title: {
						// 	text: '反馈类型统计',
						// 	x: 'center',
						// 	textStyle: {
						// 		"color": "#FFFFFF"
						// 	}
						// },
						tooltip: {},
						// legend: {
						//      // data: ['销量']
						// },
						xAxis: {
							name: '工单子类',
							data:[
							 con[0].typename,
							 con[1].typename,
							 con[2].typename,
							 con[3].typename,
							 con[4].typename,
							 con[5].typename,
							 con[6].typename,
							 con[7].typename,
							 con[8].typename,
							 con[9].typename,
							 con[10].typename,
							 con[11].typename,
							 con[12].typename,
							 con[13].typename,
							 con[14].typename,
							 con[15].typename,
							 con[16].typename,
							 con[17].typename,
							],
							axisLine: { //这是x轴文字颜色
								lineStyle: {
									color: "#333333",
								}
							}
						},
						yAxis: {
							name: '工单数量',
							splitLine:{
						　　　　show:false
						　　},
							axisLine: { //这是x轴文字颜色
								lineStyle: {
									color: "#333333",
								}
							}
						},
						series: [{
							name: '工单子类统计表',
							type: 'bar',
							x: 'center',
							// barGap:'2%', //两个柱子距离
							barWidth: 20,
							data: 
							
							[
								con[0].count,
								con[1].count,
								con[2].count,
								con[3].count,
								con[4].count,
								con[5].count,
								con[6].count,
								con[7].count,
								con[8].count,
								con[9].count,
								con[10].count,
								con[11].count,
								con[12].count,
								con[13].count,
								con[14].count,
								con[15].count,
								con[16].count,
								con[17].count,
						    
							]
						}]
					});
					myCha.setOption({
						title: {
							// text: '某站点用户访问来源',
							// subtext: '纯属虚构',
							// x:'center'
						},
						tooltip: {
							trigger: 'item',
							formatter: "{a} <br/>{b} : {c} ({d}%)"
						},
						series: [{
							name: '工单子类统计表',
							type: 'pie',
							radius: '55%',
							center: ['50%', '60%'],
							data: [
								{name:con[0].typename,value:con[0].count,},
								{name:con[1].typename,value:con[1].count,},
								{name:con[2].typename,value:con[2].count,},
								{name:con[3].typename,value:con[3].count,},
								{name:con[4].typename,value:con[4].count,},
								{name:con[5].typename,value:con[5].count,},
								{name:con[6].typename,value:con[6].count,},
								{name:con[7].typename,value:con[7].count,},
								{name:con[8].typename,value:con[8].count,},
								{name:con[9].typename,value:con[9].count,},
								{name:con[10].typename,value:con[10].count,},
								{name:con[11].typename,value:con[11].count,},
								{name:con[12].typename,value:con[12].count,},
								{name:con[13].typename,value:con[13].count,},
								{name:con[14].typename,value:con[14].count,},
								{name:con[15].typename,value:con[15].count,},
								{name:con[16].typename,value:con[16].count,},
								{name:con[17].typename,value:con[17].count,}
							],
							// label: {
							//   normal: {
							// 	position: 'inner',
							// 	show : true
							//   }
							// },
							itemStyle: {
								emphasis: {
									shadowBlur: 10,
									shadowOffsetX: 0,
									shadowColor: 'rgba(0, 0, 0, 0.5)'
								},
								normal: {
									color: function(params) {
										//自定义颜色
										var colorList = [
											'#1890FF', '#2EC25B', '#FACC14', '#223273', '#8543E0', '#13C2C2','#3436C7','#F04864','#D141D9',
											'#F26EA2', '#95FFD7', '#FBBE5B', '#FF9D9B', '#AAF58D', '#F95A83','#6C77DA','#F76A53','#88EBC4',
											'#D1F0E0',
										];
										return colorList[params.dataIndex]
									}
								}
							}
						}]
					});
					
				
			
					}
					
				},
				})
		}	




//导出功能
function dcexcel(obj) {
	var url = huayi.config.callcenter_url + "YearContrast/ExptList?token=" + token;
	url += "&beginyear=" + ($('#chooseTime').val() && $('#chooseTime').val().split(' ~ ')[0]) + "&endyear=" + ($('#chooseTime').val() && $('#chooseTime').val().split(' ~ ')[1]);
	obj.href = url;
}

// function loadDatas() {
// 	if(tabIndex == 0) {
// 		getDataList(); //加载图形
// 	} else if(tabIndex == 1) {
// 		getTableDataList(); //加载表格
// 	}
// }