<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 { findAllPaperClassifyApi } from '@/api/assessment-evaluation/paper'
export default {
  data: _ => ({
    classify: null,
    question_classify_list: []
  }),
  mounted () {
    if (this.mountedLoad) {
      this.findAllPaperClassify()
    }
  },
  activated () {
    this.findAllPaperClassify()
  },
  props: {
    value: {
      default: null
    },
    mountedLoad: {
      default: false
    }
  },
  watch: {
    value: {
      immediate: true,
      deep: true,
      handler (nv) {
        this.classify = nv
      }
    },
    classify: {
      immediate: false,
      deep: true,
      handler (nv) {
        this.$emit('input', nv)
      }

    }
  },
  methods: {
    /*
* 用于获取级联器数据的 API 调用。
*/
    findAllPaperClassify () {
      findAllPaperClassifyApi().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>
