<template>
    <el-select
        v-bind="$attrs"
        v-on="$listeners"
    >
        <el-option
                v-for="item in currentOptions"
                :key="item[valueKey]"
                :label="item[labelKey]"
                :value="item[valueKey]"
        ></el-option>
    </el-select>
</template>

<script>
import Select from '../../select'
import Option from '../../option'
export default {
    name: 'ElDictSelect',
    components: {
        Select,
        Option
    },
    props: {
        options: {
            type: Array,
            default: () => []
        },
        type: {
            type: String,
            default: ''
        },
        filter: Function,
        labelKey: {
            type: String,
            default: 'dictLabel'
        },
        valueKey: {
            type: String,
            default: 'dictValue'
        }
    },
    computed: {
        currentOptions() {
            if (this.type) {
                return this.getOptions(this.type)
            }
            return this.options
        }
    },
    methods: {
        getOptions(type) {
            if (this.$ELEMENT.dictSelect.getOptions) {
                if (this.filter) {
                    return this.$ELEMENT.dictSelect.getOptions(type)
                }
                return this.$ELEMENT.dictSelect.getOptions(type)
            }
            console.log(new Error('请实现数据字典getOptions方法'))
            return []
        }
    }
}
</script>

<style scoped>

</style>
