var breakdownTrendGraphData=[];//区域运维考核统计
var deviceBreakdownRateGraph=[];//设备恢复率
var workOrderStateGraphData={};//工单处理状态
$(function(){
	getWorkOrderStateGraphData();
	getDeviceBreakdownRateGraphData(0);
	getBreakdownTrendGraphData(0);
//	loadBreakdownTrendGraph(0);
//	loadDeviceBreakdownRateGraph(0);
//	loadWorkOrderStateGraph();		 
});


//设备恢复率
function breakdownRate(i){
	$("#deviceBreakdownRateCondition li").removeClass("active");
	$("#deviceBreakdownRateCondition li").eq(i).addClass("active");
	getDeviceBreakdownRateGraphData(i);
//	loadDeviceBreakdownRateGraph(i);
}
//区域运维考核统计
function breakdownTrend(i){
	$("#breakdownTrendCondition2 li").removeClass("active");
	$("#breakdownTrendCondition2 li").eq(i).addClass("active");
//	loadBreakdownTrendGraph(i);
	getBreakdownTrendGraphData(i);
}
function loadBreakdownTrendGraph(data){
	 parent.EchartsBase.lineChart({
		    idObj:document.getElementById("breakdownTrendGraph"),
 			data:data
 	});
 }
/*function loadBreakdownTrendGraph(i){
	parent.EchartsBase.lineChart({
		idObj:document.getElementById("breakdownTrendGraph"),
		data:breakdownTrendGraphData[i]
	});
}
*/ /*function loadDeviceBreakdownRateGraph(i){
	 parent.EchartsBase.barChart({
		    idObj:document.getElementById("deviceBreakdownRateGraph"),
 			data:deviceBreakdownRateGraph[i]
 	});
 }*/
function loadDeviceBreakdownRateGraph(data){
	 parent.EchartsBase.barChart({
		    idObj:document.getElementById("deviceBreakdownRateGraph"),
			data:data
	});
}

/* function loadWorkOrderStateGraph(){
		 parent.EchartsBase.workOrderGraphChart({
			    idObj:document.getElementById("workOrderStateGraph"),
	 			data:workOrderStateGraphData
	 	});
	}*/
function loadWorkOrderStateGraph(data){
	parent.EchartsBase.workOrderGraphChart({
		idObj:document.getElementById("workOrderStateGraph"),
		data:data
	});
}

function getWorkOrderStateGraphData(){
	$.ajax({
		type : 'post',
		dataType : 'json',
		url : 'ywcountuserrepairjobAction!count_OrderHomepage.do',
//		async:false,
		success : function(res){
			if(res){
				var bh = res.bh;
				var wxwc = res.wxwc;				
				var gq = res.gq;
				var wxz = res.wxz;
				workOrderStateGraphData = {
						"title":"",
						seriesName:"工单处理状态",
						data:[
							      {name:"维修中",value:wxz,color:"blue"},
							      {name:"驳回",value:bh,color:"red"},
							      {name:"挂起",value:gq,color:"yellow"},
							      {name:"维修完成",value:wxwc,color:"green"}
						      ]	
				}
				loadWorkOrderStateGraph(workOrderStateGraphData);
			}
		}
	})
}


//设备恢复率
function getDeviceBreakdownRateGraphData(i){
	
	$.ajax({
		type : 'post',
		dataType : 'json',
		url : 'ywalarmcountAction!count_HomepageHfl.do',
//		async:false,
		data:{type:i},
		success : function(res){
			if(res){
				var zList = res.zList;
//				var yList = res.yList;
//				var nList = res.nList;
				
				var zdata={},zxAxis=[],zxdata=[];
				if(zList){
					zList.forEach(function(item,index){
						var zs = item.zcount==null?0:item.zcount;
						var hf = item.hfcount==null?0:item.hfcount;
						var hfl = 0;
						if(zs != 0){
							hfl = hf/zs;
						}else{
							hfl = 1;
						}
						if(hfl != 0){
							hfl = hfl*100;
							hfl = hfl.toFixed(0);
						}
						zxAxis[index] = item.xzmc;
						zxdata[index] = hfl;
					})
				}				
				zdata={"title":"", "xAxis":zxAxis, "legend":[{"name":"", "data":zxdata, "color":"#1fa2da"}]};
				loadDeviceBreakdownRateGraph(zdata);
				/*var ydata={},yxAxis=[],yxdata=[];
				if(yList){
					yList.forEach(function(item,index){
						var zs = item.zcount==null?0:item.zcount;
						var hf = item.hfcount==null?0:item.hfcount;
						var hfl = 0;
						if(zs != 0){
							hfl = hf/zs;
						}else{
							hfl = 1;
						}
						if(hfl != 0){
							hfl = hfl*100;
							hfl = hfl.toFixed(0);
						}
						yxAxis[index] = item.xzmc;
						yxdata[index] = hfl;
					})
				}				
				ydata={"title":"", "xAxis":yxAxis, "legend":[{"name":"", "data":yxdata, "color":"#1fa2da"}]};

				var ndata={},nxAxis=[],nxdata=[];
				if(nList){
					nList.forEach(function(item,index){
						var zs = item.zcount==null?0:item.zcount;
						var hf = item.hfcount==null?0:item.hfcount;
						var hfl = 0;
						if(zs != 0){
							hfl = hf/zs;
						}else{
							hfl = 1;
						}
						if(hfl != 0){
							hfl = hfl*100;
							hfl = hfl.toFixed(0);
						}
						nxAxis[index] = item.xzmc;
						nxdata[index] = hfl;
					})
				}			
				ndata={"title":"", "xAxis":nxAxis, "legend":[{"name":"", "data":nxdata, "color":"#1fa2da"}]};*/
				
				
				/*deviceBreakdownRateGraph[0]=zdata;
				deviceBreakdownRateGraph[1]=ydata;
				deviceBreakdownRateGraph[2]=ndata;*/
			}
			
		}
	})
}

function getBreakdownTrendGraphData(i){
	$.ajax({
		type : 'post',
		dataType : 'json',
		url : 'ywcountvideoappraiseAction!count_HomepateAreaExam.do',
//		async:false,
		data:{type:i},
		success : function(res){
			if(res && res.length>0){
				zList = res;
//				yList = res.yList;
//				nList = res.nList;
				var zdata={},zxAxis=[],zxData=[];				
				if(zList){
					zList.forEach(function(item,index){
						var xzmc = item.areaname;
						xzmc = xzmc==null ? "":xzmc;
						zxAxis[index]=xzmc;
						zxData[index]=item.score;
					})									
				}
				zdata={"title":"", "xAxis":zxAxis, "legend":[{"name":"", "data":zxData, "color":"#1fa2da"}]};
				loadBreakdownTrendGraph(zdata);
			}
		}	
	})
}
