var alog = uni.requireNativePlugin("AndroidLog")
let speaker = uni.requireNativePlugin("SpeechPlug");
const _handlePush = function(message) {
				//{"message":{"__UUID__":"androidPushMsg222631973","appid":"__UNI__29ECCC8","content":"{\"type\":2,\"jumpTo\":\"pages/login/login\"}","payload":{"jumpTo":"pages/login/login","type":2},"title":"智慧停车PDA"}}
				try {
					alog.info({msg: '接收到推送信息:' + message.content});
					let content = JSON.parse(message.content);
					if (content.type === 1){
						deviceParkIn(content)
					}else if (content.type === 2){
						deviceParkOut(content)
					}
				} catch(e){
					
				}
				
			};

// content 消息格式:  JSON格式
// type: 1-设备入场 2-设备出场 3-用户已经支付
// speakMsg: 语音播报内容
// popNode: 弹出框内容
// jumpTo: 页面跳转地址
// data: {} 其他参数,JSON格式
function deviceParkIn(content){
	if(content.speakMsg){
		speaker.speakAction(content.speakMsg)
	}
	uni.showModal({
	  title: '温馨提示',  
	  content: content.popNode, 
	  success: (res) => {
		  if(res.confirm){
			  uni.navigateTo({
			      url: content.jumpTo
			  });
		  }
	  }  
	});
}

function deviceParkOut(content){
	if(content.speakMsg){
		speaker.speakAction(content.speakMsg)
	}
}

function pushreg(vue){	
	     alog.info({msg: '推送注册'});
		//监听系统通知栏消息点击事件
		plus.push.addEventListener('click', _handlePush, false);
		//监听接收透传消息事件
		plus.push.addEventListener('receive', _handlePush, false);
}
export default pushreg