From 6f887edd4215410c4821cf3cf616d04297ef92b2 Mon Sep 17 00:00:00 2001 From: puriphatt Date: Fri, 25 Oct 2024 15:18:50 +0700 Subject: [PATCH] fix: comma input --- .../components/employer/EmployerFormAbout.vue | 3 ++- src/stores/utils/index.ts | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pages/03_customer-management/components/employer/EmployerFormAbout.vue b/src/pages/03_customer-management/components/employer/EmployerFormAbout.vue index 00bbb70c..a97e9932 100644 --- a/src/pages/03_customer-management/components/employer/EmployerFormAbout.vue +++ b/src/pages/03_customer-management/components/employer/EmployerFormAbout.vue @@ -228,7 +228,8 @@ watch( :model-value="authorizedCapital" @update:model-value=" (v) => { - if (typeof v === 'string') authorizedCapital = commaInput(v); + if (typeof v === 'string') + authorizedCapital = commaInput(v, 'string'); } " /> diff --git a/src/stores/utils/index.ts b/src/stores/utils/index.ts index c2423210..2d85dda6 100644 --- a/src/stores/utils/index.ts +++ b/src/stores/utils/index.ts @@ -461,7 +461,10 @@ export async function waitAll[]>(arr: T) { return await Promise.all(arr); } -export function commaInput(text: string): string { +export function commaInput( + text: string, + type: 'string' | 'number' = 'number', +): string { if (typeof text !== 'string') return '0'; if (!text) return '0'; @@ -469,7 +472,7 @@ export function commaInput(text: string): string { const parts = num.toString().split('.'); const integerPart = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ','); - const decimalPart = parts[1]?.slice(0, 2) || '00'; + const decimalPart = parts[1]?.slice(0, 2) || (type === 'number' && '00'); return integerPart + (decimalPart ? `.${decimalPart}` : ''); }