<template>
  <next-tree
      ref="nextTreeRef"
      check-strictly
      func-mode="radio"
      select-parent
      :if-search="false"
      :tree-data="treeData"
      :is-show-clear="isShowClear"
      theme-color="#3377ff"
      page-height="92vh"
      label-key="name"
      value-key="departmentId"
      children-key="list"
      @confirm="fnTreeConfirm"
      @cancel="$emit('update:visible', false)"
  />
</template>

<script>
import {getTree} from "@/api";

export default {
  props: {
    visible: {
      type: Boolean,
      required: true,
    },
    value: {
      type: String,
      default: "",
    },
    isShowClear: {
      type: Boolean,
      default: false,
    },
    type:{
      type: String,
      default: "2",
    },
    corpId:{
      type: String,
      default: "",
    }
  },
  data() {
    return {
      treeData: []
    }
  },
  async mounted() {
    await this.fnGetData();
    this.$watch("visible", (newVal) => {
      if (newVal) {
        this.$refs.nextTreeRef && this.$refs.nextTreeRef._show();
        this.$refs.nextTreeRef && this.$refs.nextTreeRef.checkedFunc(this.value);
      } else this.$refs.nextTreeRef && this.$refs.nextTreeRef._hide();
    }, {immediate: true})
  },
  methods: {
    fnTreeConfirm(event) {
      this.$emit("confirm", event);
      this.$emit("update:visible", false);
    },
    async fnGetData() {
      const resData = await getTree({
        loading: false,
        getDepByCorpType:1,
        corpTypeList:[0,2]
      });
      this.treeData = resData.deptTree ;
    }
  },
}
</script>

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