<template>
  <div class="course-tag-wrapper">
    <div class="course-tag-hd">
      <h1 class="course-title">{{detail.course_name}}</h1>
    </div>
    <div class="course-tag-bd">
      <div class="course-tag-main">
        <h1 class="tag-title">{{chapter.name}}</h1>
        <ul class="tag-list">
          <li class="tag-item" v-for="item in tagList" :key="item.id" @click="onClick(item)">
            <span>{{item.title}}</span>
            <van-icon name="arrow" />
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
import * as api from '@/api/course.js'
export default {
  name: 'CourseTagList',
  data() {
    return {
      detail: { chapters: [] }
    }
  },
  computed: {
    courseId() {
      return this.$route.params.courseId
    },
    chapterId() {
      return this.$route.params.chapterId
    },
    chapter() {
      const found = this.detail.chapters.find(
        item => item.id === this.chapterId
      )
      return found || {}
    },
    tagList() {
      return this.chapter.tag || []
    }
  },
  methods: {
    // 获取知识点列表
    getCourseTagList() {
      api.getCourseTagList(this.courseId).then(response => {
        this.detail = response
      })
    },
    onClick({ id }) {
      this.$router.push({ name: 'courseTagItem', params: { id } })
    }
  },
  beforeMount() {
    this.getCourseTagList()
  }
}
</script>
<style lang="scss" scoped>
.course-tag-wrapper {
  min-height: 100vh;
  background-color: #eee;
  box-sizing: border-box;
}
.course-tag-hd {
  padding: 0.4rem;
  background-color: #fff;
}
.course-tag-bd {
  padding: 0.4rem;
}
.course-tag-main {
  padding: 0.2rem;
  background-color: #fff;
  border-radius: 0.12rem;
}
.course-title {
  font-size: 0.3rem;
  color: #222;
}
.tag-title {
  font-size: 0.3rem;
  font-weight: bold;
  color: #222;
  line-height: 0.48rem;
}
.tag-item {
  position: relative;
  padding: 0.4rem 0.4rem 0.4rem 0;
  font-size: 0.3rem;
  color: #222;
  line-height: 1.4;
  border-bottom: 1px solid #eee;
  &:last-child {
    border-bottom: 0;
  }
  ::v-deep .van-icon {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
  }
}
</style>
