<template>
    <text :class="getStatus.class">{{ getStatus.text }}</text>
</template>

<script setup>
import { computed } from 'vue'
import * as dictData from './dictData'
import { cloneDeep } from 'lodash'
const ps = defineProps({
    dictkey: {
        type: String,
        default: ''
    },
    options: {
        type: Array,
        default: () => {
            return []
        }
    },
    value: {
        type: [String, Number],
        default: ''
    },
    valueField: {
        type: String,
        default: 'value'
    }
})
const getData = computed(() => {
    if (ps.dictkey) {
        if (dictData[ps.dictkey]) {
            return cloneDeep(dictData[ps.dictkey])
        } else {
            throw new Error('请输入存在的dictkey值')
        }
    } else {
        return ps.options || []
    }
})
const getStatus = computed(() => {
    const data = getData.value.find((item) => item[ps.valueField] == ps.value)
    return data || {}
})
</script>
<style lang="scss" scoped></style>
