<script>
	var md5 = require("./common/md5.js");
	export default {
		globalData: {
			shareUrl: 'https://stock.xazhima.com/api/api.php', //开发环境全局接口域名 线上:http://guolu.xazhima.com/
			glbalHeight:'',
			globalTimestamp: (Date.now()).toString(),
			user_id: '',
			open_id:'',
			user_name:'',
			user_headUrl:'',
			isAuth:'',
			sessionId: '',
			cleanPayTime: '',
			pageSize: 5, // 列表加载的pageSize
			isSetPassword: '',
			times:'',
			total_times:''
		},
		onLaunch: function() {
			console.log('App Launch')
			// 用户登录状态判断
			// uni.login({
			// 	success: (res) => {
			//         this.getCodeRabot(res)
			// 	}
			// });
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			getCodeRabot(res){
				uni.request({
					url:getApp().globalData.shareUrl, //需要设置为全局
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						method: 'login',
						timestamp: getApp().globalData.globalTimestamp, //Date.now()
						code: res.code,
						sign: md5('login' + getApp().globalData.globalTimestamp),
						// invited:'invited'
					},
					success: res => {
						// 通过openid发起会员登录
						 getApp().globalData.user_id = res.data.msg.id;
						 getApp().globalData.open_id = res.data.msg.openid;
						 getApp().globalData.isAuth = res.data.msg.isauth === '0';
						 getApp().globalData.user_name = res.data.msg.name;
						 getApp().globalData.user_headUrl = res.data.msg.headimg;
						 getApp().globalData.times = res.data.msg.times;
						 getApp().globalData.total_times = res.data.msg.total_times;
					} 
				});
			},
		 	loginRabot(){
				uni.request({
					url: getApp().globalData.shareUrl, //需要设置为全局
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						method: 'login',
						timestamp: getApp().globalData.globalTimestamp, //Date.now()
						wx_openid: res.data.data.openid,
						sign: md5('login' + getApp().globalData.globalTimestamp)
					},
					success: res => {
						if (res.data.code === 200) {
							if (res.data.data === 0) {
								// 没有会员数据，走默认注册逻辑
							} else {
								// 获取每个页面需要的memberId
								let member_id = res.data.data.member_id;
								getApp().globalData.member_id = member_id;
							}
						}
					}
				});
			}
		},
	}
</script>

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