<template>
  <el-form-item :label="label" :rules="requireRule(!disabled && required, label)" :prop="prop">
    <el-select
      ref="select"
      v-model="$parent.model[prop]"
      :multiple="multiple" :clearable="clearable" filterable :disabled="disabled">
      <el-option :label="emptyLabel" :value="undefined" key="select"/>
      <el-option v-for="item in dict[dictType]" :key="item.value" :value="item.value"  :label="item.label"/>
    </el-select>
  </el-form-item>
</template>

<script>
import mixin from './mixin'
import { mapGetters } from 'vuex'
/**
 * 下拉框组件
 */
export default {
  mixins: [mixin],
  props: {
    multiple: {
      type: Boolean,
      default: false
    },
    dictType: {
      type: String,
      required: true
    },
    emptyLabel: {
      type: String,
      default: '全部'
    }
  },
  computed: {
    ...mapGetters(['dict']),
    selectedLabel(){
      return this.$refs.select?.selectedLabel
    }
  }
}
</script>
