<template>
  <span v-if="mode === 'look'">{{ text || props.formItem.defaultValue || '-' }}</span>
  <el-input
    v-else
    v-model="text"
    :type="formItem.inputState"
    :disabled="disabled"
    placeholder="请输入"
  />
</template>

<script setup lang="ts">
import { computed } from 'vue'

const emits = defineEmits(['update:modelValue'])
const props = defineProps({
  modelValue: {
    type: [String, Number],
    default: ''
  },
  formItem: {
    type: Object,
    default: () => {}
  },
  mode: {
    type: String,
    default: 'add'
  },
  disabled: {
    type: Boolean,
    default: false
  }
})

const text = computed({
  get() {
    return props.modelValue
  },
  set(val) {
    emits(
      'update:modelValue',
      props.formItem.fieldType === 1 && !isNaN(Number(val)) && val ? Number(val) : val
    )
  }
})
</script>
