<template>
  <view class="class-tab" >
    <view class="school-category" >
            <view 
              :class="['category-item', active === item.id ? 'category-item-active' : '']" 
              v-for="item in classCategory" 
              :key="item.id"
              @click="changeTabs(item)"
            >
              <text> {{ item.label }} <block v-if="item.hasOwnProperty('count')" >{{`(${item.count})`}}</block></text>
              <view  v-if="active === item.id" class="line" />
            </view>
    </view>
  </view>
</template>

<script>

export default {
  name: 'class-tab',
  props: {
    classCategory: {
      type: Array,
      require: true
    }
  },
  data () {
    return {
      active: -1,
    }
  },
  methods: {
    changeTabs (item) {
      this.active = item.id
      this.$emit('changeClass', item.id)
    }
  }
}
</script>

<style lang="less" scoped>

.school-category {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100vw;
      height: 102rpx;
      border-bottom: 2rpx solid #F6F6F6;
      position: sticky;
      top: 0rpx;
      z-index: 3;
      background-color: #fff;
      box-sizing: border-box;
      .category-item {
        font-size: 32rpx;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #666666;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        position: relative;
      }
      .category-item:nth-child(2) {
        margin-left: 40rpx;
        margin-right: 40rpx;
      }
      .category-item:nth-child(3) {
        margin-right: 40rpx;
      }
      .category-item-active {
        font-size: 32rpx;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #1677FF;
      } 
      .line {
        width: 40rpx;
        height: 6rpx;
        background: #1677FF;
        box-shadow: 0rpx 2rpx 12rpx 0rpx rgba(22, 119, 255, 0.43);
        border-radius: 200rpx;
        margin-top: 14rpx;
        position: absolute;
        top: 40rpx;
      }
    }
</style>