<template>
  <el-select
    slot="prepend"
    v-model="value"
    :placeholder="title"
    :multiple="multiple"
    clearable
    filterable
    :size="size"
    @change="updateValue"
  >
    <el-option
      v-for="item in data"
      :key="item.Id"
      :label="item.Name"
      :value="item.Id"
    />
  </el-select>
</template>
<script>
import { Get, GetDes } from '@/api/enum/enums'
export default {
  name: 'Enums',
  // eslint-disable-next-line vue/require-prop-types
  props: ['model', 'title', 'enumName', 'multiple', 'size', 'getEnum'],
  data() {
    return {
      data: [],
      value: ''
    }
  },
  watch: {
    'model'(newVal, oldVal) {
      this.value = newVal
    }
  },
  mounted() {
    this.value = this.model
    switch (this.getEnum) {
      case 'GetDes':
        GetDes(this.enumName).then(r => { this.data = r })
        break
      default:
        Get(this.enumName).then(r => { this.data = r })
        break
    }
  },
  methods: {
    updateValue(v) {
      this.$emit('update:model', v)
      this.$emit('change', v)
    }

  }
}
</script>
