<template>
  <div>
    <div class="answer-list" v-show="list.length">
      <div
        class="item"
        v-for="(item, index) in list"
        :key="index"
        @click="_showRed(item.redpacketId)"
      ></div>
      <div class="receive">
        待领取
        <i>{{ list.length }}</i>
      </div>
    </div>
    <transition name="fade">
      <div v-show="showRedInfo.type == 4 && showRedInfo.id && showRed">
        <red-info :answerList="list"></red-info>
      </div>
    </transition>
  </div>
</template>

<script>
const RED_TYPE = 4;
import { mapGetters, mapMutations } from 'vuex';
import redInfo from './info';
export default {
  name: 'red-answer-list',
  components: {
    redInfo
  },
  props: {
    answerList: {
      default() {
        return [];
      }
    }
  },
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      userInfo: 'userInfo',
      showRed: 'showRed',
      showRedInfo: 'showRedInfo'
    }),
    list() {
      const answerList = this.answerList || [];
      const list = answerList.sort((a, b) => {
        return b.redpacketId - a.redpacketId;
      });
      return list;
    }
  },
  methods: {
    ...mapMutations({
      set_showRed: 'set_showRed',
      set_showRedInfo: 'set_showRedInfo'
    }),
    _showRed(id) {
      if (this.userInfo.id) {
        this.set_showRedInfo({
          type: RED_TYPE,
          id: id
        });
      } else {
        this.$layer.msg('登陆后才能领取红包哦!~');
        this.$Bus.$emit('bus-showLogin', true);
      }
    },
    _closeRed() {
      this.set_showRed(false);
    }
  }
};
</script>

<style lang="less" scoped>
.answer-list {
  position: relative;
  display: block;
  width: 0.4rem;
  height: 0.65rem;
  margin-bottom: 0.05rem;
  .item {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    margin: auto;
    width: 0.4rem;
    height: 0.5rem;
    background: url('./img/answer-red.png') no-repeat center center;
    background-size: 100% 100%;
  }
  .receive {
    position: absolute;
    bottom: 0;
    left: -0.1rem;
    display: block;
    height: 0.25rem;
    line-height: 0.25rem;
    width: 0.6rem;
    background: url('./img/icon-yun.png') no-repeat center right;
    background-size: auto 100%;
    text-align: center;
    font-size: 0.1rem;
    i {
      color: #f5515f;
    }
  }
}
</style>
