MainTab.vue 3.18 KB
<template>
  <div class="tab-box flex">
    <div class="flex">
      <div v-for="(item, index) in tabList" :key="index" class="tab-item" :class="tabActive == index ? 'tab-item-active' : ''" @click="changeTab(index)">{{ item }}</div>
    </div>
    <div class="flex" v-show="showMonth">
      <span class="month-text">统计月份:</span>
      <div class="month-plugin">
        <div class="month" @click.stop="switchMonth">
          {{ month || '全部' }}
          <img class="arrow-down" src="@/assets/images/arrow-down.png" alt="" />
        </div>
        <SelectBox
          :isShow="isShow"
          isObject
          :defaultValue.sync="defaultMonth"
          @clickOutside="clickOutside"
          :dataList.sync="dataList"
          :boxWidth="'8.61vw'"
          @selectVal="selectVal"
          :valueName="'statMonth'"
        ></SelectBox>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'MainTab',
  props: {
    tabList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      tabActive: 0,
      isShow: false,
      showMonth: true,
      defaultMonth: {
        label: new Date().format('yyyy-MM'),
        statMonth: new Date().format('yyyy-MM')
      },
      dataList: [],
      month: ''
    }
  },
  created() {
    this.getMonth()
  },

  mounted() {},

  methods: {
    async getMonth() {
      const _result = await this.api.crowdFunding.getMonth()
      const _dataList = _result.data.dataList
      _dataList.forEach(item => {
        this.dataList.push({
          label: item.statMonth,
          statMonth: item.statMonth
        })
      })
      this.defaultMonth = this.month = this.dataList[0].statMonth
      this.$bus.$emit('crowdFundingMonth', this.dataList[0].statMonth)
    },
    // tab切换
    changeTab(index) {
      this.tabActive = index
      this.showMonth = index === 0
      this.$emit('tabChange', index)
    },
    switchMonth() {
      this.isShow = !this.isShow
    },
    selectVal(val) {
      this.defaultMonth = this.month = val.statMonth
      this.$bus.$emit('crowdFundingMonth', val.statMonth)
      this.switchMonth()
    },
    clickOutside() {
      this.isShow = false
    }
  }
}
</script>

<style lang="scss" scoped>
.tab-box {
  height: 6.22vh;
  justify-content: space-between;
  padding: 1.11vh 0.83vw;
  box-sizing: border-box;
  background: #091c40;
  .tab-item {
    height: 4vh;
    line-height: 4vh;
    font-weight: 400;
    font-size: 14px;
    color: #c9c9c9;
    padding: 0 1.39vw;
    cursor: pointer;
  }
  .tab-item-active {
    font-weight: 500;
    font-size: 16px;
    color: #ffffff;
    background-image: linear-gradient(270deg, #6578ff 0%, #079ff1 100%);
  }
  .month-text {
    font-weight: 400;
    font-size: 14px;
    color: #c9c9c9;
  }
  .month-plugin {
    position: relative;
  }
  .month {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 8.61vw;
    height: 4vh;
    padding: 0 0.56vw;
    box-sizing: border-box;
    background-image: linear-gradient(270deg, #6578ff 0%, #079ff1 100%);
    margin-right: 0.56vw;
    color: #ffffff;
    .arrow-down {
      width: 0.69vw;
      height: 0.67vh;
    }
  }
}
.flex {
  display: flex;
}
</style>