var proName = window.location.pathname.split("/")[1];
var sysUrl = "http://"+window.location.host+"/"+proName;
$(function() {
	// 基于准备好的dom，初始化echarts实例
	videoOnlineRate();
	videoIntactRate();
	recordIntactRate();
	
	machineOnlineRate();
	machineIntactRate();
	
//	var spzxl = echarts.init(document.getElementById('spzxl'));
//	var spwhl = echarts.init(document.getElementById('spwhl'));
//	var lxwhl = echarts.init(document.getElementById('lxwhl'));
//	var fwqzxl = echarts.init(document.getElementById('fwqzxl'));
//	var fwqwhl = echarts.init(document.getElementById('fwqwhl'));


	// 使用刚指定的配置项和数据显示图表。
//	spzxl.setOption(option);
//	spwhl.setOption(option);
//	lxwhl.setOption(option);
//	fwqzxl.setOption(option);
//	fwqwhl.setOption(option);
});
// 指定图表的配置项和数据
var option = {
	tooltip : {
		trigger : 'item',
		formatter : "{a} <br/>{b}: {c} ({d}%)"
	},
	legend : {
		orient : 'vertical',
		x : 'left',
		data : []
	},
	series : [ {
		name : '访问来源',
		type : 'pie',
		radius : [ '50%', '70%' ],
		center : [ '50%', '40%' ],
		color : [ '#27a72d', '#ff7a05' ],
		avoidLabelOverlap : false,
		label : {
			normal : {
				show : false,
				position : 'center'
			},
			emphasis : {
				show : true,
				textStyle : {
					fontSize : '20',
					fontWeight : 'bold'
				}
			}
		},
		labelLine : {
			normal : {
				show : false
			}
		},
		data : [ {
			value : 335,
			name : '在线'
		}, {
			value : 310,
			name : '不在线'
		} ]
	} ]
};
//在线率
function videoOnlineRate(){
	$.ajax({
		url:"ywvideocurrentstateAction!statisticsVideoOnlineRate.do",
		type:"post",
		dataType:"JSON",
		data:{},
		success:function(res){
			if(res){
				console.log(res);
				$("#videoOnline").text(res.onlineNum);
				$("#videoUnOnline").text(res.unonlineNum);
				var data = [ {
					value : res.onlineNum,
					name : '在线'
				}, {
					value : res.unonlineNum,
					name : '不在线'
				} ];
				EchartsBase.circularGraphChart(
			 			{
			 			id:"spzxl",
			 			data:data
			 	});
			}
		},
		error:function(res){
			
		}
	})
}
//视频完好率
function videoIntactRate(){
	$.ajax({
		url:"ywvideocurrentstateAction!statisticsVideoIntactRate.do",
		type:"post",
		dataType:"JSON",
		data:{},
		success:function(res){
			if(res){
				console.log(res);
				$("#videoIntact").text(res.intactNum);
				$("#videoUnIntact").text(res.unIntactNum);
				var data = [ {
					value : res.intactNum,
					name : '在线'
				}, {
					value : res.unIntactNum,
					name : '不在线'
				} ];
				EchartsBase.circularGraphChart(
						{
							id:"spwhl",
							data:data
						});
			}
		},
		error:function(res){
			
		}
	})
}
//录像完好率
function recordIntactRate(){
	$.ajax({
		url:"ywvideocurrentstateAction!statisticsRecordIntactRate.do",
		type:"post",
		dataType:"JSON",
		data:{},
		success:function(res){
			if(res){
				console.log(res);
				$("#recordIntact").text(res.intactNum);
				$("#recordUnIntact").text(res.unIntactNum);
				var data = [ {
					value : res.intactNum,
					name : '在线'
				}, {
					value : res.unIntactNum,
					name : '不在线'
				} ];
				EchartsBase.circularGraphChart(
						{
							id:"lxwhl",
							data:data
						});
			}
		},
		error:function(res){
			
		}
	})
}
//服务器在线率
function machineOnlineRate(){
	$.ajax({
		url:"ywmachinecurrentstateAction!statisticsMachineOnlineRate.do",
		type:"post",
		dataType:"JSON",
		data:{},
		success:function(res){
			if(res){
				console.log(res);
				$("#machineOnline").text(res.onlineNum);
				$("#machineUnOnline").text(res.unOnlineNum);
				var data = [ {
					value : res.onlineNum,
					name : '在线'
				}, {
					value : res.unOnlineNum,
					name : '不在线'
				} ];
				EchartsBase.circularGraphChart(
						{
							id:"fwqzxl",
							data:data
						});
			}
		},
		error:function(res){
			
		}
	})
}
//服务器完好率
function machineIntactRate(){
	$.ajax({
		url:"ywmachinecurrentstateAction!statisticsMachineIntactRate.do",
		type:"post",
		dataType:"JSON",
		data:{},
		success:function(res){
			if(res){
				console.log(res);
				$("#machineIntact").text(res.intactNum);
				$("#machineUnIntact").text(res.unIntactNum);
				var data = [ {
					value : res.intactNum,
					name : '在线'
				}, {
					value : res.unIntactNum,
					name : '不在线'
				} ];
				EchartsBase.circularGraphChart(
						{
							id:"fwqwhl",
							data:data
						});
			}
		},
		error:function(res){
			
		}
	})
}
function showVideoDetail(deviceType,type){
	windowid = top.$.createWin({
		 title	: 	'详情',
		 width  :  '720',
		 height :  '400',
		 data:{deviceType:deviceType,type:type},
		 url	:  sysUrl+"/yw/common/showVideoDetail.jsp",
		 
	 });
}
function showMachineDetail(deviceType,type){
	windowid = top.$.createWin({
		title	: 	'详情',
		width  :  '720',
		height :  '400',
		data:{deviceType:deviceType,type:type},
		url	:  sysUrl+"/yw/common/showMachineDetail.jsp",
		
	});
}