<template>
  <div class="main-container" v-loading="!loaded">
    <div class="course-top" v-if="detail.curriculum">
      <div class="course-top-hd">
        <div class="course-top__title">{{ detail.curriculum.curriculum_name }}</div>
      </div>
      <div class="course-top-bd">
        <div class="course-top__pic"><img :src="detail.curriculum.curriculum_picture" /></div>
        <div class="course-top__content" v-html="detail.curriculum.curriculum_represent"></div>
      </div>
    </div>
    <el-tabs v-model="tabActive">
      <el-tab-pane label="按章节学习">
        <course-chapter :courseId="courseId" :data="detail.chapters" @on-click="handleClick"></course-chapter>
      </el-tab-pane>
      <el-tab-pane label="按考点学习">
        <course-tag :courseId="courseId"></course-tag>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import CourseChapter from '@/components/CourseChapter.vue'
import CourseTag from '../tag/index.vue'
import * as api from '@/api/course.js'
export default {
  name: 'CourseLearnItem',
  components: { CourseChapter, CourseTag },
  metaInfo() {
    return {
      title: this.detail.course_name || ''
    }
  },
  data() {
    return {
      tabActive: 0,
      loaded: false,
      detail: {}
    }
  },
  computed: {
    courseId() {
      return this.$route.params.id
    }
  },
  methods: {
    // 课程学习
    getCourse() {
      this.loaded = false
      api
        .getCourse(this.courseId)
        .then(response => {
          this.detail = response
        })
        .finally(() => {
          this.loaded = true
        })
    },
    handleClick(data) {}
  },
  beforeMount() {
    this.getCourse()
  }
}
</script>

<style lang="scss" scoped>
.main-container {
  height: 100%;
  padding: 30px;
  background-color: #fff;
  border-radius: 8px;
  box-sizing: border-box;
}
.course-top {
  padding-bottom: 20px;
}
.course-top-hd {
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid #ccc;
}
.course-top__title {
  font-size: 18px;
  font-weight: bold;
  line-height: 1;
}
.course-top-bd {
  display: flex;
}
.course-top__pic {
  width: 160px;
  height: 90px;
  margin-right: 20px;
  border-radius: 2px;
  overflow: hidden;
  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
.course-top__content {
  flex: 1;
  line-height: 24px;
  overflow: hidden;
}
</style>
