<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: 15px 0;
  border-bottom: 1px solid #ccc;
}
.course-arrow {
  width: 30px;
  height: 100px;
}
.course-arrow__up {
  background: url('https://zws-imgs-pub.ezijing.com/transport/weapp/icon_arrow_up.png') no-repeat left center;
  background-size: 15px 15px;
}
.course-arrow__down {
  background: url('https://zws-imgs-pub.ezijing.com/transport/weapp/icon_arrow_down.png') no-repeat left center;
  background-size: 15px 15px;
}
.course-item-top {
  display: flex;
}
.course-item-bottom {
  padding-left: 30px;
}
.course-item-pic {
  width: 108px;
  height: 100px;
  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: 24px;
  margin-left: 10px;
  padding: 0 10px;
  font-size: 10px;
  line-height: 24px;
}
.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>
