<template>
  <view class="page">
    <cu-custom :isBack="true" title="课程档案"></cu-custom>
    <view class="cu-list box-shadow menu">
      <view class="cu-item arrow margin-top-xs" v-for="file in list" :key="file.id" @tap="goto('fileDetail', file)">
        <view class="content margin-left-sm">
          <view>{{ file.course_name }}</view>
          <star-rating name="serviceNum" :score="file.level" :max="file.max_level"></star-rating>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { _getStudentFiles } from '@/api/course'
import starRating from '@/components/star-rating.vue'
export default {
  components: {
    starRating
  },
  data() {
    return {
      key: '课程档案',
      params: {
        page: 1
      },
      list: [],
      ability: []
    }
  },
  onLoad() {
    this.get_list()
  },
  methods: {
    get_list() {
      _getStudentFiles(this.params).then(res => {
        this.list = res.data.list
        this.ability = res.data.ability
      })
    },
    goto(page, file) {
      const ability = this.ability.filter(item => {
        if (file.ability_total[item.id]) {
          this.$set(item, 'score', file.ability_total[item.id])
          return true
        }
      })
      this.$set(file, 'ability', ability)
      this.globalNavigateTo(page, { file: JSON.stringify(file) })
    }
  }
}
</script>

<style lang="scss" scoped></style>
