<template>
  <el-table-column :label="label" :prop="prop" :align="align" :min-width="minWidth">
    <template v-slot="scope">
      <el-select v-model="scope.row[prop]"
                 :clearable="clearable"
                 :disabled="disabled"
                 :multiple="multiple"
                 :placeholder="$t('common.pleaseSelect')"
                 collapse-tags
                 filterable
                 width="100%"
                 size="small"
                 @change="val => $emit('change', val)">
        <el-option
          v-for="item in searchDict"
          :key="item[`${valueProp}`]"
          :label="initDictLabel(item)"
          :value="String(item[`${valueProp}`])"
        >
        </el-option>
      </el-select>
    </template>
  </el-table-column>
</template>

<script>

export default {
  name: "DictSelectColumn",
  props: {
    valueProp: {
      type: String,
      default: "value",
    },
    labelProp: {
      type: String,
      default: "label",
    },
    searchDict: {
      type: Array,
      default: () => []
    },
    multiple: {
      type: Boolean,
      default: false
    },
    clearable: {
      type: Boolean,
      default: true
    },
    label: {
      type: String,
      default: "",
    },
    prop: {
      type: String,
    },
    minWidth: {
      type: Number,
      default: 150,
    },
    disabled:{
      type:Boolean,
      default:false,
    },
    align:{
      type:String,
      default:'center',
    },
    customHeight:{
      type:String,
      default:'',
    },
  },

  data() {
    return {
      data: []

    }
  },
  computed: {
    initDictLabel(item){
      return function (item) {
        const currentLocale = window.VueI18n.locale;
        if(currentLocale === 'chinese'){
          return item['label']||item[this.labelProp];
        }
        if(currentLocale === 'english'){
          return item['dictLabelUS'] || item[this.labelProp];
        }
        if(currentLocale === 'russia'){
          return item['dictLabelRU'] || item[this.labelProp];
        }
        if(currentLocale === 'spanish'){
          return item['dictLabelES'] || item[this.labelProp];
        }
      }
    },
  },
  created() {
  }

};
</script>


