<template>
  <el-tree-select
    ref="treeSelectRef"
    v-model="modelValue"
    :data="data"
    :props="{
      value: 'id',
      children: 'nodes',
      label: 'name',
    }"
    node-key="id"
    :render-after-expand="false"
    accordion
    check-strictly
    :clearable="true"
    :disabled="disabled"
  />
</template>

<script setup>
import {
  layoutFnGetTrainingIndustryType,
  layoutFnGetTrainingPlateType,
  layoutFnGetTrainingPostType,
} from "@/assets/js/data_dictionary";
import { ref } from "vue";
import { useVModel } from "@vueuse/core";

defineOptions({
  name: "LayoutLearningTrainType",
});
const props = defineProps({
  modelValue: {
    type: String,
    required: true,
    default: "",
  },
  type: {
    type: String,
    required: true,
    default: "",
    validator: (value) => {
      if (["industry", "post", "plate"].includes(value)) {
        return true;
      } else {
        throw new Error("type必须是industry、post、plate之一");
      }
    },
  },
  disabled: {
    type: Boolean,
    default: false,
  },
});
const emits = defineEmits(["update:modelValue"]);
const modelValue = useVModel(props, "modelValue", emits);
const treeSelectRef = ref(null);
const getCurrentNode = () => {
  return treeSelectRef.value.getCurrentNode();
};
defineExpose({
  getCurrentNode,
});
let data = [];
if (props.type === "industry") data = await layoutFnGetTrainingIndustryType();
if (props.type === "post") data = await layoutFnGetTrainingPostType();
if (props.type === "plate") data = await layoutFnGetTrainingPlateType();
</script>

<style scoped></style>
