<template>
  <div>
    <group>
      <cell
        title="停车发票"
        inline-desc='仅支持微信支付订单,按照实际消费金额开票'
        is-link
        :link="{path:'./parkInvoice',query:{invoiceType:1}}"
      >
        <!-- anything -->
      </cell>

      <cell
        title="购买会员卡发票"
        inline-desc='支持购买月卡、季卡、年卡产生的费用，开具发票'
        is-link
        :link="{path:'./parkInvoice',query:{invoiceType:2}}"
      >
        <!-- anything -->
      </cell>

      <cell
        title="开票历史" is-link
        :link="{path:'./invoiceRecord'}"
      >
        <!-- anything -->
      </cell>

      <cell-box>
        注: 开具电子发票之前请绑定车牌并提交行驶证审核通过。
      </cell-box>
    </group>
  </div>
</template>

<script>
import {
  getOpenIdByCode,
  getTokenByOpenId,
  queryUserInfo,
  queryCustPersonBaseInfo,
  logout
} from "@/api/selfNav/selfNav";
export default {
  name: "eInvoiceNav",
  data() {
    return {
      webCode: ""
    };
  },
  created() {
    this.webCode = this.getUrlParam("code");
  },
  mounted() {
    this.getopenid();
  },
  methods: {
    getUrlParam(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
      var r = window.location.search.substr(1).match(reg);
      if (r != null) return unescape(r[2]);
      return null;
    },
    getopenid() {
      let jsondata = {
        appId: this.$utils.myVxAppId,
        code: this.webAppCode
      };
      getOpenIdByCode(jsondata).then(data => {
        console.log(data);
        if (data.code == "0") {
          let openid = data.data;
          sessionStorage.setItem("wx_openId", openid);
          console.log("用户 openid " + openid);
          this.getTokenByOpenId(openid);
        } else {
          this.$vux.toast.text(data.message, "top");
        }
      });
    },
    // 获取token
    getTokenByOpenId(openid) {
      let that = this;
      var jsondata = {
        openid: openid,
        deviceInfo: this.$utils.myDeviceInfo
      };
      getTokenByOpenId(jsondata).then(data => {
        console.log("执行获取token的接口  " + JSON.stringify(data));
        if (data.code == 0) {
          console.log("用户 token " + data.data.token);
          let _token = data.data.token;
          console.log("getTokenByOpenId获取到的" + _token);
          sessionStorage.setItem("wx_Token", data.data.token);
          // alert(data.data.token)
          sessionStorage.setItem("WXPhone", data.data.phoneNum);
          that.getinfoself(); //获取用户信息
        } else {
          this.$vux.toast.text(data.message, "top");
        }
        this.$vux.loading.hide();
      });
    }
  }
};
</script>

<style scoped>
  >>> .vux-label {
    padding-right: 20px;
  }
</style>
