<template>
  <div>
    <div class="business-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>{{ rodNum }}</i>
      </div>
    </div>
    <transition name="fade">
      <div v-show="showRedInfo.type == 5 && showRedInfo.id && showRed">
        <div class="business" @click="_closeRed">
          <div class="business-box" @click.stop>
            <i class="close" @click="_closeRed"></i>
            <div class="info">
              <red-info></red-info>
            </div>
            <div class="list">
              <red-list :list="businessList"></red-list>
            </div>
          </div>
        </div>
      </div>
    </transition>
  </div>
</template>

<script>
const RED_TYPE = 5;
import { mapGetters, mapMutations } from 'vuex';
import redInfo from './info';
import redList from './list';
export default {
  name: 'red-business-box',
  components: {
    redInfo,
    redList
  },
  props: {
    businessList: {
      default() {
        return [];
      }
    }
  },
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      channelInfo: 'channelInfo',
      userInfo: 'userInfo',
      showRed: 'showRed',
      showRedInfo: 'showRedInfo'
    }),
    list() {
      const arr = [];
      const businessList = this.businessList;
      for (let i = 0; i < businessList.length; i++) {
        const item = this.businessList[i];
        if (item.isRob === 2) {
          arr.push(item);
        } else {
          arr.unshift(item);
        }
      }
      return arr;
    },
    rodNum() {
      let num = 0;
      const businessList = this.businessList;
      for (let i = 0; i < businessList.length; i++) {
        const item = this.businessList[i];
        if (item.isExpire !== 1 && item.isRob !== 1 && item.isEmpty !== 0) {
          num++;
        }
      }
      return num;
    }
  },
  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>
.business-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/business-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;
    }
  }
}
.business {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 500;
  background-color: rgba(0, 0, 0, 0.3);

  .business-box {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    margin: auto;
    width: 2.75rem;
    height: 4.625rem;
    .close {
      position: absolute;
      right: 0;
      top: -0.1rem;
      z-index: 2;
      width: 0.32rem;
      height: 0.32rem;
      background: url('./img/icon-close.png') no-repeat center center;
      background-size: 100% 100%;
    }
    .info {
      position: relative;
      width: 100%;
      height: 3.875rem;
      background: url('./img/red-bg.png') no-repeat 0 0;
      background-size: 100% 100%;
      overflow: hidden;
    }
    .list {
      height: 0.75rem;
      padding-top: 0.1rem;
    }
  }
}
</style>
