<template>
  <el-select v-model="selectValue" placeholder="请选择机构" :disabled="disabled" clearable filterable :multiple="multiple" style="width: 100%;" @change="change">
    <el-option v-for="item in organList" :key="item.id" :label="item.name" :value="item.id">
      <span style="float: left">{{ item.name }}</span>
    </el-option>
  </el-select>
</template>

<script>
import organApi from '@/api/organ/organApi'

export default {
  name: 'SelectOrgan',
  props: {
    value: { 
      type: String,
      default: () => {
        return ''
      }
    },
    disabled: {
      type: Boolean,
      default: false
    },
    multiple: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      organList: []
    }
  },
  computed: {
    selectValue: {
      get() {
        return this.value
      },
      set(newValue) {
        this.$emit('input', newValue)
      }
    }
  },
  mounted() {
    // todo 后面增加缓存...
    this.list()
  },
  methods: {
    list() {
      organApi.selectOrgan().then(data => {
        this.organList = data
      })
    },
    change() {
      this.$emit('change')
    }
  }
}
</script>

<style scoped>
</style>
