<template>
  <div>
    <template v-for="(item, index) in options">
      <template v-if="values.includes(item.value)">
        <span
          v-if="item.elTagType == 'default' || item.elTagType == '' || tag == false"
          :key="item.value"
          :index="index"
          :class="item.elTagType"
          @click="handleItem(item)"
          :style="{color: props.color}"
          >{{ item.label || item.zdmc }}</span>
        <el-tag
          v-else
          :disable-transitions="true"
          :key="item.value + ''"
          :index="index"
          :type="item.elTagType === 'primary' ? '' : item.elTagType"
          @click="handleItem(item)"
          :class="item.elTagType"
          >{{ item.label || item.zdmc }}</el-tag
        >
      </template>
    </template>
  </div>
</template>

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

const props = defineProps({
  // 数据
  options: {
    type: Array,
    default: null
  },
  color:{
    type:String,
    default:'#6f6f74'
  },
  tag: false,
  value: [Number, String, Array]
});

const emit = defineEmits(['clickTag'])

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

// 处理数据
const handleItem  = (item) =>{
  emit('clickTag',item)
}
</script>

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