<!--
 * @Author: 曹捷
 * @Date: 2020-04-16 15:05:48
 * @LastEditors: 曹捷
 * @LastEditTime: 2021-03-23 15:44:12
 * @Description: 机构 组件
 -->
<template>
  <obit-cascader :disabled="disabled" valueName="orgId" label="orgName" children="childs" :options="orgList"
    expand-trigger="hover" v-if="orgList.length>0" changeOnSelect v-model:value="orgId" placeholder="请选择机构">
  </obit-cascader>
</template>

<script>
import obitCascader from './../obit-cascader/obit-cascader.vue'
export default {
  components: { obitCascader },
  props: {
    value: {
      type: [Number, String]
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  watch: {
    value (newValue, oldValue) {
      if (!oldValue && newValue) {
        this.orgId = newValue
      }
    },
    orgId (value) {
      this.$emit('update:value', value)
    }
  },
  data () {
    return {
      orgId: '',
      orgList: []
    }
  },
  methods: {
    getOrgList () {
      this.$http.getAllOrgTree().then(res => {
        this.orgList = res
      })
    }
  },
  mounted () {
    this.orgId = this.value
    this.getOrgList()
  }
}
</script>

<style>
</style>