<script>
	var md5 = require("./common/md5.js");
	export default {
		globalData: {  //https://stock.xazhima.com/
		    //shareUrl:'https://stock.xazhima.com/api/api.php',
			shareUrl: 'https://fenxiao.xazhima.com/api/api.php', //开发环境全局接口域名 线上:https://guolu.xazhima.com/
			globalTimestamp: (Date.now()).toString(),
			user_id: '',
			open_id:'',
			user_status:'',
			user_name:'',
			user_phone:'',
			user_headUrl:'',
			lastId:'',
			isAuth:true,
			session_key: '',
			inviteId:'',
			cleanPayTime: '',
			pageSize: '', // 列表加载的pageSize
			isAndroid:Boolean,
			isIos:false,
			globalShareCounts:'',
			shareImg:'',
		},
		onLaunch: function() {
			// console.log('App Launch')
		    // let equType = uni.getSystemInfoSync().platform;
			//  switch(equType){
			//     case 'android':
			//        console.log('运行Android上')
			//        break;
			//     case 'ios':
			//        console.log('运行iOS上');
			//        setTimeout(()=>{
			// 		  getApp().globalData.isIos = true 
			// 	   },100)
			//        break;
			//     default:
			//        console.log('运行在开发者工具上')
			//        break;
			// }
		},
		onShow: function() {
		},
		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 */
	page {
		height: 100%;
		background: #eee;
	}
</style>
