<template>
  <div class="course-item" @click="onClick(data)">
    <div class="course-item-pic" v-if="curriculum.curriculum_picture">
      <img :src="curriculum.curriculum_picture" />
    </div>
    <div class="course-item-content">
      <h3 class="course-item__title">{{data.course_name}}</h3>
      <div class="course-item__text" v-html="curriculum.curriculum_represent"></div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CourseItem',
  props: {
    data: { type: Object, required: true }
  },
  computed: {
    curriculum() {
      return this.data.curriculum
    },
    isWeapp() {
      return this.$store.state.isWeapp
    }
  },
  methods: {
    onClick(data) {
      if (this.isWeapp) {
        const url = `/pages/web/index?src=${window.location.origin}/course/learn/${data.course_id}`
        wx.miniProgram.navigateTo({ url })
      } else {
        this.$router.push({
          name: 'courseLearnItem',
          params: { id: data.course_id }
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.course-item {
  display: flex;
  padding: 0.4rem 0;
  border-bottom: 1px solid #f1f1f1;
}
.course-item-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}
.course-item-pic {
  width: 2.4rem;
  height: 1.35rem;
  margin-right: 10px;
  border-radius: 6px;
  overflow: hidden;
  margin-right: 0.2rem;
  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
.course-item__title {
  margin: 0;
  font-size: 0.3rem;
  font-weight: 400;
  color: #222;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
.course-item__text {
  max-height: 0.34rem;
  font-size: 0.26rem;
  color: #999;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  ::v-deep p {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
}
</style>
