<template>
  <div class="draw" @click="goDraw">
    <div class="btn">
      <div class="icon"></div>
    </div>
    <div class="title">{{ countDowm }}</div>
  </div>
</template>
<script>
import { mapGetters } from 'vuex';
export default {
  name: 'suspension-draw',
  props: {
    info: {}
  },
  computed: {
    ...mapGetters({
      nowDate: 'nowDate',
      type: 'type',
      userInfo: 'userInfo',
      channelInfo: 'channelInfo'
    }),
    countDowm() {
      const now = this.nowDate / 1000;
      if (!this.info.id) {
        return '未开始';
      }
      if (this.info.endTime <= now) {
        return '已结束';
      } else if (this.info.startTime >= now) {
        const time = this.info.startTime - now;
        return this.$options.filters.formatTime(time, 'mm:ss');
      } else {
        return '进行中';
      }
    }
  },
  methods: {
    goDraw() {
      if (!this.userInfo.id) {
        this.$Bus.$emit('bus-showLogin', true);
      } else {
        const { previewUrl } = this.info;
        const channelId = this.channelInfo.id;
        const type = this.type;
        const backUrl = encodeURIComponent(window.location.href);
        window.location.href = `${previewUrl}&stype=${type}&sid=${channelId}&backUrl=${backUrl}`;
      }
    }
  }
};
</script>
<style lang="less" scoped>
.draw {
  width: 0.8rem;
  height: 0.8rem;
  .btn {
    position: relative;
    padding: 0 0.1rem;
    width: 0.8rem;
    height: 0.6rem;
    background: var(--suspension-draw-bg) no-repeat center center;
    background-size: contain;
    .icon {
      width: 100%;
      height: 100%;
      background: url(./img/icon-draw.png) no-repeat center center;
      background-size: auto 60%;
    }
  }
  .title {
    margin-top: 0.02rem;
    line-height: 0.18rem;
    text-align: center;
    white-space: nowrap;
    font-size: 0.16rem;
    color: #666;
  }
}
</style>
