<template>
  <div>
    <template v-for="(item, index) in options">
      <template v-if="values.includes(item.value)">
        <span
          v-if="!item.elTagType || !props.tag"
          class="tag-label"
          :key="item.value"
          :index="index"
          :class="item.elTagClass"
        >{{ item.label }}</span>
        <van-tag
          v-else
          :disable-transitions="true"
          :key="item.value + ''"
          :index="index"
          :plain="props.plain"
          round
          size="medium"
          :type="(item.elTagType === 'info' ? 'default' : item.elTagType) || ''"
          class="van-tag"
        >{{ item.label }}</van-tag>
      </template>
    </template>
  </div>
</template>

<script setup lang="ts" name="DictTag">
import { computed } from 'vue'
// import type { TagSize, TagType, TagProps } from 'vant'

interface IOptions extends TagProps {
  elTagType: TagType | 'info' | ''
  elTagClass?: string
  label: string
  value: number | string
}

const props = withDefaults(defineProps<{
  options: Array<IOptions> // 数据
  plain?: boolean
  value: number | string | null | undefined | any[]
  tag?: boolean
}>(), {
  plain: true,
  tag: true
})

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

</script>

<style lang="less" scoped>
.van-tag + .van-tag {
  margin-left: 10px;
}

.tag-label {
  font-size: 24rpx;
} 
</style>