<template>
  <section>
    <!-- <article class="group-title-title">
      <span class="group-title-title-main">{{groupTitle}}</span><span class="group-title-title-sub">专业领域的资深专家</span>
    </article> -->
    <article class="group-title">
        <article v-show="showOrder" class="group-title-order">
          <div @click="order(1, 'isLetterOrderDown', 'doctorFirstNameChar')" 
          :class="{'active': showOrderIndex === 1}" class="group-title-order-item">
            <span>按名首字母</span>
            <img class="first-name default" src="../../images/lecturer/sort-default.png" v-show="showOrderIndex !== 1"/>
            <img class="first-name" src="../../images/lecturer/sort-down.png" v-show="isLetterOrderDown && showOrderIndex === 1"/>
            <img class="first-name" src="../../images/lecturer/sort-up.png" v-show="!isLetterOrderDown && showOrderIndex === 1"/>
          </div>
          <div @click="order(2, 'isNewCourseOrderDown', 'newTime')" 
          :class="{'active': showOrderIndex === 2}" class="group-title-order-item">
            <span >最新课程</span>
            <img class="new-course-default" src="../../images/lecturer/sort-default.png" v-show="showOrderIndex !== 2"/>
            <img src="../../images/lecturer/sort-down.png" v-show="isNewCourseOrderDown && showOrderIndex === 2"/>
            <img src="../../images/lecturer/sort-up.png" v-show="!isNewCourseOrderDown && showOrderIndex === 2"/>
          </div>
          <div @click="order(3, 'isResourceNumOrderDown', 'resourceNum')" 
          :class="{'active': showOrderIndex === 3}" class="group-title-order-item">
            <span>资源数</span>
            <img class="course-num default" src="../../images/lecturer/sort-default.png" v-show="showOrderIndex !== 3"/>
            <img class="course-num" src="../../images/lecturer/sort-down.png" v-show="isResourceNumOrderDown && showOrderIndex === 3"/>
            <img class="course-num" src="../../images/lecturer/sort-up.png" v-show="!isResourceNumOrderDown && showOrderIndex === 3"/>
          </div>
          <div @click="order(4, 'isHotOrderDown', 'totalNum')" 
          :class="{'active': showOrderIndex === 4}" class="group-title-order-item">
            <span>热门</span>
            <img class="hot-degree default" src="../../images/lecturer/sort-default.png" v-show="showOrderIndex !== 4"/>
            <img class="hot-degree" src="../../images/lecturer/sort-down.png" v-show="isHotOrderDown && showOrderIndex === 4"/>
            <img class="hot-degree" src="../../images/lecturer/sort-up.png" v-show="!isHotOrderDown && showOrderIndex === 4"/>
          </div>
        </article>
    </article>
  </section>

</template>
<script>
import { mapGetters } from 'vuex'
export default {
  data() {
      return {
        showOrderIndex: 1,
        isLetterOrderDown: true,
        isNewCourseOrderDown: true,
        isResourceNumOrderDown: true,
        isHotOrderDown: true,
      }
  },
  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, orderType, orderName) {
      console.log(index, orderType, orderName)
      this.showOrderIndex = index
      this[orderType] = !this[orderType]
      this.$emit('order', orderName, this[orderType])
    },
    // 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;
      display: block;
      padding: px2rem(2px) px2rem(20px) px2rem(2px) px2rem(10px);
      margin-right: px2rem(10px);
      border: 1px solid #F6F6F6;
      border-radius: px2rem(25px);
      background: #F6F6F6;
      // border: 1px solid #449284;
      // span {
      //   // margin-right: px2rem(30px);
      // }
      img {
        position: absolute;
        top: px2rem(4px);
        left: px2rem(63px);
        height: px2rem(15px);
        width: px2rem(15px);
      }
    }
  }
  .first-name {
    left: px2rem(76px);
  }
  .first-name.default {
    top: px2rem(6px);
    left: px2rem(78px);
    height: px2rem(10px);
    width: px2rem(10px);    
  }
  .new-course-default {
    top: px2rem(6px);
    left: px2rem(65px);
    height: px2rem(10px);
    width: px2rem(10px);   
  }
  .course-num {
    left: px2rem(50px);
  }
  .course-num.default {
    top: px2rem(6px);
    left: px2rem(52px);
    height: px2rem(10px);
    width: px2rem(10px);    
  }
  .hot-degree {
    left: px2rem(37px);
  }
  .hot-degree.default {
    top: px2rem(6px);
    left: px2rem(39px);
    height: px2rem(10px);
    width: px2rem(10px);    
  }
  .active {
    color: #449284;
    background:rgba(68,146,132,0.06);
    border: 1px solid #449284;
    span {
      color: #449284;
    }
  }
  &-title {
    padding: 0 px2rem(15px);
    &-main {
      margin-right: px2rem(6px);
      font-size: px2rem(18px);
      font-weight: 500;
      color: #28344C;
    }
    &-sub {
      font-size: px2rem(15px);
      font-weight: 400;
      color: #999;
    }
  }
}
</style>
