mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-15 07:27:33 +08:00
code refactor
This commit is contained in:
@@ -109,7 +109,7 @@
|
||||
<v-btn class="px-2 ml-2 mr-3" color="default"
|
||||
density="comfortable" variant="text"
|
||||
:class="{ 'd-none': loading, 'hover-display': !loading }"
|
||||
@click="setAsBaseline(exchangeRate.currencyCode, exchangeRate)">
|
||||
@click="setAsBaseline(exchangeRate.currencyCode, getConvertedAmount(exchangeRate))">
|
||||
{{ $t('Set As Baseline') }}
|
||||
</v-btn>
|
||||
<span>{{ getDisplayConvertedAmount(exchangeRate, isEnableThousandsSeparator) }}</span>
|
||||
@@ -138,7 +138,9 @@ import { useSettingsStore } from '@/stores/setting.js';
|
||||
import { useUserStore } from '@/stores/user.js';
|
||||
import { useExchangeRatesStore } from '@/stores/exchangeRates.js';
|
||||
|
||||
import { isNumber } from '@/lib/common.js';
|
||||
import {
|
||||
stringCurrencyToNumeric,
|
||||
getConvertedAmount,
|
||||
getDisplayExchangeRateAmount
|
||||
} from '@/lib/currency.js';
|
||||
@@ -156,7 +158,7 @@ export default {
|
||||
return {
|
||||
activeTab: 'exchangeRatesPage',
|
||||
baseCurrency: userStore.currentUserDefaultCurrency,
|
||||
baseAmount: '1',
|
||||
baseAmount: 100,
|
||||
loading: true,
|
||||
alwaysShowNav: mdAndUp.value,
|
||||
showNav: mdAndUp.value,
|
||||
@@ -246,23 +248,22 @@ export default {
|
||||
const fromExchangeRate = this.exchangeRatesStore.latestExchangeRateMap[this.baseCurrency];
|
||||
|
||||
try {
|
||||
return getConvertedAmount(parseFloat(this.baseAmount), fromExchangeRate, toExchangeRate);
|
||||
return getConvertedAmount(this.baseAmount / 100, fromExchangeRate, toExchangeRate);
|
||||
} catch (e) {
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
getDisplayConvertedAmount(toExchangeRate, isEnableThousandsSeparator) {
|
||||
if (this.baseAmount === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
const rateStr = this.getConvertedAmount(toExchangeRate).toString();
|
||||
return getDisplayExchangeRateAmount(rateStr, isEnableThousandsSeparator);
|
||||
},
|
||||
setAsBaseline(currency, toExchangeRate) {
|
||||
const rateStr = this.getConvertedAmount(toExchangeRate).toString();
|
||||
setAsBaseline(currency, amount) {
|
||||
if (!isNumber(amount)) {
|
||||
amount = '';
|
||||
}
|
||||
|
||||
this.baseCurrency = currency;
|
||||
this.baseAmount = getDisplayExchangeRateAmount(rateStr, false)
|
||||
this.baseAmount = stringCurrencyToNumeric(amount.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,8 +124,8 @@
|
||||
/>
|
||||
</v-col>
|
||||
<v-col cols="12" md="12" v-if="account.type === allAccountTypes.SingleAccount || currentAccountIndex >= 0">
|
||||
<amount-input persistent-placeholder
|
||||
:disabled="loading || submitting || !!editAccountId"
|
||||
<amount-input :disabled="loading || submitting || !!editAccountId"
|
||||
:persistent-placeholder="true"
|
||||
:currency="selectedAccount.currency"
|
||||
:label="currentAccountIndex < 0 ? $t('Account Balance') : $t('Sub Account Balance')"
|
||||
:placeholder="currentAccountIndex < 0 ? $t('Account Balance') : $t('Sub Account Balance')"
|
||||
@@ -436,14 +436,12 @@ export default {
|
||||
},
|
||||
setAccount(account) {
|
||||
setAccountModelByAnotherAccount(this.account, account);
|
||||
this.account.balance = this.account.balance / 100;
|
||||
this.subAccounts = [];
|
||||
|
||||
if (account.subAccounts && account.subAccounts.length > 0) {
|
||||
for (let i = 0; i < account.subAccounts.length; i++) {
|
||||
const subAccount = this.accountsStore.generateNewSubAccountModel(this.account);
|
||||
setAccountModelByAnotherAccount(subAccount, account.subAccounts[i]);
|
||||
subAccount.balance = subAccount.balance / 100;
|
||||
|
||||
this.subAccounts.push(subAccount);
|
||||
}
|
||||
|
||||
@@ -54,18 +54,20 @@
|
||||
<v-form class="mt-2">
|
||||
<v-row>
|
||||
<v-col cols="12" :md="transaction.type === allTransactionTypes.Transfer ? 6 : 12">
|
||||
<amount-input persistent-placeholder
|
||||
<amount-input :color="sourceAmountColor"
|
||||
:readonly="mode === 'view'"
|
||||
:disabled="loading || submitting"
|
||||
:persistent-placeholder="true"
|
||||
:hide="transaction.hideAmount"
|
||||
:label="$t(sourceAmountName)"
|
||||
:placeholder="$t(sourceAmountName)"
|
||||
v-model="transaction.sourceAmount"/>
|
||||
</v-col>
|
||||
<v-col cols="12" :md="6" v-if="transaction.type === allTransactionTypes.Transfer">
|
||||
<amount-input persistent-placeholder
|
||||
<amount-input color="primary"
|
||||
:readonly="mode === 'view'"
|
||||
:disabled="loading || submitting"
|
||||
:persistent-placeholder="true"
|
||||
:hide="transaction.hideAmount"
|
||||
:label="$t('Transfer In Amount')"
|
||||
:placeholder="$t('Transfer In Amount')"
|
||||
@@ -464,6 +466,15 @@ export default {
|
||||
transactionTimezoneTimeDifference() {
|
||||
return this.$locale.getTimezoneDifferenceDisplayText(this.transaction.utcOffset);
|
||||
},
|
||||
sourceAmountColor() {
|
||||
if (this.transaction.type === this.allTransactionTypes.Expense) {
|
||||
return 'expense';
|
||||
} else if (this.transaction.type === this.allTransactionTypes.Income) {
|
||||
return 'income';
|
||||
} else if (this.transaction.type === this.allTransactionTypes.Transfer) {
|
||||
return 'primary';
|
||||
}
|
||||
},
|
||||
geoLocationStatusInfo() {
|
||||
if (this.geoLocationStatus === 'success') {
|
||||
return '';
|
||||
@@ -538,8 +549,6 @@ export default {
|
||||
if (options && options.id) {
|
||||
if (options.currentTransaction) {
|
||||
self.setTransaction(options.currentTransaction, options, true);
|
||||
self.transaction.sourceAmount = self.transaction.sourceAmount / 100;
|
||||
self.transaction.destinationAmount = self.transaction.destinationAmount / 100;
|
||||
}
|
||||
|
||||
self.mode = 'view';
|
||||
@@ -574,8 +583,6 @@ export default {
|
||||
if (options.id && responses[3]) {
|
||||
const transaction = responses[3];
|
||||
self.setTransaction(transaction, options, true);
|
||||
self.transaction.sourceAmount = self.transaction.sourceAmount / 100;
|
||||
self.transaction.destinationAmount = self.transaction.destinationAmount / 100;
|
||||
} else {
|
||||
self.setTransaction(null, options, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user