<template>
  <Tree
    ref="resourceTree"
    class="resourceTree"
    style="margin-top: -8px;"
    :data="resourceTree"
    v-bind="$attrs"
    @on-select-change="select"
  ></Tree>
</template>
<script>
export default {
  props: {
    treeData: {
      type: Array,
      default: () => {
        return [];
      }
    }
  },
  data() {
    return {
      resourceTree: []
    };
  },
  watch: {
    treeData(val) {
      this.setTree(val);
    }
  },
  created() {
    this.setTree(this.treeData);
  },
  methods: {
    setTree(data) {
      this.resourceTree = JSON.parse(JSON.stringify(data));
    },
    select(list, data) {
      if (list.length) {
        this.$emit('select', data);
      } else {
        this.$emit('select', null);
      }
    },
    // 获取选中的树节点
    getSelectedNodes() {
      return this.$refs.resourceTree.getSelectedNodes();
    }
  }
};

</script>
<style lang="less">
.resourceTree {
  .ivu-tree-arrow-disabled + .ivu-tree-title {
    color: #c5c8ce;
    cursor: not-allowed;
    &:hover {
      background-color: #fff;
    }
  }
}
</style>
