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

<script>
export default {
  data() {
    return {
      homeUrl: "https://jtishfw.ncjti.edu.cn/jiaofei/backendApi", //线上服务器域名
    };
  },
  onLoad(options) {
    this.loginFilter(); //获取cardNumber
  },
  methods: {
    //获取当前URL指定参数
    getQueryString(name) {
      let url = window.location.href; // 获取URL

      let pattern = new RegExp("[?&]" + name + "=([^&]+)", "i"); // 正则匹配URL

      let matcher = pattern.exec(url);

      if (matcher == null || matcher.length < 1) {
        return false;
      }
      return decodeURIComponent(matcher[1]); // 输出指定的参数值中文也可以
    },
    //获取cardNumber
    loginFilter() {
      let cardNumber = this.getQueryString("cardNumber");

      let error = this.getQueryString("error");

      let errorMsg = this.getQueryString("errorMsg");

      let homeWeb = `https://open.wecard.qq.com/connect/oauth/authorize?app_key=580DBB565097446B&response_type=code&scope=snsapi_userinfo&ocode=1015730314&redirect_uri=${this.homeUrl}/wechat/weixiao/auth/&connect=curLogin&state=${this.homeUrl}/wechat/weixiao/auth/`;

      if (error) {
        //微校服务器报错提示框
        uni.showToast({
          title: errorMsg,
          icon: "error",
          mask: true,
          duration: 1000,
        });
      } else if (!cardNumber) {
        window.location.href = homeWeb;
      } else {
        localStorage.setItem("cardNumber", cardNumber);
        this.getDetailMess(); //获取详细信息
      }
    },

    //换取详情信息
    getDetailMess() {
      let cardNumber = localStorage.getItem("cardNumber");

      let url = this.homeUrl + "/tuitionpayment/payableinfo/payableInfo";

      uni.request({
        url: url,
        data: {},
        header: {
          card_number: cardNumber,
          Accept: "application/json",
          "Content-Type": " application/x-www-form-urlencoded;charset=utf-8",
          "X-Requested-With": "XMLHttpRequest",
        },
        method: "GET",
        sslVerify: true,
        success: ({ data, statusCode, header }) => {
          if (data.data === null) {
            //识别家长跳转代缴费页面
            uni.redirectTo({ url: "/pages/parentPay/parentPay" });
          } else {
            //识别学生跳转学生支付页面
            uni.redirectTo({ url: "/pages/Pay/pay" });
          }
        },
        fail: (error) => {},
      });
    },
  },
};
</script>

<style lang="scss"></style>
