<script>
	export default {
		onLaunch: function(options) {
			// 系统没有开放前,请注释这段代码
			// uni.redirectTo({
			// 	url: '/pages/default/default'
			// })
			// return;
			// console.log('App Launch')
			// 系统没有开放前,请注释下面这行
			this.accredit(options)
		},
		onShow: function() {
			// console.log('App Show')
		},
		onHide: function() {
			// console.log('App Hide')
		},
		methods: {
			accredit(options) {
				// console.log('\'' + this.$utils.getEncryptedData('token') + '\'')
				// console.log('\'' + this.$utils.getEncryptedData('cardNumber') + '\'')
				// console.log('\'' + this.$utils.getEncryptedData('errorMsg') + '\'')

				var cardNumber = options.query.card_number;
				if (!this.$utils.isEmpty(cardNumber)) {
					this.$utils.storeEncryptedData('cardNumber', cardNumber);
				} else {
					cardNumber = this.$utils.getEncryptedData('cardNumber');
					if (this.$utils.isEmpty(cardNumber)) {
						uni.showToast({
							title: '未获得用户信息',
							duration: 3000
						})
					}
				}

				var token = this.$utils.getEncryptedData('token');
				var errorMsg = this.$utils.getEncryptedData('errorMsg');

				if (this.$utils.isEmpty(cardNumber) && this.$utils.isEmpty(token) && this.$utils.isEmpty(errorMsg)) {
					var url = 'https://chtech.ncjti.edu.cn/hotelReservation/zhotel/appopenid.action';
					var encodedUrl = encodeURIComponent(url);
					window.location.href = 'https://open.wecard.qq.com/connect/oauth/authorize' +
						'?app_key=9FFFACD6D09F15D2' +
						'&response_type=code' +
						'&scope=snsapi_userinfo' +
						'&ocode=1015730314' +
						'&redirect_uri=' + encodedUrl +
						'&state=' + url;
				} else if (this.$utils.isEmpty(cardNumber) && this.$utils.isEmpty(token) && this.$utils.containsString(errorMsg, '失败')) {
					uni.navigateTo({
						url: '/pages/p404/p404'
					})
				}
			}
		}
	}
</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>