<template>
  <div class="qr-code">
    <img id="image" src alt />
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "index",
  data() {
    return {
      accessToken: "",
      nowUrl: "",
      activeId: "",
      voucherId: "",
      unionId: ""
    };
  },
  mounted() {
    // alert('--->arCode: mounted: IN.')
    this.cleanUrl()
    // this.getAcessToken();
    this.createCode()
  },
  methods: {
    cleanUrl() {
      // alert('--->arCode: cleanUrl: IN.')
      this.nowUrl = this.$route.query.Url
      this.activeId = this.$route.query.activeId
      this.voucherId = this.$route.query.voucherId
      this.unionId = this.$route.query.unionId
    },
    getAcessToken() {
      let _this = this;
      axios({
        url: "http://139.155.48.151:8085/workWx/auth/oauth2/getAccessToken",
        method: "get"
      }).then(res => {
        _this.accessToken = res.data.data;
        _this.createCode();
      });
    },
    createCode() {
      let _this = this;
      let nowUrl = _this.nowUrl? _this.nowUrl : ""
      let voucherId = _this.voucherId? _this.voucherId : ""
      let activeId = _this.activeId? _this.activeId : ""
      let unionId = _this.unionId? _this.unionId : ""
      let pageUri = `${nowUrl}&detailid=${voucherId}&actionid=${activeId}&unionid=${unionId}`;
      let pageUrl = `http://139.155.48.151:8085/workWx/auth/oauth2/wxMiniQrCode?pageUri=${pageUri}`;
      $.ajax({
        type: "POST",
        url: pageUrl,
        // data: JSON.stringify({ path: "pages/signIn/signIn" }),
        data: {},
        success: function(res) {
          console.log(res)
          $('#image').attr('src',res.data)
        },
        error: function(data) {
          alert('error' + JSON.stringify(data))
          console.log(data);
        }
      });
    }
  }
};
</script>

<style scoped lang="scss">
.qr-code {
  text-align: center;
  padding-top: 50px;
  #image {
    display: inline-block;
    width: 60%;
  }
}
</style>
