<template>
  <t-input-number
    v-model="valueData"
    theme="normal"
    :disabled="!config.writable"
    style="width: 100%"
    @change="emitChange"
    :min="0"
    :max="999999"
    :decimalPlaces="decimalPlaces"
    :allowInputOverLimit="false"
  ></t-input-number>
</template>
<script setup name="NUMBER">
import { ref, watch, computed } from 'vue';
const props = defineProps({
  config: { type: Object },
  modelValue: { type: Number },
});
//需要支持只能输入整数的控件
const integerWidgetArr = ['import_exam_student_count_2'];
const decimalPlaces = computed(() => {
  return integerWidgetArr.includes(props.config.formName) ? 0 : undefined;
});
const emit = defineEmits(['update:modelValue', 'change']);

const valueData = ref(null);

const emitChange = () => {
  emit('update:modelValue', valueData.value);
  emit('change', valueData.value);
};
watch(
  () => props.modelValue,
  (val, oldval) => {
    if (val === oldval) return;
    valueData.value = val || undefined;
  },
  {
    immediate: true,
  }
);
</script>
