<template>
  <div class="main">
    <div class="input-warp">
        <el-input size="small" suffix-icon="el-icon-search" placeholder="请输入功能名称" v-model="filterText"> </el-input>
    </div>      

    <el-tree
      class="filter-tree"
      :data="data"
      :props="defaultProps"
      default-expand-all
      :highlight-current="true"
      :filter-node-method="filterNode"
      @node-click="handleNodeClick"
      ref="tree"
    >
    </el-tree>
  </div>
</template>
<script>
export default {
  props: {
    data: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      filterText: "",
      defaultProps: {
        children: "children",
        label: "label",
      },
    };
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },
  methods: {
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    handleNodeClick(data, Node){
        this.$emit("change", data);
    }
  },
};
</script>
<style lang="scss" scoped>
.input-warp{
    padding: 10px;
}
.main{
    background: #ffffff;
}
</style>