Skip to content

Commit

Permalink
display amounts according to currency decimals number count
Browse files Browse the repository at this point in the history
  • Loading branch information
mayswind committed Dec 6, 2024
1 parent e2f2b32 commit e549779
Show file tree
Hide file tree
Showing 15 changed files with 313 additions and 23 deletions.
14 changes: 11 additions & 3 deletions src/components/desktop/AmountInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default {
'color',
'density',
'currency',
'showCurrency',
'label',
'placeholder',
'persistentPlaceholder',
Expand Down Expand Up @@ -100,7 +101,7 @@ export default {
return finalClass;
},
prependText() {
if (!this.currency) {
if (!this.currency || !this.showCurrency) {
return '';
}
Expand All @@ -113,7 +114,7 @@ export default {
return texts.prependText;
},
appendText() {
if (!this.currency) {
if (!this.currency || !this.showCurrency) {
return '';
}
Expand All @@ -127,6 +128,13 @@ export default {
}
},
watch: {
'currency': function () {
const newStringValue = this.getFormattedValue(this.userStore, this.modelValue);
if (!(newStringValue === '0' && this.currentValue === '')) {
this.currentValue = newStringValue;
}
},
'modelValue': function (newValue) {
const numericCurrentValue = this.$locale.parseAmount(this.userStore, this.currentValue);
Expand Down Expand Up @@ -300,7 +308,7 @@ export default {
getFormattedValue(userStore, value) {
if (!Number.isNaN(value) && Number.isFinite(value)) {
const digitGroupingSymbol = this.$locale.getCurrentDigitGroupingSymbol(userStore);
return removeAll(this.$locale.formatAmount(userStore, value), digitGroupingSymbol);
return removeAll(this.$locale.formatAmount(userStore, value, this.currency), digitGroupingSymbol);
}
return '0';
Expand Down
20 changes: 18 additions & 2 deletions src/components/mobile/NumberPadSheet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@
<f7-button class="numpad-button numpad-button-function no-right-border" @click="setSymbol('+')">
<span class="numpad-button-text numpad-button-text-normal">&plus;</span>
</f7-button>
<f7-button class="numpad-button numpad-button-num" @click="inputDecimalSeparator()">
<f7-button class="numpad-button numpad-button-num" v-if="supportDecimalSeparator" @click="inputDecimalSeparator()">
<span class="numpad-button-text numpad-button-text-normal">{{ decimalSeparator }}</span>
</f7-button>
<f7-button class="numpad-button numpad-button-num" v-if="!supportDecimalSeparator" @click="inputDoubleNum(0)">
<span class="numpad-button-text numpad-button-text-normal">00</span>
</f7-button>
<f7-button class="numpad-button numpad-button-num" @click="inputNum(0)">
<span class="numpad-button-text numpad-button-text-normal">0</span>
</f7-button>
Expand All @@ -66,13 +69,15 @@
import { mapStores } from 'pinia';
import { useUserStore } from '@/stores/user.js';
import currencyConstants from '@/consts/currency.js';
import { isString, isNumber, removeAll } from '@/lib/common.js';
export default {
props: [
'modelValue',
'minValue',
'maxValue',
'currency',
'show'
],
emits: [
Expand All @@ -94,6 +99,13 @@ export default {
decimalSeparator() {
return this.$locale.getCurrentDecimalSeparator(this.userStore);
},
supportDecimalSeparator() {
if (!this.currency || !currencyConstants.all[this.currency] || !isNumber(currencyConstants.all[this.currency].fraction)) {
return true;
}
return currencyConstants.all[this.currency].fraction > 0;
},
currentDisplay() {
const previousValue = this.$locale.appendDigitGroupingSymbol(this.userStore, this.previousValue);
const currentValue = this.$locale.appendDigitGroupingSymbol(this.userStore, this.currentValue);
Expand Down Expand Up @@ -129,7 +141,7 @@ export default {
return '';
}
let str = this.$locale.formatAmount(userStore, value);
let str = this.$locale.formatAmount(userStore, value, this.currency);
const digitGroupingSymbol = this.$locale.getCurrentDigitGroupingSymbol(userStore);
Expand Down Expand Up @@ -208,6 +220,10 @@ export default {
this.currentValue = newValue;
},
inputDoubleNum(num) {
this.inputNum(num);
this.inputNum(num);
},
inputDecimalSeparator() {
if (this.currentValue.indexOf(this.decimalSeparator) >= 0) {
return;
Expand Down
Loading

0 comments on commit e549779

Please sign in to comment.