<template>
  <div class="course-item custom-class" :style="isOpen ? 'padding-bottom:0;' : ''">
    <div class="course-item-top" @click="toggleChild">
      <div class="course-arrow" :class="isOpen ? 'course-arrow__up' : 'course-arrow__down'"></div>
      <img class="course-item-pic" :src="data.photo" v-if="data.photo" />
      <div class="course-item-content">
        <div class="course-item__title">{{ data.title }}</div>
        <div class="course-item__tools">
          <div class="course-item__text course-item__text__course">含{{ data.course_num }}节课</div>
          <div class="course-item__text course-item__text__video">{{ data.video_num }}节视频课</div>
        </div>
      </div>
    </div>
    <div class="course-item-bottom" v-show="isOpen">
      <div
        class="course-child"
        v-for="item in data.child"
        :key="item.id"
        @click="onClick(item)"
      >{{ item.course_name }}</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CourseItem',
  props: { data: Object },
  data() {
    return {
      isOpen: false
    }
  },
  methods: {
    toggleChild() {
      this.isOpen = !this.isOpen
    },
    onClick(data) {
      this.$emit('on-click', data)
    }
  }
}
</script>

<style lang="scss" scoped>
.course-item {
  padding: 0.3rem 0;
  border-bottom: 1px solid #ccc;
}
.course-arrow {
  width: 0.6rem;
  height: 2rem;
}
.course-arrow__up {
  background: url('https://zws-imgs-pub.ezijing.com/transport/weapp/icon_arrow_up.png') no-repeat left center;
  background-size: 0.3rem 0.3rem;
}
.course-arrow__down {
  background: url('https://zws-imgs-pub.ezijing.com/transport/weapp/icon_arrow_down.png') no-repeat left center;
  background-size: 0.3rem 0.3rem;
}
.course-item-top {
  display: flex;
}
.course-item-bottom {
  padding-left: 0.6rem;
}
.course-item-pic {
  width: 3.15rem;
  height: 2rem;
  margin-right: 10px;
  overflow: hidden;
}
.course-item-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}
.course-item__title {
  font-size: 13px;
  color: #666;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
.course-item__text {
  display: inline-block;
  height: 0.48rem;
  margin-left: 0.15rem;
  padding: 0 0.2rem;
  font-size: 0.22rem;
  line-height: 0.48rem;
}
.course-item__text:first-child {
  margin-left: 0;
}
.course-item__text__course {
  color: #88bbff;
  background-color: #edf5ff;
}
.course-item__text__video {
  color: #54d0b0;
  background-color: #edfaf7;
}
.course-child {
  font-size: 13px;
  color: #666;
  padding: 15px 15px 15px 0;
  border-bottom: 1px solid #eee;
  background: url('https://zws-imgs-pub.ezijing.com/transport/weapp/icon_arrow.png') no-repeat right center;
  background-size: 5px 10px;
}
.course-child:last-child {
  border-bottom: 0;
}
</style>
