<script>
	//#ifdef APP-PLUS
	var AndroidLog = uni.requireNativePlugin("AndroidLog")
	var device = uni.requireNativePlugin("DeviceInfo")
	//#endif
	export default {
		onLaunch: function() {
			//#ifdef APP-PLUS
			//判断客户端类别
			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"}}

			};
			// 
			setTimeout(() => {
				var pinf = plus.push.getClientInfo();
				var cid = pinf.clientid; //客户端标识  
				if (cid != null && cid != '' && cid != 'null') {
					//注册设备
					var deviceInfo = device.getDeviceInfo()
					this.$u.api.deviceReg({
							deviceNo: deviceInfo.deviceId,
							pushCid: cid
						})
						.then(res => {
							if (res.code == 200) {
								plus.nativeUI.toast('设备注册成功');
							} else {
								plus.nativeUI.toast('设备注册失败');
							}
						}).catch(err => {
							plus.nativeUI.toast('设备注册失败');
						});
					clearTimeout()
				}
			}, 400);
			//监听系统通知栏消息点击事件  
			plus.push.addEventListener('click', _handlePush, false);
			//监听接收透传消息事件
			plus.push.addEventListener('receive', _handlePush, false);
			//#endif
			//#ifdef H5
			  this.$u.api.deviceReg({
			  		deviceNo: '123456789',
			  		pushCid: '123456789'
			  	})
			  	.then(res => {
			  		if (res.code == 200) {
						uni.showToast({
							title: '设备注册成功',
							duration: 2000
						});
			  		} else {
						uni.showToast({
							title: '设备注册失败',
							duration: 2000
						});
			  		}
			  	}).catch(err => {
					uni.showToast({
						title: '设备注册失败',
						duration: 2000
					});
			  	});
			//#endif
		},
		onShow: function() {
			// console.log('App Show')

		},
		onHide: function() {
			// console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";
	/*每个页面公共css */
</style>