<template>
  <view></view>
</template>

<script>
export default {
  data() {
    return {
      homeUrl: "https://jtishfw.ncjti.edu.cn/jiaofei/backendApi",
    };
  },
  onLoad(options) {
    this.loginFilter(); //获取cardNumber
  },
  methods: {
    //获取cardNumber
    loginFilter() {
      let cardNumber = sessionStorage.getItem("cardNumber");

      if (!cardNumber) {
        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=2DDC9DBF32F28845&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 {
          sessionStorage.setItem("cardNumber", cardNumber);
          this.getDetailMess();
        }
      } else {
        this.getDetailMess();
      }
    },

    //换取详情信息
    getDetailMess() {
      let cardNumber = sessionStorage.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) => {},
      });
    },

    //获取当前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]); // 输出指定的参数值 中文也可以
    },
  },
};
</script>

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