<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-ui/index.scss";
	@import 'static/css/common.scss';
</style>
<script>
	import {
		mapMutations
	} from 'vuex';
	import * as config from '@/config'
	import appUpdate from 'common/appUpdate.js'
	import app_push from './components/APPPush/app_push.js'
	import permision from "@/js_sdk/wa-permission/permission.js"
	export default {
		methods: {
			...mapMutations(['login']),
			// vue的method里编写如下代码
			// async requestAndroidPermission(permisionID) {
			//     var result = await permision.requestAndroidPermission(permisionID)
			//     var strStatus
			//     if (result == 1) {
			//         strStatus = "已获得授权"
			//     } else if (result == 0) {
			//         strStatus = "未获得授权"
			// 		// permision.gotoAppPermissionSetting()
			// 		// 引导设置，判断是否有运输中订单，有订单，必须授权
			//     } else {
			//         strStatus = "被永久拒绝权限"
			// 		// permision.gotoAppPermissionSetting()
			//     }
			  
			// },
		},
		onLaunch: function() {
			// #ifdef APP-PLUS
       // let  isOpenLocation= permision.checkSystemEnableLocation() 
	   // console.log("isOpenLocation",isOpenLocation)
	   // this.requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION')
			let type = uni.getSystemInfoSync().platform
			console.log(type) 
			if (type == "android") {
				// appUpdate()
			}
			var that = this
			// plus.push.getClientInfoAsync((info) => {
			// 	var name = 'clientId'
			// 	var value = info.clientid
			// 	that.$store.commit('$uStore', {
			// 		name,
			// 		value
			// 	});
			// 	uni.setStorageSync("clientId", info.clientid)
			// 	console.log("info.clientid", info.clientid)
			// }, err => {});
			// 监听在线消息事件  
			plus.push.addEventListener("receive", function(msg) {
				var title = msg.content.split('：')[0]
				var content = msg.content.split('：')[1]

				let params = {
					inApp: true, // app内横幅提醒
					voice: true, // 声音提醒
					vibration: true, // 振动提醒
					messageType: "",
					messageTitle: title,
					messageContent: content,
					messageImage: 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/app/logo.png'
				}
				console.log("msg", msg)
				new app_push({
					...params
				}).show();
				var userInfo = uni.getStorageSync("userInfo")
				var that = this
				that.$request.baseRequest('get', '/notice/query/noticeNumber').then(res => {
					if (res.data.data) {
						let name = 'myTip';
						let value = res.data.data.task;
						that.$store.commit('$uStore', {
							name,
							value
						});
						if (value != 0 && value) {
							uni.setTabBarBadge({
								index: 4,
								text: value + ""
							})
						}
						name = 'taskTip';
						value = res.data.data.task;
						that.$store.commit('$uStore', {
							name,
							value
						});
						// name = 'contractTip';
						// value = res.data.data.contractTip;
						// that.$store.commit('$uStore', {
						// 	name,
						// 	value
						// });
					}
				})
				//其它逻辑  
			}, false);
			//监听系统通知栏消息点击事件  
			plus.push.addEventListener('click', function(msg) {
				//处理点击消息的业务逻辑代码  
				if (msg.content && msg.content.contains("任务")) {
					uni.navigateTo({
						url: '/pages/task/my_task'
					})
				} else if (msg.content && (msg.content.contains("合同") || msg.content.contains("交易"))) {
					uni.navigateTo({
						url: '/pageB/contract/contract'
					})
				}

			}, false);
			// #endif
			this.$socket.initWebIM(this.$ws, true, true)
			let userInfo = uni.getStorageSync('userInfo') || '';
			if (userInfo.id) {
				//更新登陆状态
				uni.getStorage({
					key: 'userInfo',
					success: (res) => {
						this.login(res.data);
					}
				});
			}

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

<style>
	/*每个页面公共css */
</style>
