<!-- 设备分类树形选择下拉框 -->
<template>
  <ele-tree-select
    clearable
    filterable
    :value="value || ''"
    :data="treeData"
    label-key="name"
    value-key="id"
    default-expand-all
    :placeholder="placeholder"
    @input="updateValue"
    v-on="$listeners"
		@change="chooseNode"
  />
</template>

<script>
  import { getTreeByType } from '@/api/classifyManage';
  export default {
    props: {
      // 选中的数据(v-model)
      value: [Number, String],
      // 提示信息
      placeholder: {
        type: String,
        default: '请选择'
      }
    },
    data () {
      return {
        treeData: []
      };
    },
    created () {
      this.getData();
    },
    methods: {
      async getData () {
        const res = await getTreeByType(1);
        this.treeData = res.data;
		this.$emit('setRootId', res.data[0].id);
        // this.treeData = this.$util.toTreeData({
        //   data: data || [],
        //   idField: 'id',
        //   parentIdField: 'parentId'
        // });
      },
      /* 更新选中数据 */
      updateValue (value) {
        this.$emit('input', value);
      },
			
		chooseNode(node){
			this.$emit('changeNode', node);
		}
    }
  };
</script>
