<template>
  <div class="reward" @click="_toggleReward(true)">
    <div class="btn">
      <div class="icon" :style="{background: channelInfo && channelInfo.screenDirection === 'vertical' ? `url(${defaultIcon}) no-repeat center center` : ''}"></div>
    </div>
    <div class="title">打赏</div>
    <reward v-model="isShow"></reward>
  </div>
</template>

<script>
import { mapGetters } from 'vuex';
const reward = resolve => require(['./rewardNew'], resolve);

export default {
  name: 'suspension-reward',
  components: {
    reward
  },
  data() {
    return {
      isShow: false,
      defaultIcon: require('./img/icon-reward.png')
    };
  },
  computed: {
    ...mapGetters({
      channelInfo: 'channelInfo',
      userInfo: 'userInfo'
    }),
  },
  mounted() {
    this.$Bus.$on('bus-showReward', this._toggleReward);
  },
  beforeDestroy() {
    this.$Bus.$off('bus-showReward', this._toggleReward);
  },
  methods: {
    _toggleReward(bol) {
      if (!this.userInfo.id && bol) {
        this.$layer.msg('请先登录');
        this.$Bus.$emit('bus-showLogin', true);
        return false;
      }
      this.isShow = bol
    },
  }
};
</script>
<style lang="less" scoped>
.reward {
  width: 0.8rem;
  height: 0.8rem;
  .btn {
    position: relative;
    padding: 0 0.1rem;
    width: 0.8rem;
    height: 0.6rem;
    background: var(--suspension-reward-bg) no-repeat center center;
    background-size: contain;
    .icon {
      width: 100%;
      height: 100%;
      background: var(--suspension-reward-icon) no-repeat center center;
      background-size: auto 50%;
    }
  }
  .title {
    margin-top: 0.04rem;
    line-height: 0.18rem;
    text-align: center;
    white-space: nowrap;
    font-size: 0.16rem;
  }
}
</style>
