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>