<template>
  <view class="center">
    <image class="w600" mode="widthFix" :src="referCodeBase64"></image>
    <button type="primary" @click="getReferCode()" class="mt30">重新获取</button>
  </view>
</template>

<script>
import api from "@/api";
export default {
  data() {
    return {
      referCodeBase64:
        "data:image/png;base64,[encoded data, 10756 characters]",
    };
  },
  methods: {
    getReferCode() {
      api.user.userInfoGetWxacodeunLimit().then((res) => {
        let userInfo = uni.getStorageSync("userInfo");
        let unionId = userInfo.unionId;
        this.referCodeBase64 = "data:image/png;base64," + res.data;

        uni.setStorageSync(
          unionId + "_referCodeBase64",
          "data:image/png;base64," + res.data
        );
      });
    },
  },
  onLoad() {
    let userInfo = uni.getStorageSync("userInfo");
    let unionId = userInfo.unionId;
    if (uni.getStorageSync(unionId + "_referCodeBase64")) {
      this.referCodeBase64 = uni.getStorageSync(unionId + "_referCodeBase64");
      return;
    }
    this.getReferCode();
  },
};
</script>

<style lang="scss" scoped>
.center {
  width: 750rpx;
  display: flex;
  justify-content: center;
  padding-top: 30rpx;
  flex-wrap: wrap;
}
.mt30{
  margin-top: 30rpx;
}
.w600 {
  width: 600rpx;
}
</style>