<template>
  <div>
    <template v-for="(item, index) in CurrOptions">
      <span :style="{ color: color, background: bgc }" v-if="item.elTagType == 'default' || item.elTagType == '' || tag == false
      " :key="item.value" :index="index" :class="item.elTagType">
        {{ item.label }}{{ index == CurrOptions.length - 1 ? '' : ', ' }}
      </span>
      <el-tag v-else :style="{ color: color, background: bgc }" :disable-transitions="true" :key="item.value + ''"
        :index="index" :type="item.elTagType === 'primary' ? '' : item.elTagType" :class="item.elTagType">
        {{ item.label }}
      </el-tag>
    </template>
  </div>
</template>

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

const props = defineProps({
  // 数据
  options: {
    type: Array,
    default: null
  },
  tag: false,
  value: [Number, String, Array],
  color: {
    type: String,
    default: '#000'
  },
  bgc: {
    type: String,
    default: 'rgba(0,0,0,0)'
  },
  toArr: {
    type: Boolean,
    default: false
  }
});
const values = computed(() => {
  if (props.value !== null && typeof props.value !== "undefined") {
    if (props.toArr && typeof props.value === 'string') return props.value ? props.value.split(',') : []
    return Array.isArray(props.value) ? props.value : [String(props.value)];
  } else {
    return [];
  }
});

/**可见选项 需要回显的内容 */
const CurrOptions = computed(() => {
  const optionsArr = Array.isArray(props.options) ? props.options : [];
  return optionsArr.filter(item => values.value.includes(item.value));
});
</script>
