<template>
  <view>
    <uni-easyinput :value="value" type="text" placeholder="请输入" @input="$emit('on-change', $event)" v-if="config.type === 'input'" />

    <uni-datetime-picker type="datetime" :value="value" :modelValue="value" @change="$emit('on-change', $event)"
                         v-else-if="config.type === 'datetime'" />

    <uni-data-checkbox :value="value" :localdata="config.range" @change="$emit('on-change', $event.detail.value)"
                       v-else-if="config.type === 'radio'" />

    <uni-data-select :value="value" :modelValue="value" :localdata="config.range" @change="$emit('on-change', $event)"
                     v-else-if="config.type === 'select'"></uni-data-select>
  </view>
</template>

<script lang="ts" setup>
import { CODE_DICT } from '@/config/code'
import { computed } from 'vue'

interface IConfig {
  text: string
  type: string
  default: string
  range?: { value: string, text: string }[]
  showType?: {
    type: string
    code: string
    value: string
  }
}
interface IProps {
  code: string
  value: string
}

const props = defineProps<IProps>()
defineEmits(['on-change'])

const config = computed<IConfig>(() => CODE_DICT[props.code])
</script>

<style lang="scss" scoped>
</style>
