<script>
	import Vue from 'vue'
	export default {
		onLaunch: function(options) {

			uni.getSystemInfo({
				success: function(e) {
					// #ifndef MP
					Vue.prototype.StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
						Vue.prototype.CustomBar = e.statusBarHeight + 50;
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 45;
					};
					// #endif
					// #ifdef MP-WEIXIN
					Vue.prototype.StatusBar = e.statusBarHeight;
					let custom = wx.getMenuButtonBoundingClientRect();
					Vue.prototype.Custom = custom;
					Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
					// #endif		
					// #ifdef MP-ALIPAY
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
					// #endif
				}
			});
			let avatar=''
			let param={}
			param.phone =  options.query.mobile
			if(options.query.head)
			{
				param.avatar= options.query.head.replace('http', "https")
			}
			if(options.query.name){
				param.nickname=decodeURI(options.query.name)
			}
			// alert(nickname)
			
			uni.onTabBarMidButtonTap(() => {
			    uni.navigateTo({
			    	url:'/pages/publish/addPublish'
			    })
			})
			
			// this.$api.msg(param.avatar)
			if (options.query.mobile== null || options.query.mobile == '') {
			} else {
				if(options.query.mobile!= uni.getStorageSync('userInfo').phone){
					 uni.clearStorageSync();
					 console.log('用户不大对')
				}
				this.tokenLogin(param)
				// uni.setStorageSync("head" )	
			}
			// alert(options.query.mobile)
			console.log(options)
			// if(options.query.goodId && options.query.shopId && options.query.isPerson)
			// {
			// 	// alert(options.query.goodId)
			// 	if(options.query.isPerson === '1') //1是个人0是商家
			// 	{
			// 		uni.navigateTo({
			// 			url: 'pages/index/personDetails?goodsId='+options.query.goodId+'&serverId='+options.query.shopId+'&bizType='+this.$bizType+'&flag=true'
			// 		})
			// 	}else{
			// 		uni.navigateTo({
			// 			url: 'pages/index/shopDetails?goodsId='+options.query.goodId+'&bizType='+this.$bizType+'&flag=true'
			// 		})
			// 	}
			// }
		},


		onShow: function() {
			console.log('App Show')
			if(uni.getStorageSync('cameraPermissionsTime')=='')
			{
				uni.setStorageSync('cameraPermissionsTime',0)
			}
		},
		onHide: function() {
			console.log('App Hide')
			// uni.setStorageSync('cameraPermissionsTime',0)
		},
		methods: {
			tokenLogin(param) {
				if (param.phone == '') {
					uni.navigateTo({
						url: 'pages/codelogin/codelogin'
					})
				} else {
					this.$u.api.tokenLogin(param).then(res => {
						if (res.code === 200) {
							//登录成功，跳转首页
							// console.log(res)
							uni.setStorageSync("userInfo", res.data)
							uni.setStorageSync("token", res.data.token)
							// uni.setStorageSync("head", res.data.head)
							// uni.setStorageSync("name", res.data.name)
						} else {
							this.$api.msg(res.msg);
						}
					})
				}
			}
		}

	}
</script>

<style>
	@import "colorui/main.css";
	@import "colorui/icon.css";
	@import "common/common.scss";
	@import "uview-ui/index.scss";
	/* @import "uview-ui/index.scss"; */
	/*每个页面公共css */
</style>
