<template>
  <view class="content">
    <image src="../../static/images/pay.png" />
    <text class="tip">付款成功</text>
    <view class="item" v-show="isShow2">
      <text>南昌交通学院</text>
      <text>{{ realPayAmount }}</text>
    </view>
    <view class="item-show" v-show="isShow1">
      <text>请通知本人查询</text>
    </view>
    <button @click="navigateToIndex">返回首页</button>
  </view>
</template>
<script>
export default {
  data() {
    return {
      realPayAmount: "",
      isShow1: false,
      isShow2: true,
    };
  },
  onLoad(options) {
    // this.loginFilter();
  },
  methods: {
    //获取cardNumber
    loginFilter() {
      let cardNumber = this.getQueryString("cardNumber");
      let error = this.getQueryString("error");
      let homeWeb =
        "https://open.wecard.qq.com/connect/oauth/authorize?app_key=2DDC9DBF32F28845&response_type=code&scope=snsapi_userinfo&ocode=1015730314&redirect_uri=https://jtishfw.ncjti.edu.cn/jiaofei/backendApi/wechat/weixiao/auth/&connect=curLogin&state=https://jtishfw.ncjti.edu.cn/jiaofei/backendApi/wechat/weixiao/auth/";
      if (!cardNumber) {
        window.location.href = homeWeb;
      } else if (error) {
        uni.showToast({
          title: "cardNumber获取失败",
          icon: "error",
          mask: true,
          duration: 2000,
        });
      } else {
        localStorage.setItem("cardNumber", cardNumber);
        this.getDetailMess();
      }
    },

    //换取详情信息
    getDetailMess() {
      let that = this;
      let cardNumber = localStorage.getItem("cardNumber");
      let url = that.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.success) {
            uni.showToast({
              title: "获取信息失败",
              icon: " error",
              mask: true,
              duration: 2000,
            });
          } else {
            if (data.data === null) {
              that.isShow1 = !that.isShow1;
              that.isShow2 = !that.isShow2;
            } else {
              let res = data.data;
              that.realPayAmount = res.realPayAmount;
            }
          }
        },
        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]); // 输出指定的参数值 中文也可以
    },

    // 退出支付成功页面
    navigateToIndex() {
      uni.navigateTo({ url: "/pages/Pay/pay" });
    },
  },
};
</script>

<style lang="scss">
@import url("./css/paySuccess.min.css");
</style>
