account edit page displays the debt amount instead of the balance for credit card and debt accounts

This commit is contained in:
MaysWind
2025-02-11 00:45:23 +08:00
parent 18a6d25ed6
commit ab58109e5e
12 changed files with 133 additions and 28 deletions
+30 -3
View File
@@ -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<string>(getFormattedValue(props.modelValue));
const currentValue = ref<string>(getInitedFormattedValue(props.modelValue, props.flipNegative));
const prependText = computed<string | undefined>(() => {
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);
}
});
</script>
+22 -5
View File
@@ -66,7 +66,7 @@
</template>
<script setup lang="ts">
import { ref, computed } from 'vue';
import { ref, computed, watch } from 'vue';
import { useI18n } from '@/locales/helpers.ts';
import { useI18nUIComponents } from '@/lib/ui/mobile.ts';
@@ -75,10 +75,11 @@ import { ALL_CURRENCIES } from '@/consts/currency.ts';
import { isString, isNumber, removeAll } from '@/lib/common.ts';
const props = defineProps<{
modelValue: number | string;
modelValue: number;
minValue?: number;
maxValue?: number;
currency?: string;
flipNegative?: boolean;
show: boolean;
}>();
@@ -99,7 +100,7 @@ const { showToast } = useI18nUIComponents();
const previousValue = ref<string>('');
const currentSymbol = ref<string>('');
const currentValue = ref<string>(getStringValue(props.modelValue));
const currentValue = ref<string>(getInitedStringValue(props.modelValue, props.flipNegative));
const decimalSeparator = computed<string>(() => getCurrentDecimalSeparator());
@@ -140,6 +141,14 @@ const confirmText = computed<string>(() => {
}
});
function getInitedStringValue(value: number, flipNegative?: boolean): string {
if (flipNegative) {
value = -value;
}
return getStringValue(value);
}
function getStringValue(value: number | string): string {
if (!isNumber(value) && !isString(value)) {
return '';
@@ -333,7 +342,11 @@ function confirm(): boolean {
return true;
} else {
const value = parseAmount(currentValue.value);
let value: number = parseAmount(currentValue.value);
if (props.flipNegative) {
value = -value;
}
emit('update:modelValue', value);
close();
@@ -347,12 +360,16 @@ function close(): void {
}
function onSheetOpen(): void {
currentValue.value = getStringValue(props.modelValue);
currentValue.value = getInitedStringValue(props.modelValue, props.flipNegative);
}
function onSheetClosed(): void {
close();
}
watch(() => props.flipNegative, (newValue) => {
currentValue.value = getInitedStringValue(props.modelValue, newValue);
});
</script>
<style>