<template>
  <section class="group-title">
      <article v-show="showTitle" class="group-title-title">
        <span>{{groupTitle}}</span><span class="group-title-title-ml-6" v-show="isShowNum">（{{groupNum}}）</span>
      </article>
      <article v-show="showOrder" class="group-title-order">
        <div @click="order(1)" class="group-title-order-item">
          <span :class="{'active': showOrderIndex === 1}">学习人数</span>
          <img 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>
      </article>
  </section>
</template>
<script>
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: false
    }
  },
  methods: {
    toggle() {
      this.showTitle = !showTitle
      this.showOrder = !showOrder
    },
    order(index) {
      this.showOrderIndex = index
      this.$emit('order', index)
    } 
  }
}
</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(20px) 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);
      }
    }
  }
  .active {
    color: #449284;
  }
  &-title {
    padding: px2rem(20px) 0 px2rem(10px);
    font-size: px2rem(18px);
    font-weight: 500;
    color: #28344C;
    &-ml-6 {
      margin-left: -6px;
    }
  }
}
</style>
