var winId	= $.getUrlParam("winId");
var planRecord = top.$("#"+winId).panel("options").data;
var planExecRecord;
var planDeviceRecord;
$(function(){
	//planRecord处理优化
	//可以根据ID加载planRecord
	initDefault();	
	//initPushLet();
});
/*
function eventTabChange(type){
	//console.log("=type="+type);
	if(type=="eventDiv"){
		$("#eventDiv").css("display","block");
		$("#planDiv").css("display","none");
	}
	if(type=="planDiv"){
		$("#eventDiv").css("display","none");
		$("#planDiv").css("display","block");
	}
}
*/
function initDefault(){
	if(planRecord){
		//获取图片路径
		var imgPath = planRecord.eventSmallUrl; 
		var sz_imgPath=new Array(); 
		var firstImg = '';
		var allImg = '';
		if(imgPath != null){
			sz_imgPath = imgPath.split('$');
			firstImg = sz_imgPath[0];
			//循环显示小图
			for(var k=0;k<sz_imgPath.length;k++){
				allImg+='<img src="'+getPicProxyUrl()+(sz_imgPath[k])+'" alt=""  width="100" height="80" onerror="$.loadErrorPic(this);">';
			}
		}
		$("#eventDiv").find('div.pc-img-topimg img').eq(0).attr('src',getPicProxyUrl()+(firstImg));
		$("#eventDiv").find('div.pc-img-btm').html(allImg);
		//事件详细信息
		$('#tdmc').append(planRecord.tdmc);
		$('#occurTime').append(planRecord.occurTime);
		$('#eventName').append(planRecord.eventName);
		$('#alarmLevelName').append(planRecord.alarmLevelName);
		$('#roadName').append(planRecord.roadName);
		$('#tunnelName').append(planRecord.tunnelName);
		$('#startPile').append(planRecord.startPile);
		$('#accidentName').append(planRecord.accidentName);
		if(planRecord.accidentName=="已处理"){
			//$('#showYaxx').css('display','block');
			//unionPlan();
		}
		/*
		if(records.accidentName != '未处理'){
			$("#eventPhoto").find('div #btn_qrbj').hide();
			$("#eventPhoto").find('div #btn_hlbj').hide();
		}else{
			$("#eventPhoto").find('div #btn_qrbj').show();
			$("#eventPhoto").find('div #btn_hlbj').show();
		}
		*/
	}
}
//图片代理
function getPicProxyUrl(){
	var proName = top.window.location.pathname.split("/")[1];
	var sysUrl = "http://"+window.location.host+"/"+proName;
	var picProxyUrl = sysUrl+"/sourceProxy?fileType=picUrlProxy&picUrl=";
	return  picProxyUrl;
}
//忽略报警
function alarmCheckFalse(){
	var params = {};
	params.accidentState = 3;
	params.accidentId = planRecord.accidentId;
	$.ajax({
		type: "post",
		url: "trafficaccidentinfoAction!update_Trafficaccidentinfo.do",
		dataType: "json",
		data: params,
	}).done(function(res) {
		//console.log(res);
		top.$.showMsg("状态已变更为【忽略报警】");
		refshParentQuery('3');
	});
}
//确认报警
function alarmCheckTrue(){
	var params = {};
	params.accidentState = 4;
	params.accidentId = planRecord.accidentId;
	$.ajax({
		type: "post",
		url: "trafficaccidentinfoAction!update_Trafficaccidentinfo.do",
		dataType: "json",
		data: params,
	}).done(function(res) {
		//console.log(res);
		top.$.showMsg("状态已变更为【 确认报警】");
		refshParentQuery('4');
		unionPlan();
	});
}
function unionPlan(){
	var url = top.sysUrl+"/szmap/business/nplan/planExec.jsp";
 	windowid = top.$.createWin({
		 title	: 	'交通事件预案处理',
		 width  :  '1100',
		 height :  '500',
		 data   : 	planRecord,
		 url	:  url
	 });
}
//刷新父窗口的处理信息
function refshParentQuery(){
	
}
function changeExecModel(data){
	if(data.execModel=="0"){
		data.execModelName = "自";
	}
	if(data.execModel=="1"){
		data.execModelName = "手";
	}
	if(data.execModel=="2"){
		data.execModelName = "延";
	}
	return data;
}
//启动
function planStart(){
	//运行
	$("#planState").val("1");
}
//暂停
function planPause(){
	$("#planState").val("2");
}
//继续执行
function planNext(){
	$("#planState").val("1");
	var currentExecStep = $('#currentExecStep').val();
	planExecStep(currentExecStep,"1");
}
//手动执行
function planManual(){
	$("#planState").val("1");
	var currentExecStep = $('#currentExecStep').val();
	planExecStep(currentExecStep,"4");
}
//终止
function planStop(){
	$("#planState").val("0");
}
