<template>
  <template v-for="(item, index) in props.options" :key="item.dictionary_guid">
    <template v-if="values.includes(item.dictionary_value)">
      <span v-if="item.dictionary_list_class == 'default' || item.dictionary_list_class == ''" :key="item.dictionary_value" :index="index" :class="item.cssClass">
        {{ item.dictionary_name }} <i v-if="showValue">#{{ item.dictionary_value }}</i>
      </span>
      <el-tag
        v-else
        :disable-transitions="true"
        :index="index"
        :type="item.dictionary_list_class == 'primary' ? '' : item.dictionary_list_class"
        :class="item.cssClass">
        {{ item.dictionary_name }}
        <i v-if="showValue">#{{ item.dictionary_value }}</i>
      </el-tag>
    </template>
  </template>
</template>

<script setup>
import {computed} from 'vue';

const props = defineProps({
  // 数据
  options: {
    type: Array,
    default: null,
  },
  // 当前的值
  value: [Number, String, Array, Boolean],
  showValue: false,
})

const values = computed(() => {
  if (props.value !== null && typeof props.value !== 'undefined') {
    return Array.isArray(props.value) ? props.value : [String(props.value)]
  } else {
    return []
  }
})
</script>

<style scoped>
.el-tag + .el-tag {
  margin-left: 10px;
}
</style>
