<template>
	<view>
		<!-- 登陆拦截页面 -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//线上服务器域名
				homeUrl: "https://chtech.ncjti.edu.cn/jiaofei/jiaofei-api",
				// homeUrl: "http://192.168.161.34:9999",
			}
		},
		onLoad() {
			//获取cardNumber
			// this.loginFilter();
		},
		methods: {
			//获取cardNumber
			loginFilter() {
				let card_number = localStorage.getItem("card_number")
				if (!card_number) {
					let cardNumber = this.getQueryString("cardNumber");
					if (!cardNumber) {
						window.location.href =
							`https://open.wecard.qq.com/connect/oauth/authorize?app_key=580DBB565097446B&response_type=code&scope=snsapi_userinfo&ocode=1015730314&redirect_uri=${this.homeUrl}/tuitionpayment/wechat/weixiao/auth/&connect=curLogin&state=${this.homeUrl}/tuitionpayment/wechat/weixiao/auth/`;
					} else {
						localStorage.setItem("card_number", cardNumber)
						this.getStudentName()
					}
				} else {
					this.getStudentName()
				}
			},

			// 获取学生姓名
			getStudentName() {
				let studentName = localStorage.getItem("studentName")
				if (!studentName) {
					let studentName = this.getQueryString("name");
					if (!studentName) {
						window.location.href =
							`https://open.wecard.qq.com/connect/oauth/authorize?app_key=580DBB565097446B&response_type=code&scope=snsapi_userinfo&ocode=1015730314&redirect_uri=${this.homeUrl}/tuitionpayment/wechat/weixiao/auth/&connect=curLogin&state=${this.homeUrl}/tuitionpayment/wechat/weixiao/auth/`;
					} else {
						localStorage.setItem("studentName", studentName)
						this.getOpenId()
					}
				} else {
					this.getOpenId()
				}
			},

			//获取openId
			getOpenId() {
				// 从缓存获取openId，如果有的话
				let openId = localStorage.getItem("openId")
				if (!openId) {
					// 从url连接中获取openId，如果有的话
					let openId = this.getQueryString("openId");

					// 缓存中和url参数中度没有获取到openId，则请求授权地址发起授权
					if (!openId) {
						window.location.href =
							`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd87cbe1db0437303&redirect_uri=${this.homeUrl}/tuitionpayment/wechat/pub/auth&response_type=code&scope=snsapi_base&state=pages/index/index#wechat_redire`;
						return
					} else {
						// 获取到openId，存入缓存
						localStorage.setItem("openId", openId)
						// 跳转到缴费信息列表页面
						this.goPageHome();
					}
				} else {
					// 跳转到缴费信息列表页面
					this.goPageHome();
				}
			},

			//获取当前URL指定参数
			getQueryString(name) {
				// 获取URL
				let url = window.location.href;
				// 正则匹配URL
				let pattern = new RegExp("[?&]" + name + "=([^&]+)", "i");
				let matcher = pattern.exec(url);
				if (matcher == null || matcher.length < 1) {
					return false;
				}
				// 输出指定的参数值
				return decodeURIComponent(matcher[1]);
			},

			//跳转到支付信息列表页
			goPageHome() {
				uni.reLaunch({
					url: "/pages/home/home"
				});
			},
		}
	}
</script>

<style>

</style>
