classic-tabs.vue 2.24 KB
<template>
  <div :class="classes">
    <div class="yoho-coupon-filter-bar">
      <div
        :class="tabCls(item)"
        v-for="(item, index) in navList"
        @click="handleChange(index)"
        :key="index"
      >{{item.label}}

        <span v-if="getNum[index]">({{getNum[index]}})</span>
        <span :class="filterClass" v-if="item.filter"></span>
      </div>
    </div>
  </div>
</template>

<script>
import {createNamespacedHelpers} from 'vuex';
const {mapGetters} = createNamespacedHelpers('coupon/yoho');

export default {
  name: 'ClassicTabs',
  props: {
    value: {
      type: [String, Number]
    },
    data: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  data() {
    return {
      prefixCls: 'yoho-tabs',
      navList: this.data,
      activeKey: this.value,
      showFilter: false
    };
  },
  computed: {
    classes() {
      return [`${this.prefixCls}`];
    },
    filterClass() {
      if (this.showFilter) {
        return ['iconfont', 'icon-up'];
      } else {
        return ['iconfont', 'icon-downn'];
      }
    },
    ...mapGetters(['getNum'])
  },
  methods: {
    handleChange(index) {
      const nav = this.navList[index];

      if (this.activeKey === nav.label) {
        this.showFilter = !this.showFilter;
        this.$emit('on-filter-change', this.showFilter);
        return;
      }

      this.activeKey = nav.label;
      this.$emit('input', nav.label);
    },
    tabCls(item) {
      return [
        'filter-btn-box',
        {
          active: item.label === this.activeKey
        }
      ];
    },
  },
  watch: {
    value(val) {
      this.activeKey = val;
    }
  }
};
</script>

<style lang="scss" scoped>
$yoho-tab: yoho-tab;

.#{$yoho-tab}s {
  width: 100%;
}

.yoho-coupon-filter-bar {
  width: 100%;
  height: 90px;
  display: flex;
  padding: 14px 0;
  box-shadow: 0 0 16px 0 #eee;
  background-color: #fff;
  left: 0;
  z-index: 3;
  border-bottom: 1px solid #e0e0e0;

  .filter-btn-box {
    flex: 1;
    line-height: 60px;
    text-align: center;
    font-size: 28px;
    color: #b0b0b0;
    border-right: 1px solid #e0e0e0;
  }

  .filter-btn-box:last-child {
    border-right: none;
  }

  .show-filter-btn {
    color: #b0b0b0;
  }

  .active {
    color: #444;
  }
}
</style>