<template>
  <div class="main-container" v-if="loaded">
    <template v-if="detail.chapters && detail.chapters.length">
      <course-chapter :courseId="courseId" :data="detail.chapters"></course-chapter>
    </template>
    <van-empty description="暂无内容" v-else />
  </div>
</template>

<script>
import CourseChapter from './components/courseChapter.vue'
import * as api from '@/api/course.js'
export default {
  name: 'CourseLearnItem',
  components: { CourseChapter },
  metaInfo: {
    title: '课程内容'
  },
  data() {
    return {
      loaded: false,
      detail: {}
    }
  },
  computed: {
    courseId() {
      return this.$route.params.id
    }
  },
  methods: {
    // 课程学习
    getCourse() {
      this.loaded = false
      api.getCourse(this.courseId).then(response => {
        this.loaded = true
        response.chapters = response.chapters.filter(item => {
          item.children = item.children.filter(
            child => child.type === 2 && child.resource_id && child.resource_id !== '6684350363920760832'
          )
          return item.children.length
        })
        this.detail = response
      })
    }
  },
  beforeMount() {
    this.getCourse()
  }
}
</script>
