fix: comma input behavior

This commit is contained in:
puriphatt 2024-12-25 15:47:25 +07:00
parent 61501dba8d
commit 889d4afbf5
6 changed files with 113 additions and 50 deletions

View file

@ -10,9 +10,13 @@ const price = defineModel<number>('price');
const vatIncluded = defineModel<boolean>('vatIncluded');
const calcVat = defineModel<boolean>('calcVat');
const price4Show = ref('');
const agentPrice4Show = ref('');
const serviceCharge4Show = ref('');
const price4Show = ref<string>(commaInput(price.value?.toString() || '0'));
const agentPrice4Show = ref<string>(
commaInput(agentPrice.value?.toString() || '0'),
);
const serviceCharge4Show = ref<string>(
commaInput(serviceCharge.value?.toString() || '0'),
);
const column = [
{
@ -194,17 +198,21 @@ withDefaults(
:borderless="readonly"
hide-bottom-space
input-class="text-right"
debounce="500"
:model-value="commaInput(price?.toString() || '0')"
:model-value="price4Show"
@blur="
() => {
price = Number(price4Show.replace(/,/g, ''));
if (price % 1 === 0) {
const [, dec] = price4Show.split('.');
if (!dec) {
price4Show += '.00';
}
}
}
"
@update:model-value="
(v) => {
if (typeof v === 'string') price4Show = commaInput(v);
const x = parseFloat(
price4Show && typeof price4Show === 'string'
? price4Show.replace(/,/g, '')
: '',
);
price = x;
price4Show = commaInput(v?.toString() || '0', 'string');
}
"
/>
@ -218,17 +226,24 @@ withDefaults(
:borderless="readonly"
hide-bottom-space
input-class="text-right"
debounce="500"
:model-value="commaInput(agentPrice?.toString() || '0')"
:model-value="agentPrice4Show"
@blur="
() => {
agentPrice = Number(agentPrice4Show.replace(/,/g, ''));
if (agentPrice % 1 === 0) {
const [, dec] = agentPrice4Show.split('.');
if (!dec) {
agentPrice4Show += '.00';
}
}
}
"
@update:model-value="
(v) => {
if (typeof v === 'string') agentPrice4Show = commaInput(v);
const x = parseFloat(
agentPrice4Show && typeof agentPrice4Show === 'string'
? agentPrice4Show.replace(/,/g, '')
: '',
agentPrice4Show = commaInput(
v?.toString() || '0',
'string',
);
agentPrice = x;
}
"
/>
@ -242,19 +257,26 @@ withDefaults(
:borderless="readonly"
input-class="text-right"
hide-bottom-space
debounce="500"
:model-value="commaInput(serviceCharge?.toString() || '0')"
:model-value="serviceCharge4Show"
@blur="
() => {
serviceCharge = Number(
serviceCharge4Show.replace(/,/g, ''),
);
if (serviceCharge % 1 === 0) {
const [, dec] = serviceCharge4Show.split('.');
if (!dec) {
serviceCharge4Show += '.00';
}
}
}
"
@update:model-value="
(v) => {
if (typeof v === 'string')
serviceCharge4Show = commaInput(v);
const x = parseFloat(
serviceCharge4Show &&
typeof serviceCharge4Show === 'string'
? serviceCharge4Show.replace(/,/g, '')
: '',
serviceCharge4Show = commaInput(
v?.toString() || '0',
'string',
);
serviceCharge = x;
}
"
/>