feat: CurrencyInput em todos os campos de valor monetário
Input digit-by-digit em centavos com formatação BRL automática. Substitui amountRaw/initialRaw + parseAmount nas 3 views. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useAccountsStore, type AccountInput } from '@/stores/accounts'
|
||||
import NeonPanel from '@/components/NeonPanel.vue'
|
||||
import CurrencyInput from '@/components/CurrencyInput.vue'
|
||||
|
||||
const store = useAccountsStore()
|
||||
onMounted(() => store.fetchAll())
|
||||
@@ -16,13 +17,8 @@ const typeLabels: Record<string, string> = {
|
||||
const blank = (): AccountInput => ({ name: '', type: 'checking', initial_balance: 0, yield_type: 'none', closing_day: null, due_day: null })
|
||||
const form = ref(blank())
|
||||
const editId = ref<number | null>(null)
|
||||
const initialRaw = ref('')
|
||||
const formError = ref<string | null>(null)
|
||||
|
||||
function parseAmount(s: string) {
|
||||
return parseFloat(s.replace(/\./g, '').replace(',', '.')) || 0
|
||||
}
|
||||
|
||||
function startEdit(id: number) {
|
||||
const a = store.accounts.find((x) => x.id === id)
|
||||
if (!a) return
|
||||
@@ -33,7 +29,6 @@ function startEdit(id: number) {
|
||||
closing_day: a.closing_day ?? null,
|
||||
due_day: a.due_day ?? null,
|
||||
}
|
||||
initialRaw.value = a.initial_balance.toLocaleString('pt-BR', { minimumFractionDigits: 2 })
|
||||
formError.value = null
|
||||
}
|
||||
|
||||
@@ -45,13 +40,11 @@ async function payBill(billId: number) {
|
||||
function cancelEdit() {
|
||||
editId.value = null
|
||||
form.value = blank()
|
||||
initialRaw.value = ''
|
||||
formError.value = null
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
formError.value = null
|
||||
form.value.initial_balance = parseAmount(initialRaw.value)
|
||||
try {
|
||||
if (editId.value !== null) {
|
||||
await store.update(editId.value, form.value)
|
||||
@@ -59,7 +52,6 @@ async function submit() {
|
||||
} else {
|
||||
await store.create(form.value)
|
||||
form.value = blank()
|
||||
initialRaw.value = ''
|
||||
}
|
||||
} catch (e: any) {
|
||||
formError.value = e.message
|
||||
@@ -110,9 +102,8 @@ function totalBalance() {
|
||||
<input type="number" v-model.number="form.due_day" min="1" max="28" class="fc-input fc-acc-form__day" />
|
||||
</div>
|
||||
</template>
|
||||
<input
|
||||
v-model="initialRaw"
|
||||
placeholder="Saldo inicial (ex: 1.500,00)"
|
||||
<CurrencyInput
|
||||
v-model="form.initial_balance"
|
||||
class="fc-input fc-acc-form__balance"
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user