<template>
  <span v-if="displayLabel">{{ displayLabel }}</span>
  <span v-else>-</span>
</template>

<script>
import {mapGetters} from 'vuex'

export default {
  name: 'EnumTag',
  props: {
    // 枚举类型：relationType | certType
    type: {
      type: String,
      required: true
    },
    // 枚举值
    value: {
      type: [String, Number],
      default: ''
    }
  },
  computed: {
    ...mapGetters('ccdiEnum', ['relationTypeOptions', 'certTypeOptions']),

    // 获取对应的选项列表
    options() {
      switch (this.type) {
        case 'relationType':
          return this.relationTypeOptions
        case 'certType':
          return this.certTypeOptions
        default:
          return []
      }
    },

    // 查找对应的显示标签
    displayLabel() {
      if (!this.value) return ''
      const option = this.options.find(item => item.value === this.value)
      return option ? option.label : this.value
    }
  }
}
</script>
