<template>
  <el-select
    v-model="selected"
    :placeholder="placeholder"
    :clearable="clearable"
    :multiple="multiple"
    :disabled="disabled"
    @change="change"
  >
    <el-option
      v-for="dict in getDictDatas(DICT_TYPE[dictType])"
      :key="dict.value"
      :label="dict.label"
      :value="dict.value"
    />
  </el-select>
</template>

<script>
export default {
  props: {
    // eslint-disable-next-line vue/require-prop-types
    value: {
      required: true
    },
    dictType: {
      type: String,
      required: true
    },
    placeholder: {
      type: String,
      default: '请选择'
    },
    clearable: {
      type: Boolean,
      default: true
    },
    multiple: {
      type: Boolean,
      default: false
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    selected: {
      get() {
        const reg = /^[0-9]+.?[0-9]*/
        return reg.test(this.value) ? this.value + '' : this.value
      },
      set(v) {
        this.$emit('input', v)
      }
    }
  },
  methods: {
    change(v) {
      this.$emit('change', v)
    }
  }
}
</script>
