<template>
  <el-col :xl="span" :lg="lgSpan" :md="mdSpan" :sm="smSpan" :xs="xsSpan">
    <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" value-key="value" collapse-tags @change="val => $emit('change', val)">
        <el-option v-for="item in data" :key="item.value" :value="item" :label="item.label" :title="item.label"/>
      </el-select>
    </el-form-item>
  </el-col>
</template>

<script>
import mixin from '../../../../components/CustomElement/mixin'

import {mapGetters} from 'vuex'

/**
 * 下拉框组件
 */
export default {
  mixins: [mixin],
  props: {
    multiple: {
      type: Boolean,
      default: false
    },
    showEmpty: {
      type: Boolean,
      default: false
    },
    emptyLabel: {
      type: String,
      default: '全部'
    },
    dictType: {
      type: String,
      required: true,
    },
    //查询参数1
    param: {
      type: String,
      default: ''
    },
    setFirst: {
      type: Boolean,
      default: true
    },
    span: {
      type: Number,
      default: 8
    },
    exclude: {
      type: Array,
      default: () => []
    },
    lgSpan: {
      type: Number,
      default: 8
    },
    mdSpan: {
      type: Number,
      default: 8
    },
    smSpan: {
      type: Number,
      default: 12
    },
    xsSpan: {
      type: Number,
      default: 24
    },
    filter: {
      type: Function
    }
  },
  data() {
    return {
      data: []

    }
  },
  computed: {
    ...mapGetters(['dict']),
  },
  created() {
    this.data = this.dict[this.dictType]
    .filter(item => !this.exclude.includes(item.value) && (!this.filter || this.filter(item)))
  }
}
</script>
