var breakdownRateGraphData=[];//监控完好率
var breakdownTypeGraphData=[];//监控故障类型
$(function(){
	getFaultCount();
	getData();
	loadBreakdownRateGraph(0);
	loadBreakdownTypeGraph();
});

//监控完好率选项卡切换
function JkwhlSwitch(i){
	$(".breakdownRateBox li span").removeClass("active");
	$(".breakdownRateBox li").eq(i).find("span").addClass("active");
	loadBreakdownRateGraph(i);
}

function loadBreakdownRateGraph(i){
	 parent.EchartsBase.circularGraphChart({
	    idObj:document.getElementById("breakdownRateGraph"),
		data:breakdownRateGraphData[i]
 	});
}

function loadBreakdownTypeGraph(){
	 parent.EchartsBase.pieChart({
	    idObj:document.getElementById("breakdownTypeGraph"),
		data:breakdownTypeGraphData
 	});
}

function getData(){
	//监控完好率
	$.ajax({
		type : 'post',
		dateType : 'json',
		url:"ywvideocurrentstateAction!count_HomepageJkwhl.do",
		async:false,
		success : function(res){
			if(res){
				/*
				var zxs = res.onlineNum;				// 在线
				var lxs = res.unonlineNum;				// 离线
				var zcs = res.intactNum;				// 正常数
				var ycs = res.unIntactNum;				// 异常数
				var lxwhs = res.recordIntactNum;		// 录像完好数
				var lxycs = res.unrecordIntactNum;		// 录像异常数
				*/		
				var zxs = res.onlinenum==null?0:res.onlinenum;						// 在线
				var lxs = res.unonlinenum==null?0:res.unonlinenum;					// 离线
				var zcs = res.intactnum==null?0:res.intactnum;						// 正常数
				var ycs = res.unintactnum==null?0:res.unintactnum;					// 异常数
				var lxwhs = res.recordintactnum==null?0:res.recordintactnum;		// 录像完好数
				var lxycs = res.unrecordintactnum==null?0:res.unrecordintactnum;	// 录像异常数
				
				var zxl = 0;
				var zxzs = parseInt(zxs)+parseInt(lxs);
				if(zxzs !=0 ){
					zxl = parseInt(zxs)/zxzs;
				}
				if(zxl != 0){
					zxl = zxl*100; 
	        		zxl = zxl.toFixed(2)+"%";
				}
				$('#jkzxl').html(zxl);
				 
				var zcl = 0;
				var zzcs = parseInt(zcs)+parseInt(ycs);
				if(zzcs !=0 ){
					zcl = parseInt(zcs)/zzcs;
				}
				if(zcl != 0){
					zcl = zcl*100; 
					zcl = zcl.toFixed(2)+"%";
				}
				$('#jkwhl').html(zcl);
				
				var whl = 0;
				var zwhs = parseInt(lxwhs)+parseInt(lxycs);
				if(zzcs !=0 ){
					whl = parseInt(lxwhs)/zwhs;
				}
				if(whl != 0){
					whl = whl*100; 
					whl = whl.toFixed(2)+"%";
				}
				$('#lxwhl').html(whl);	
					
				breakdownRateGraphData=[
						{
						   "title":"",
							seriesName:"故障检测",
							 data:[
							      {name:"监控完好率",value:zcs,color:"#1e9dd2"},
							      {name:"监控故障率",value:ycs,color:"#d5001e"}
							      ]
						},
						{
						   "title":"",
							seriesName:"故障检测",
							 data:[
							      {name:"监控在线率",value:zxs,color:"#1e9dd2"},
							      {name:"监控离线率",value:lxs,color:"#d5001e"}
							      ]
					   },
					   {
						   "title":"",
							seriesName:"故障检测",
							 data:[
							      {name:"录像完好率",value:lxwhs,color:"#1e9dd2"},
							      {name:"录像故障率",value:lxycs,color:"#d5001e"}
							      ]
					   }
				];
			}
		}
	})
	
	
	// 监控故障类型
	$.ajax({
		type : 'post',
		dateType : 'json',
		url:"ywvideocurrentstateAction!count_HomepageFalultType.do",
		async:false,
		success : function(res){
			if(res){
				var sbbzx = res.sbbzx;
				var wlyc = res.wlyc;
				var czyc = res.czyc;
				var zlzdyc = res.zlzdyc;
				var lxyc = res.lxyc;
				
				breakdownTypeGraphData={
						"title":"",
						seriesName:"故障类型",
						data:[{name:"设备不在线",   value:sbbzx, color:"#e71d19"},
							 /* {name:"网络异常",    value:wlyc,   color:"#f5a518"},*/
							  {name:"抽帧异常",    value:czyc,   color:"#754599"},
							  {name:"质量诊断异常", value:zlzdyc,  color:"#5fb631"},
							  {name:"录像异常",    value:lxyc,    color:"#28b5ea"}
							 ]
				}
			}
		}
	})
}

function getFaultCount(){
	$.ajax({
		type : 'post',
		dataType : 'json',
		url : "ywalarmeventinfoAction!count_HomepageFaultCount.do",
		data:{page:1,rows:6},
		success : function(res){
			var htmlTr = "";
			// 只显示6条
			if(res){
				var len = res.length;
				for(var i=0; i < len; i++){
					item = res[i];
					//var cjmc = item.cjmc==null ? "" : item.cjmc;    // 设备厂家
					var sbmc = item.sbmc==null ? "" : item.sbmc;
					htmlTr +="<tr style='cursor:pointer;'>" +
						   		"<td><div>"+(i+1)+"</div></td>" +
						   		"<td title='"+ (sbmc) +"'  class='easyui-tooltip'><div style='    width: 320px;text-overflow: ellipsis;overflow: hidden; white-space: nowrap;'>"+sbmc+"</div></td>" +
						   		//"<td>"+cjmc+"</td>" +
						   		"<td>"+item.gjcs+"</td>" +
						   	"</tr>"
				    if(i==5){
				    	break;
				    }
				}
			}
			$('#jkgzcs').append(htmlTr);
		}
	})
}
