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

<script>
export default {
  name: 'CourseItem',
  props: {
    data: { type: Object, required: true }
  },
  computed: {
    isWeapp() {
      return this.$store.state.isWeapp
    }
  },
  methods: {
    onClick(data) {
      if (this.isWeapp) {
        wx.miniProgram.navigateTo({
          url: `/pages/course/free?id=${data.course_id}`
        })
      } else {
        window.alert('请在微信小程序中打开')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.course-item {
  display: flex;
  padding: 0.2rem 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-left: 10px;
  border-radius: 6px;
  overflow: hidden;
  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
.course-item__title {
  margin: 0;
  font-size: 0.3rem;
  font-weight: 400;
  color: #222;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.course-item__text {
  font-size: 0.26rem;
  line-height: 0.42rem;
  color: #999;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
</style>
