classic-tabs.vue 3.23 KB
<template>
  <div class="classic-tabs">
    <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 class="filter-wrapper" v-if="showFilter && filterList.length">
      <div class="filter-mask" @click="onMaskClick"></div>
      <FilterBar :list="filterList" v-model="selectFilterId" class="filter"></FilterBar>
    </div>
  </div>
</template>

<script>
import {createNamespacedHelpers} from 'vuex';
import FilterBar from '../filter-bar';
const {mapGetters, mapState} = createNamespacedHelpers('coupon/yoho');

export default {
  name: 'ClassicTabs',
  props: {
    value: {
      type: [String, Number]
    },
    data: {
      type: Array,
      default() {
        return [];
      }
    },
    filterId: {
      type: [String, Number],
      default() {
        return 0;
      }
    }
  },
  data() {
    return {
      prefixCls: 'yoho-tabs',
      navList: this.data,
      activeKey: this.value,
      showFilter: false,
      selectFilterId: this.filterId,
    };
  },
  computed: {
    classes() {
      return [`${this.prefixCls}`];
    },
    ...mapState(['filterList']),
    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 && index === 0) {
        this.showFilter = !this.showFilter;
        this.$emit('on-filter-change', this.showFilter);
        return;
      } else {
        this.showFilter = false;
      }

      this.activeKey = nav.label;
      this.$emit('input', nav.label);
    },
    tabCls(item) {
      return [
        'filter-btn-box',
        {
          active: item.label === this.activeKey
        }
      ];
    },
    onMaskClick() {
      this.showFilter = false;
    },
  },
  watch: {
    value(val) {
      this.activeKey = val;
    },
    selectFilterId(newVal) {
      this.$emit('update:filterId', newVal);
      this.onMaskClick();
    }
  },
  components: {
    FilterBar
  }
};
</script>

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

.classic-tabs {
  width: 100%;
  height: 90px;
}

.yoho-coupon-filter-bar {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  padding: 14px 0;
  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;
  }
}

.filter-wrapper {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 180px;
  z-index: 4;
}

.filter {
  position: absolute;
  top: 0;
}

.filter-mask {
  position: absolute;
  width: 100%;
  top: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.4);
}
</style>