<script>
	import {
		getpayOpenId
	} from './utils/api_hotel.js'
	// https://chtech.ncjti.edu.cn/hotel/ihotel/auto/appletLogin/login
	// https%3A%2F%2Fchtech.ncjti.edu.cn%2Fhotel%2Fh5%2F
	export default {
		onLaunch: function() {
			console.log('App Launch')
			// alert(localStorage.getItem('errorMsg')+'token')
			if(localStorage.getItem('token')=='null'){
				// alert(333)
				window.location.href ='https://open.wecard.qq.com/connect/oauth/authorize?app_key=4FD5599032819781&response_type=code&scope=snsapi_userinfo&ocode=1015730314&redirect_uri=https://chtech.ncjti.edu.cn/hotel/ihotel/auto/appletLogin/login&state=https://chtech.ncjti.edu.cn/hotel/ihotel/auto/appletLogin/login';
				//// window.location.href ='https://open.wecard.qq.com/connect/oauth/authorize?app_key=4FD5599032819781&response_type=code&scope=snsapi_userinfo&ocode=1015730314&redirect_uri=https://chtech.ncjti.edu.cn/testingServer/ihotel/auto/appletLogin/login&state=https://chtech.ncjti.edu.cn/testingServer/ihotel/auto/appletLogin/login';
			}else if(localStorage.getItem('token')=='null' && localStorage.getItem('errorMsg')=='null') {
				
				window.location.href ='https://open.wecard.qq.com/connect/oauth/authorize?app_key=4FD5599032819781&response_type=code&scope=snsapi_userinfo&ocode=1015730314&redirect_uri=https://chtech.ncjti.edu.cn/hotel/ihotel/auto/appletLogin/login&state=https://chtech.ncjti.edu.cn/hotel/ihotel/auto/appletLogin/login';
			} else if (localStorage.getItem('token')=='null' && localStorage.getItem('errorMsg')=='获取用户信息失败') {
				uni.navigateTo({
					url:'pages/huoquanshibai/huoquanshibai'
				})
			}
			// alert((localStorage.getItem('code')=='null'|| localStorage.getItem('code')=='undefined' || localStorage.getItem('code')==null),'2')
			if((!localStorage.getItem('openId2')&&localStorage.getItem('code')) || (localStorage.getItem('openId2')=='null'&&localStorage.getItem('code'))){
				this.getOpenId()
			}else if(localStorage.getItem('code')=='null'|| localStorage.getItem('code')=='undefined' || localStorage.getItem('code')==null){
				window.location.href ='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd87cbe1db0437303&redirect_uri=https%3A%2F%2Fchtech.ncjti.edu.cn%2Fhotel%2Fh5%2F&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect';
			}
		},
		methods:{
			getOpenId(){
				var data='?wxcode='+localStorage.getItem('code')
				getpayOpenId(data).then((res) => {
					if (res.success) {
						localStorage.setItem('openId2',res.message)
					} else if(res.code=='500'){
						window.location.href ='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd87cbe1db0437303&redirect_uri=https%3A%2F%2Fchtech.ncjti.edu.cn%2Fhotel%2Fh5%2F&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect';
					}
				}).catch((err) => {
				});
			}
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import '@/uni_modules/uni-scss/index.scss';
	/* #ifndef APP-NVUE */
	@import '@/static/customicons.css';
	// 设置整个项目的背景色
	page {
		background-color: #f5f5f5;
	}

	/* #endif */
	.example-info {
		font-size: 14px;
		color: #333;
		padding: 10px;
	}
</style>
