function PushletData(){}
console.log("pushlet========");
PushletData.init = function(){
	console.log("pushlet==== init ====");
	PushletData.initData();
	console.log("pushlet==== init end====");
}

PushletData.leave = function () {
	try {
		console.log("11111111111");
		PL.leave(); 
		
		console.log('pushlet关闭');
	} catch(e) {
		console.log("Pushlet关闭失败!");
	}
}
//MapMain.js 中开启 PushletData.init
//pushlet加载
PushletData.initData = function (){
	console.log("pushlet==== initfunction ====");
	try {
		console.log("***pushlet初始化!***");
		PL._init();
		PL.join();
		PL.listen();
		PL.subscribe('/trafficAlarmData'); //交通事件告警信息 
		console.log("***Pushlet开启!***");
	} catch(e) {
		$.showMsg("Pushlet监听初始化失败!");
		setTimeout("PushletData.initData()",10000);
	}
	
	// 测试调取页面方法
//	var ff = document.getElementById("iframe-jklk-tab").contentWindow;
//	var ff = $("#iframe-jklk-tab")[0];
//	console.log(ff);
//	ff.pushletFillData();

//	$("#iframe-jklk-tab")[0].contentWindow.addPusData();
	/*var ff = $("#iframe-jklk-tab")[0].contentWindow;
	ff.resetSearchQuery();*/
	
//	var page = hh.document.getElementById('page');
//	console.log("page：",page);
	
}
//接收数据
function onData(data) {
	var event = data.get("p_subject");
	//var sid = data.get("p_sid");
	var text = data.get("obj");
	if(!text){
		return;
	}
	console.log("===接收=1111=trafficPlanData=========");
	if(event == "/trafficAlarmData") {
		//console.log("**************pushlet接受数据,trafficAlarmData");
		//调用子页面方法，将pushlet数据传输到iframe子页面中
		//console.log("数据")
		//console.log(JSON.parse(text))
		var res = JSON.parse(text)
		var str = '';
		var params = {};
		var msgTitle = '';
		//console.log('pushlet 返回数据-----',res.length);
		if(res.length){   //如果返回数据大于0
			console.log("==============：",res);
			res.forEach(function(item){
				str+=item.accidentId+",";
				msgTitle+=item.tdmc+' 发生 '+item.eventName+'，等级：'+item.alarmLevelName+'<br/>';
			})
		
			str = str.substr(0,str.length-1);
			params.accidentState = 0;
			params.accidentId = str;
			//批量更新状态
			$.ajax({
				type:"post",
				url:"trafficaccidentinfoAction!batch_update_TrafficHomePageinfo.do",
				data:params,
				dataType:"json"
			}).done(function(res){
				console.log('----pushlet-update--success',res)
			});
			//在窗口右下角显示消息提醒
			$.messager.show({
	             title:'消息提醒',
	             width:280,
	             height:180,
	             msg:'<a href="javascript:showPushletMsg();">工作台有【'+res.length+'】条告警信息待处理：<br/>'+msgTitle+'</a>',
	             showType:'show', //此处可改为slide fade等不同显示方式
	             timeout: 200000
	         });
//			$("#iframe-jklk-tab")[0].contentWindow.pushletFillData(text);			// 左侧刷新查询
			
			$("#iframe-jklk-tab")[0].contentWindow.addPusData(res);
//			console.log("111111111111111111111");
			//语音提醒信息
			setTimeout(function(){
				const utter = new SpeechSynthesisUtterance();
				utter.lang = 'zh-Hant-CN';      
				utter.text = msgTitle;      
				window.speechSynthesis.speak(utter);
			},0);
			
		}
		/*
		if(MapMain.layers[(String)(MapConst.LAYER_CHEGPS)].isChecked){
			//PushletData.pushCarMsg(text);
			//console.log('*************trafficAlarmData*****************',text);
		}
		*/
		return;
	}
	/*
	if(event == "/gpsCheMap") {
		if(MapMain.layers[(String)(MapConst.LAYER_CHEGPS)].isChecked){
			PushletData.pushCarMsg(text);
		}
		return;
	}
	*/
}
//警车推送
PushletData.pushCarMsg = function (text){
	var gpsMsgList = eval(text);	
	for(var i = 0; i < gpsMsgList.length; i++) {
		var msg = gpsMsgList[i];
		if(msg){
			var cheGpsLayer = MapMain.getLayer(MapConst.LAYER_CHEGPS);
			var vdChannelId = msg.vdChannelId;
			var id = msg.id;
			var preTime = cheGpsLayer.getObjGpsTime(vdChannelId, "updateTime");
			if (!msg.updateTime)  
				continue;
			if(msg.updateTime != preTime) {
				if(vdChannelId == CarTrace.carTraceId){
					CarTrace.currentCarTrace(msg);
				} else {
					var marker = cheGpsLayer.getMarkerBy(vdChannelId);
					if (marker) {
//						cheGpsLayer.tryCloseWindowHtml(marker, msg);
						MapAPI.removeOverlay(marker);
					}
					marker = cheGpsLayer.getMark(msg, MapConst.MARKER_ICON_ACTIVE_CHEGPS);
					MapAPI.addOverlay(marker);
					cheGpsLayer.tryOpenWindowHtml(marker, msg);
					cheGpsLayer.addMarkerToMarkerObj(vdChannelId, marker);
				}
				cheGpsLayer.setGpsObj(vdChannelId, msg);
			}
			
		}
	}
}
//错误重载
function onError(){
	setTimeout("PushletData.initData()",1000);
}
function showPushletMsg(){
	//$("#iframe-jklk-tab")[0].contentWindow.pushletFillData(text);
}
