<template>
  <section>
    <article class="group-title-title">
      <span>{{groupTitle}}</span>
    </article>
    <article class="group-title">
        <article v-show="showOrder" class="group-title-order">
          <div @click="order(1)" class="group-title-order-item">
            <span :class="{'active': showOrderIndex === 1}">按名首字母</span>
            <img class="first-name" src="../../images/sousuo/sort-down.png" v-show="showOrderIndex === 1"/>
          </div>
          <div @click="order(2)" class="group-title-order-item">
            <span :class="{'active': showOrderIndex === 2}">最新课程</span>
            <img src="../../images/sousuo/sort-down.png" v-show="showOrderIndex === 2"/>
          </div>
          <div @click="order(3)" class="group-title-order-item">
            <span :class="{'active': showOrderIndex === 3}">资源数</span>
            <img class="course-num" src="../../images/sousuo/sort-down.png" v-show="showOrderIndex === 3"/>
          </div>
          <div @click="order(4)" class="group-title-order-item">
            <span :class="{'active': showOrderIndex === 4}">热门</span>
            <img class="hot-degree" src="../../images/sousuo/sort-down.png" v-show="showOrderIndex === 4"/>
          </div>
        </article>
    </article>
  </section>

</template>
<script>
import { mapGetters } from 'vuex'
export default {
  data() {
      return {
        showOrderIndex: 1
      }
  },
  props: {
    groupTitle: {
      type: String,
      default: '课程'
    },
    isShowNum: {
      type: Boolean,
      default: true
    },
    groupNum: {
      type: String,
      default: "0"
    },
    showTitle: {
      type: Boolean,
      default: true
    },
    showOrder: {
      type: Boolean,
      default: true
    }
  },
  computed: {
    ...mapGetters({
      orderNum: 'orderNum'
    })
  },
  watch: {
    orderNum(val) {
      this.showOrderIndex = 1    
    }
  },
  methods: {
    toggle() {
      this.showTitle = !showTitle
      this.showOrder = !showOrder
    },
    order(index) {
      this.showOrderIndex = index
      this.$emit('order', index)
    },
    // resetShowOrderIndex(){
    //   this.showOrderIndex = 1
    // }
  }
}
</script>

<style lang="scss" scoped>
@import '../../style/mixin.scss';
.group-title {
  margin-left: px2rem(15px);
  display: flex;
  flex-direction: row;
  &-order {
    display: flex;
    flex-direction: row;
    padding: px2rem(10px) 0 px2rem(10px);
    font-size: px2rem(13px);
    &-item {
      position: relative;
      span {
        margin-right: px2rem(30px);
      }
      img {
        position: absolute;
        top: px2rem(2px);
        left: px2rem(51px);
        height: px2rem(15px);
        width: px2rem(15px);
      }
    }
  }
  .first-name {
    left: px2rem(63px);
  }
  .course-num {
    left: px2rem(37px);
  }
  .hot-degree {
    left: px2rem(25px);
  }
  .active {
    color: #449284;
  }
  &-title {
    padding: 0 px2rem(15px);
    span {
      font-size: px2rem(18px);
      font-weight: 500;
      color: #28344C;
    }
  }
}
</style>
