<template>
  <container :title="chapter.name">
    <div class="read-desc" v-html="detail.reading_content"></div>
    <file-list :files="files"></file-list>
  </container>
</template>

<script>
// components
import Container from '../common/container.vue'
import FileList from './fileList.vue'
import * as api from '../../api'

// 章节阅读资料
export default {
  name: 'ChapterRead',
  components: { Container, FileList },
  props: {
    // 当前选中的
    chapter: {
      type: Object,
      default() {
        return {}
      }
    },
    // 课程详情接口返回的数据
    data: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      detail: {},
      files: []
    }
  },
  computed: {
    // 资源ID
    resourceId() {
      return this.chapter.resource_id
    }
  },
  methods: {
    getChapterReading() {
      api.getChapterReading(this.resourceId).then(response => {
        this.detail = response
        this.files = response.reading_attachment
      })
    }
  },
  beforeMount() {
    this.getChapterReading()
  }
}
</script>

<style scoped>
.read-desc {
  font-size: 16px;
  margin-bottom: 40px;
}
</style>
