//分析维度
var isAlarmType=true;
var xAxis={hours:[],day:[],month:[]};
$(function(){
	$("#datetimeStart").datetimebox("setValue",$.getTodayStart(0,"00:00:00"));
	$("#datetimeEnd").datetimebox("setValue",$.getTodayEnd("23:59:59"));
	initBtn();
	initAlarmType();
	initXAxis();
});

//初始化x轴
function initXAxis(){
	for(var i=0;i<24;i++){
		if(i<10){
			xAxis.hours[i]=0+i+"";
		}else{
			xAxis.hours[i]=i+"";
		}	
	}
	for(var j=1;j<32;j++){
		xAxis.day[j]=j+"";
	}
	for(var k=1;k<13;k++){
		xAxis.month[k]=k+"";
	}
}

//初始化按钮事件
function initBtn(){
	$("[name='countDate']").change(function(){
		var val=$(this).val();
		if(val==5){
			$("#controlDate").css("display","inline-block");
		}else{
			if(isAlarmType){
				initAlarmType();
			}else{
				initAlarmTrend();
			}
			$("#controlDate").css("display","none");
		}
		$("#countDate span").removeClass("btn-success")
		$(this).next().addClass("btn-success");
	});
	
	$("[name='countType']").change(function(){
		var val=$(this).val();
		$("#countType span").removeClass("btn-success")
		$(this).next().addClass("btn-success");
		if(val==2){
			isAlarmType=false;
			$("#countCycle").show();
			$("#alarmType").hide();
			$("#alarmTrend").show();
			initAlarmTrend();
		}else{
			isAlarmType=true;
			$("#countCycle").hide();
			$("#alarmTrend").hide();
			$("#alarmType").show();
			initAlarmType();
		}
	});
	
	$("[name='countCycle']").change(function(){
		$("#countCycle span").removeClass("btn-success")
		$(this).next().addClass("btn-success");
		if(isAlarmType){
			initAlarmType();
		}else{
			initAlarmTrend();
		}
	});
}

//初始化告警趋势
function initAlarmTrend(){
	var searchParams=getQueryParams();
	console.log("initAlarmTrend",searchParams);
	var data={"title":"本周运维告警趋势",xAxis: ["监控","NVR","服务器","应用系统"],"legend":[{"name":"Doset","data":[5, 20, 36, 50],"color":"green"},{"name":"Yeland","data":[51, 210, 36, 10],"color":"blue"},{"name":"Yeland1","data":[21,12,13,14],"color":"red"}]};
 	EchartsBase.lineChart(
 			{
 			id:"alarmTrend",
 			data:data
 	});
}

//初始化告警类型
function initAlarmType(){
	var searchParams=getQueryParams();
	console.log("initAlarmType",searchParams);
	var data={"title":"本周运维告警统计",xAxis: ["监控","NVR","服务器","应用系统"],"legend":[{"name":"Doset","data":[5, 20, 36, 50],"color":"#00accb"},{"name":"Yeland","data":[51, 210, 36, 10],"color":"#fa102a"}]}	;
	EchartsBase.barChart(
 			{
 			id:"alarmType",
 			data:data
 	});
}

//查询
function searchAlarm(){
	if(isAlarmType){
		initAlarmType();
	}else{
		initAlarmTrend();
	}
}

//查询条件
function getQueryParams(){
	var sParam = {};
	sParam.countDate = $('input:radio[name="countDate"]:checked').val();   //统计时间
	sParam.datetimeStart = $('#datetimeStart').datetimebox("getValue");			   // 开始时间
	sParam.datetimeEnd = $('#datetimeEnd').datetimebox("getValue");			   //结束时间
	sParam.countType = $('input:radio[name="countType"]:checked').val();       	//分析维度
	sParam.countCycle = $('input:radio[name="countCycle"]:checked').val();	 //趋势周期
	return sParam;
}