<script>
import md5 from '@/common/md5.js';
export default {
  globalData: {
    //shareUrl: 'https://gdoctor.xazhima.com/api/v1.0/api.php', //开发环境全局接口域名 线上:https://guolu.xazhima.com/
    shareUrl: "https://kiq.xazhima.com/",
    globalTimestamp: Date.now().toString(),
    secret: "AirQK_weichat_app_zhima",
    selectedIndex:0,
	isSider:false,
	user_id: '',
	open_id:'',
	user_status:'',
	user_name:'',
	user_phone:'',
	user_headUrl:'',
	isAuth:false,
	session_key: '',
	contact_name:'',
  },
  onLaunch: function () {
    console.log("App Launch");
	this.loginLoad();
  },
  onShow: function () {
    console.log("App Show");
    uni.hideTabBar({})
  },
  onHide: function () {
    console.log("App Hide");
  },
  methods:{
	  loginLoad(){
	  	let that = this;
	  	uni.login({
	  		success(res) {
	  			that.loginRequest(res.code)
	  		}
	  	})
	  },
	  loginRequest(codeRes){
	  	let md5Sign = md5("method="+'user'+"&timestamp="+getApp().globalData.globalTimestamp+"&secret="+getApp().globalData.secret)
	  	let url = getApp().globalData.shareUrl+'api/api.php'+'?method=user&source=user&action=login&timestamp='+getApp().globalData.globalTimestamp +'&sign='+md5Sign
	  	uni.request({
	  		url:url,
	  		method: 'POST',
	  		header: {
	  			'content-type': 'application/x-www-form-urlencoded'
	  		},
	  		data: {
	  			code:codeRes
	  		},
	  		success: (res) => {
	  			console.log(res)
	  			if(res.data.code === 200){
	  				getApp().globalData.session_key = res.data.data.session_key;
	  				getApp().globalData.open_id = res.data.data.openid;
					getApp().globalData.user_status = res.data.data.status;
					getApp().globalData.user_phone = res.data.data.phone;
	  			}
	  		},
	  		fail: () => {
	  			console.log("连接失败");
	  		}
	  	});
	  },
  }
};
</script>

<style>
/*每个页面公共css */
.display-flex-start {
  display: flex;
  align-items: center;
}
.display-flex-end {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.display-between {
  display: flex;
  justify-content: space-between;
}
.display-around {
  display: flex;
  justify-content: space-around;
}
.display-between-column {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.display-around-column {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}
.display-wrap {
  display: flex;
  flex-wrap: wrap;
}
.items-center {
  align-items: center;
}
</style>
