<template>
  <el-cascader :options="question_classify_list"
    :props="{ checkStrictly: true, value: 'id', label: 'name', children, emitPath: false }" clearable
    v-model="classify">
  </el-cascader>
</template>

<script>
import { findAllQuestionsClassifyApi } from '@/api/assessment-evaluation/questions'
export default {
  data: _ => ({
    classify: null,
    question_classify_list: []
  }),
  mounted () {
    if (this.mountedLoad) {
      this.findAllQuestionsClassify()
    }
  },
  activated () {
    this.findAllQuestionsClassify()
  },
  props: {
    mountedLoad: {
      default: false
    },
    value: {
      default: null
    }
  },
  watch: {
    value: {
      immediate: true,
      deep: true,
      handler (nv) {
        this.classify = nv
      }
    },
    classify: {
      immediate: false,
      deep: true,
      handler (nv) {
        this.$emit('input', nv)
      }

    }
  },
  methods: {
    /*
      获取所有试题分类
    */
    findAllQuestionsClassify () {
      findAllQuestionsClassifyApi().then(({ data }) => {
        let questionClassifyMap = {}
        questionClassifyMap = data.toTree()
        const list = questionClassifyMap.tree
        this.question_classify_list = list
      }).catch(err => {
        console.info(err)
      }).finally(_ => {
        this.page_is_loading = false
      })
    }
  }
}
</script>

<style>

</style>
