<template>
	<view class="maincontent contentBg">
		<view>通知标题：{{payload.title}}</view>
		<view>设备信息：{{device.deviceName}}</view>
		<view>Mac地址：{{device.deviceMac}}</view>
		<view>设备IMEI：{{device.deviceImei}}</view>
		<view>通知详情：{{payload.content}}</view>		
	</view>
</template>

<script>
	import {deviceInfo} from '@/api/common/index.js';
	export default {
		data() {
			return {
				payload: {
					device_mac: '',
					device_imei: '',
					content: '',
					title: ''
				},
				device: {
					"id": "",
					"deviceName": "",
					"deviceImei": "",
					"deviceMac": "",
					"communicationMode": null,
					"devicePic": "",
					"typeName": "",
					"bluetoothName": "",
					"deviceStatus": null,
					"bindingTime": "",
					"onlineStatus": null,
					"battery": "",
					"latitude": "",
					"longitude": "",
					"alarmStatus": null,
					"detailPageUrl": ""
				}
			}
		},
		onLoad() {
			var eventChannel = this.getOpenerEventChannel();

			eventChannel.on('pushMsg', (res) => {
				this.payload.content = res.data.content;
				this.payload.title = res.data.payload.title;
				this.payload.device_mac = res.data.payload.device_mac;
				this.payload.device_imei = res.data.payload.device_imei;
				
				this.getDevice();
			});
		},
		methods: {
			getDevice() {
				deviceInfo({
					pageNum: 1,
					pageSize: 1,
					deviceMac: this.payload.device_mac
				}).then(res => {
					if (res.code == 200) {
						if (res.rows && res.rows.length) {
							let device=res.rows[0];
							this.device=device;
						}
					}
				});
			}
		}
	}
</script>

<style>

</style>