<script setup>
// 常用属性：
//   min - 最小数值
//   max - 最大数值
//   readonly - 是否只读
//   allowEmpty - 是否允许为空
//   placeholder - 占位文字
//   mode - 模式 "decimal" | "currency"
//   size <string|number> - 数字个数1, 2, 3...
//   name <string> 字段名

// TODO 支持maxlength
// TODO 实现change事件

import InputNumber from "primevue/inputnumber";
import T from "./T.js"
import {ref} from "vue";

const props = defineProps({
	format: false,
	size: "",
	name: ""
})
const valueRef = ref(0)
const emits = defineEmits(["input"])

let format = props.format
if (T.isNull(format)) {
	format = false
}

const numberSize = ref()
if (typeof props.size === "number") {
	numberSize.value = props.size.toString()
} else if (typeof props.size === "string" && props.size.match(/^\d+$/)) {
	numberSize.value = props.size
} else if (T.isNull(props.size)) {
	numberSize.value = "8"
}

const onInput = e => {
	emits("input", e.value)
}

</script>

<template>
	<InputNumber v-model="valueRef" v-model:format="format" :pt="{pcInput:{root:{size:numberSize, name:name}}}"
				 @input="onInput"></InputNumber>
</template>

<style scoped>

</style>