<!-- 部门树形选择下拉框 -->
<template>
  <ele-tree-select
    clearable
    :value="value || ''"
    :data="treeData"
    label-key="name"
    value-key="id"
    default-expand-all
    :placeholder="placeholder"
    @input="updateValue"
  />
</template>

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