From ab58109e5ece57ad682121b3c14ff312ae681734 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Tue, 11 Feb 2025 00:45:23 +0800 Subject: [PATCH] account edit page displays the debt amount instead of the balance for credit card and debt accounts --- src/components/desktop/AmountInput.vue | 33 +++++++++++++++-- src/components/mobile/NumberPadSheet.vue | 27 +++++++++++--- src/core/account.ts | 24 +++++++----- src/locales/de.json | 2 + src/locales/en.json | 2 + src/locales/es.json | 2 + src/locales/ru.json | 2 + src/locales/vi.json | 2 + src/locales/zh_Hans.json | 2 + src/models/account.ts | 37 +++++++++++++++++-- .../accounts/list/dialogs/EditDialog.vue | 13 ++++++- src/views/mobile/accounts/EditPage.vue | 15 ++++++-- 12 files changed, 133 insertions(+), 28 deletions(-) diff --git a/src/components/desktop/AmountInput.vue b/src/components/desktop/AmountInput.vue index 320ba270..a1d3d0d9 100644 --- a/src/components/desktop/AmountInput.vue +++ b/src/components/desktop/AmountInput.vue @@ -53,6 +53,7 @@ const props = defineProps<{ readonly?: boolean; hide?: boolean; enableRules?: boolean; + flipNegative?: boolean; modelValue: number; }>(); @@ -90,7 +91,7 @@ const rules = [ } ]; -const currentValue = ref(getFormattedValue(props.modelValue)); +const currentValue = ref(getInitedFormattedValue(props.modelValue, props.flipNegative)); const prependText = computed(() => { if (!props.currency || !props.showCurrency) { @@ -292,6 +293,14 @@ function getValidFormattedValue(value: number, textualValue: string, hasDecimalS return textualValue; } +function getInitedFormattedValue(value: number, flipNegative?: boolean): string { + if (flipNegative) { + value = -value; + } + + return getFormattedValue(value); +} + function getFormattedValue(value: number): string { if (!Number.isNaN(value) && Number.isFinite(value)) { const digitGroupingSymbol = getCurrentDigitGroupingSymbol(); @@ -309,7 +318,15 @@ function getDisplayCurrencyPrependAndAppendText(): CurrencyPrependAndAppendText } watch(() => props.currency, () => { - const newStringValue = getFormattedValue(props.modelValue); + const newStringValue = getInitedFormattedValue(props.modelValue, props.flipNegative); + + if (!(newStringValue === '0' && currentValue.value === '')) { + currentValue.value = newStringValue; + } +}); + +watch(() => props.flipNegative, (newValue) => { + const newStringValue = getInitedFormattedValue(props.modelValue, newValue); if (!(newStringValue === '0' && currentValue.value === '')) { currentValue.value = newStringValue; @@ -317,6 +334,10 @@ watch(() => props.currency, () => { }); watch(() => props.modelValue, (newValue) => { + if (props.flipNegative) { + newValue = -newValue; + } + const numericCurrentValue = parseAmount(currentValue.value); if (newValue !== numericCurrentValue) { @@ -346,7 +367,13 @@ watch(currentValue, (newValue) => { if (finalValue !== newValue) { currentValue.value = finalValue; } else { - emit('update:modelValue', parseAmount(finalValue)); + let value: number = parseAmount(finalValue); + + if (props.flipNegative) { + value = -value; + } + + emit('update:modelValue', value); } }); diff --git a/src/components/mobile/NumberPadSheet.vue b/src/components/mobile/NumberPadSheet.vue index 40003f3e..a1346c76 100644 --- a/src/components/mobile/NumberPadSheet.vue +++ b/src/components/mobile/NumberPadSheet.vue @@ -66,7 +66,7 @@