<template>
  <div>
    <img :src="data.imgUrl" alt="" class="background-image" @click="jumpToUrl(data.jumpUrl)" />
  </div>
</template>
<script>
import localStorage from '@/service/localStorage.service';
import { getTokenFromApp } from '@/service/yxmLogin.service';
export default {
  props: {
    data: Object
  },
  data() {
    return {};
  },
  methods: {
    async jumpToUrl(url) {
      if (!url) return;
      this.$track.registeredEvents('H5_NewUserPageVcccardClick', {
        card_status: this.data.openVccStatus
      });
      if (this.$bridge.isApp) {
        if (!sessionStorage.getItem('vccToken')) {
          try {
            const res = await getTokenFromApp(true);
            sessionStorage.setItem('vccToken', res);
            this.$emit('reload');
          } catch (e) {
            console.error(e);
          }
          return;
        }
        url = url.replace(/{token}/, sessionStorage.getItem('vccToken'));
        url = url.replace(/{registerFrom}/, localStorage.get('registerFrom'));
        url = url.replace(/{appChannel}/, localStorage.get('appChannel'));
        url = url.replace(/{appName}/, localStorage.get('appName'));
        this.$bridge.openNewUrl({
          data: {
            newUrl: `xyqb://openHttp?jumpUrl=${url}`
          }
        });
      } else {
        if (!localStorage.get('vccToken')) {
          this.$router.push({ name: 'Login' });
        } else {
          url = url.replace(/{token}/, localStorage.get('vccToken'));
          url = url.replace(/{registerFrom}/, localStorage.get('vccChannel'));
          window.location.href = url;
        }
      }
    }
  }
};
</script>
<style lang="less" scoped>
.background-image {
  width: 100vw;
  height: auto;
}
</style>
