<template>
  <div class="tab-box">
    <ul class="list">
      <li
        class="item"
        :class="{ 'z-active': active == index }"
        v-for="(item, index) in menuList"
        :key="index"
        @click="_tabSwitch(index)"
      >
        <span>{{ item.menuName }}</span>
      </li>
    </ul>
    <div class="follow" v-if="wechatInfo.status" @click="_showFollow">
      <span class="icon"></span>
      <span>关注</span>
    </div>
    <div class="follow-box" v-if="wechatInfo.status" v-transfer-dom>
      <transition name="fade">
        <follow-box v-show="wechatInfo.isShow" v-model="wechatInfo"></follow-box>
      </transition>
    </div>
  </div>
</template>
<script>
import { getWechatInfo } from '@/plugins/API/apiAll';
import { mapGetters } from 'vuex';
const followBox = resolve => require(['@/components/modules/followBox'], resolve);

export default {
  name: 'menu-tab',
  props: {
    value: {}
  },
  components: {
    followBox
  },
  data() {
    return {
      wechatInfo: {}
    };
  },
  computed: {
    ...mapGetters({
      channelInfo: 'channelInfo',
      menuList: 'menuList'
    }),
    active: {
      get() {
        return this.value;
      },
      set(nVal) {
        this.$emit('input', nVal);
      }
    }
  },
  mounted() {
    this._getWechatInfo();
  },
  methods: {
    async _getWechatInfo() {
      const res = await getWechatInfo({
        id: this.channelInfo.id
      });
      if (res.code === 200 && res.errorCode === 0) {
        this.wechatInfo = res.data || {};
      }
    },
    _tabSwitch(num) {
      this.active = num;
    },
    _showFollow() {
      this.wechatInfo.isShow = true;
    }
  }
};
</script>
<style lang="less" scoped>
.tab-box {
  position: relative;
  display: flex;
  height: 0.4rem;
  line-height: 0.4rem;
  text-align: center;
  font-size: 0.12rem;
  background-color: #fff;
  color: #666666;
  .list {
    flex: 1;
    display: flex;
    .item {
      flex: 1;
      overflow: hidden;
      text-overflow: ellipsis;
      span {
        white-space: nowrap;
      }
      &.z-active {
        position: relative;
        font-size: 0.14rem;
        font-weight: bold;
        color: var(--main-color);
        &:after {
          content: '';
          display: block;
          position: absolute;
          left: calc(50% - 0.12rem);
          bottom: 0.02rem;
          width: 0.24rem;
          height: 0.02rem;
          background: var(--main-color);
          border-radius: 0.02rem;
        }
      }
    }
  }
  .follow {
    flex: 0 0 0.8rem;
    width: 0.8rem;
    background: var(--main-color);
    color: #fff;
    span {
      vertical-align: middle;
    }
    .icon {
      margin-right: 0.04rem;
      display: inline-block;
      width: 0.1rem;
      height: 0.1rem;
      background-image: var(--icon-jia-white);
      background-repeat: no-repeat;
      background-position: center center;
      background-size: 100% auto;
    }
  }
}
</style>
