<template>
  <AddCourse
    v-if="nowEditorCourseInfo"
    :classify="classifyList_tree"
    :nowCheckCourse="nowEditorCourseInfo"
    @close_addCourse="$router.back()"
  />
</template>

<script>
import { getCourseClassfiyApi, getCourseInfoApi } from '@/api/online-course/online-course'
import AddCourse from '../../components/add-course/add-course.vue'

export default {
  components: { AddCourse },

  data: () => ({ classifyList_tree: [], nowEditorCourseInfo: null }),

  activated () {
    this.nowEditorCourseInfo = null
    this.$nextTick(() => {
      this[this.$route.params?.courseId ? 'edit' : 'add'](this.$route.params?.courseId)
    })
    this.getClassifyList()
  },

  methods: {
    async getClassifyList () {
      const { data } = await getCourseClassfiyApi()
      const { tree } = data.toTree()
      this.classifyList_tree = tree
    },

    add () {
      this.nowEditorCourseInfo = {
        creator: this.$store.user.id,
        updater: this.$store.user.id,
        remarks: null,
        name: '',
        classify: this.nowCheckClassify?.id || 1,
        sectionCount: 0,
        difficulty: 1,
        status: 1,
        grade: 0,
        cover: '',
        explain: '',
        studyOrgId: 1,
        sectionSortStudy: 0,
        coursewareSortStudy: 0,
        openQuiz: 0,
        openDiscussion: 0,
        openSelfEvaluation: 0,
        openEval: 0,
        txtOrGradeEvealute: 0,
        textOrGradeSelfEval: 0,
        textEvaluateTitle: '',
        selfTextEvaluateTitle: '',
        exercise: [],
        evalDimension: [],
        courseSectionContent: []
      }
    },

    async edit (courseId) {
      const { data } = await getCourseInfoApi(courseId)
      this.nowEditorCourseInfo = data
    }
  }
}
</script>

<style>

</style>
