<template>
  <el-cascader ref="cascader" :span="24" v-model="deptparam" :options="orderData" :props="defaultProps" style="width: 100%;" placeholder="请选择部门" filterable clearable @change="handleChange"/>
</template>

<script>
import {
  getDeptTree
} from '@/api/systemSetup/roleSetting/userManage'
export default {
  name: 'SelectDeptTree',
  props: {
    deptparam: {
      type: Array,
      default: []
    },
    deptparamName: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      defaultProps: {
        checkStrictly: true,
        children: 'children',
        label: 'text',
        value: 'id'
      },
      // deptids: [],
      parentid: '-1',
      orderData: []
    }
  },
  watch: {

  },
  created() {
    // 默认数据加载
    this.getTreeList()
  },
  methods: {
    getTreeList() {
      return new Promise((resolve) => {
        getDeptTree(this.parentid).then((response) => {
          if (response.state.toLowerCase() === 'success') {
            this.orderData = response.data
          }
        })
        resolve()
      })
    },
    handleChange(data) {
      console.log(data)
      // console.log(Number(data[data.length - 1]))
      this.$emit('post-deptid', data)
      // this.$emit('post-deptid',Number(data[data.length - 1]))
    }
  }
}
</script>

<style>

</style>
