mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 17:54:30 +08:00
code refactor
This commit is contained in:
@@ -1,5 +1,18 @@
|
|||||||
import accountConstants from '@/consts/account.js';
|
import accountConstants from '@/consts/account.js';
|
||||||
|
|
||||||
|
export function setAccountModelByAnotherAccount(account, account2) {
|
||||||
|
account.id = account2.id;
|
||||||
|
account.category = account2.category;
|
||||||
|
account.type = account2.type;
|
||||||
|
account.name = account2.name;
|
||||||
|
account.icon = account2.icon;
|
||||||
|
account.color = account2.color;
|
||||||
|
account.currency = account2.currency;
|
||||||
|
account.balance = account2.balance;
|
||||||
|
account.comment = account2.comment;
|
||||||
|
account.visible = !account2.hidden;
|
||||||
|
}
|
||||||
|
|
||||||
export function getAccountCategoryInfo(categoryId) {
|
export function getAccountCategoryInfo(categoryId) {
|
||||||
for (let i = 0; i < accountConstants.allCategories.length; i++) {
|
for (let i = 0; i < accountConstants.allCategories.length; i++) {
|
||||||
if (accountConstants.allCategories[i].id === categoryId) {
|
if (accountConstants.allCategories[i].id === categoryId) {
|
||||||
@@ -303,3 +316,21 @@ export function isAccountOrSubAccountsHasButNotAllChecked(account, filterAccount
|
|||||||
|
|
||||||
return checkedCount > 0 && checkedCount < account.subAccounts.length;
|
return checkedCount > 0 && checkedCount < account.subAccounts.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setAccountSuitableIcon(account, oldCategory, newCategory) {
|
||||||
|
for (let i = 0; i < accountConstants.allCategories.length; i++) {
|
||||||
|
if (accountConstants.allCategories[i].id === oldCategory) {
|
||||||
|
if (account.icon !== accountConstants.allCategories[i].defaultAccountIconId) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < accountConstants.allCategories.length; i++) {
|
||||||
|
if (accountConstants.allCategories[i].id === newCategory) {
|
||||||
|
account.icon = accountConstants.allCategories[i].defaultAccountIconId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+84
-8
@@ -4,6 +4,9 @@ import { useUserStore } from './user.js';
|
|||||||
import { useExchangeRatesStore } from './exchangeRates.js';
|
import { useExchangeRatesStore } from './exchangeRates.js';
|
||||||
|
|
||||||
import accountConstants from '@/consts/account.js';
|
import accountConstants from '@/consts/account.js';
|
||||||
|
import currencyConstants from '@/consts/currency.js';
|
||||||
|
import iconConstants from '@/consts/icon.js';
|
||||||
|
import colorConstants from '@/consts/color.js';
|
||||||
import services from '@/lib/services.js';
|
import services from '@/lib/services.js';
|
||||||
import logger from '@/lib/logger.js';
|
import logger from '@/lib/logger.js';
|
||||||
import { isNumber, isEquals } from '@/lib/common.js';
|
import { isNumber, isEquals } from '@/lib/common.js';
|
||||||
@@ -249,6 +252,36 @@ export const useAccountsStore = defineStore('accounts', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
generateNewAccountModel() {
|
||||||
|
const userStore = useUserStore();
|
||||||
|
|
||||||
|
return {
|
||||||
|
category: 1,
|
||||||
|
type: accountConstants.allAccountTypes.SingleAccount,
|
||||||
|
name: '',
|
||||||
|
icon: iconConstants.defaultAccountIconId,
|
||||||
|
color: colorConstants.defaultAccountColor,
|
||||||
|
currency: userStore.currentUserDefaultCurrency,
|
||||||
|
balance: 0,
|
||||||
|
comment: '',
|
||||||
|
visible: true
|
||||||
|
};
|
||||||
|
},
|
||||||
|
generateNewSubAccountModel(parentAccount) {
|
||||||
|
const userStore = useUserStore();
|
||||||
|
|
||||||
|
return {
|
||||||
|
category: null,
|
||||||
|
type: null,
|
||||||
|
name: '',
|
||||||
|
icon: parentAccount.icon,
|
||||||
|
color: parentAccount.color,
|
||||||
|
currency: userStore.currentUserDefaultCurrency,
|
||||||
|
balance: 0,
|
||||||
|
comment: '',
|
||||||
|
visible: true
|
||||||
|
};
|
||||||
|
},
|
||||||
updateAccountListInvalidState(invalidState) {
|
updateAccountListInvalidState(invalidState) {
|
||||||
this.accountListStateInvalid = invalidState;
|
this.accountListStateInvalid = invalidState;
|
||||||
},
|
},
|
||||||
@@ -703,24 +736,67 @@ export const useAccountsStore = defineStore('accounts', {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
saveAccount({ account }) {
|
saveAccount({ account, subAccounts, isEdit, isFloatBalance }) {
|
||||||
const self = this;
|
const self = this;
|
||||||
const oldAccount = account.id ? self.allAccountsMap[account.id] : null;
|
|
||||||
|
const submitSubAccounts = [];
|
||||||
|
|
||||||
|
if (account.type === accountConstants.allAccountTypes.MultiSubAccounts) {
|
||||||
|
for (let i = 0; i < subAccounts.length; i++) {
|
||||||
|
const subAccount = subAccounts[i];
|
||||||
|
const submitAccount = {
|
||||||
|
category: account.category,
|
||||||
|
type: accountConstants.allAccountTypes.SingleAccount,
|
||||||
|
name: subAccount.name,
|
||||||
|
icon: subAccount.icon,
|
||||||
|
color: subAccount.color,
|
||||||
|
currency: subAccount.currency,
|
||||||
|
balance: isFloatBalance ? subAccount.balance * 100 : subAccount.balance,
|
||||||
|
comment: subAccount.comment
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isEdit) {
|
||||||
|
submitAccount.id = subAccount.id;
|
||||||
|
submitAccount.hidden = !subAccount.visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
submitSubAccounts.push(submitAccount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitAccount = {
|
||||||
|
category: account.category,
|
||||||
|
type: account.type,
|
||||||
|
name: account.name,
|
||||||
|
icon: account.icon,
|
||||||
|
color: account.color,
|
||||||
|
currency: account.type === accountConstants.allAccountTypes.SingleAccount ? account.currency : currencyConstants.parentAccountCurrencyPlaceholder,
|
||||||
|
balance: account.type === accountConstants.allAccountTypes.SingleAccount ? (isFloatBalance ? account.balance * 100 : account.balance) : 0,
|
||||||
|
comment: account.comment,
|
||||||
|
subAccounts: account.type === accountConstants.allAccountTypes.SingleAccount ? null : submitSubAccounts,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isEdit) {
|
||||||
|
submitAccount.id = account.id;
|
||||||
|
submitAccount.hidden = !account.visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
const oldAccount = submitAccount.id ? self.allAccountsMap[submitAccount.id] : null;
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let promise = null;
|
let promise = null;
|
||||||
|
|
||||||
if (!account.id) {
|
if (!submitAccount.id) {
|
||||||
promise = services.addAccount(account);
|
promise = services.addAccount(submitAccount);
|
||||||
} else {
|
} else {
|
||||||
promise = services.modifyAccount(account);
|
promise = services.modifyAccount(submitAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
promise.then(response => {
|
promise.then(response => {
|
||||||
const data = response.data;
|
const data = response.data;
|
||||||
|
|
||||||
if (!data || !data.success || !data.result) {
|
if (!data || !data.success || !data.result) {
|
||||||
if (!account.id) {
|
if (!submitAccount.id) {
|
||||||
reject({ message: 'Unable to add account' });
|
reject({ message: 'Unable to add account' });
|
||||||
} else {
|
} else {
|
||||||
reject({ message: 'Unable to save account' });
|
reject({ message: 'Unable to save account' });
|
||||||
@@ -728,7 +804,7 @@ export const useAccountsStore = defineStore('accounts', {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!account.id) {
|
if (!submitAccount.id) {
|
||||||
addAccountToAccountList(self, data.result);
|
addAccountToAccountList(self, data.result);
|
||||||
} else {
|
} else {
|
||||||
if (oldAccount && oldAccount.category === data.result.category) {
|
if (oldAccount && oldAccount.category === data.result.category) {
|
||||||
@@ -745,7 +821,7 @@ export const useAccountsStore = defineStore('accounts', {
|
|||||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||||
reject({ error: error.response.data });
|
reject({ error: error.response.data });
|
||||||
} else if (!error.processed) {
|
} else if (!error.processed) {
|
||||||
if (!account.id) {
|
if (!submitAccount.id) {
|
||||||
reject({ message: 'Unable to add account' });
|
reject({ message: 'Unable to add account' });
|
||||||
} else {
|
} else {
|
||||||
reject({ message: 'Unable to save account' });
|
reject({ message: 'Unable to save account' });
|
||||||
|
|||||||
@@ -171,7 +171,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import { mapStores } from 'pinia';
|
import { mapStores } from 'pinia';
|
||||||
import { useSettingsStore } from '@/stores/setting.js';
|
import { useSettingsStore } from '@/stores/setting.js';
|
||||||
import { useUserStore } from '@/stores/user.js';
|
|
||||||
import { useAccountsStore } from '@/stores/account.js';
|
import { useAccountsStore } from '@/stores/account.js';
|
||||||
|
|
||||||
import accountConstants from '@/consts/account.js';
|
import accountConstants from '@/consts/account.js';
|
||||||
@@ -179,6 +178,10 @@ import iconConstants from '@/consts/icon.js';
|
|||||||
import colorConstants from '@/consts/color.js';
|
import colorConstants from '@/consts/color.js';
|
||||||
import currencyConstants from '@/consts/currency.js';
|
import currencyConstants from '@/consts/currency.js';
|
||||||
import { isNumber } from '@/lib/common.js';
|
import { isNumber } from '@/lib/common.js';
|
||||||
|
import {
|
||||||
|
setAccountModelByAnotherAccount,
|
||||||
|
setAccountSuitableIcon
|
||||||
|
} from '@/lib/account.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
mdiDotsVertical,
|
mdiDotsVertical,
|
||||||
@@ -195,24 +198,15 @@ export default {
|
|||||||
'open'
|
'open'
|
||||||
],
|
],
|
||||||
data() {
|
data() {
|
||||||
const userStore = useUserStore();
|
const accountsStore = useAccountsStore();
|
||||||
|
const newAccount = accountsStore.generateNewAccountModel();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
showState: false,
|
showState: false,
|
||||||
activeTab: 'account',
|
activeTab: 'account',
|
||||||
editAccountId: null,
|
editAccountId: null,
|
||||||
loading: false,
|
loading: false,
|
||||||
account: {
|
account: newAccount,
|
||||||
category: 1,
|
|
||||||
type: accountConstants.allAccountTypes.SingleAccount,
|
|
||||||
name: '',
|
|
||||||
icon: iconConstants.defaultAccountIconId,
|
|
||||||
color: colorConstants.defaultAccountColor,
|
|
||||||
currency: userStore.currentUserDefaultCurrency,
|
|
||||||
balance: 0,
|
|
||||||
comment: '',
|
|
||||||
visible: true
|
|
||||||
},
|
|
||||||
subAccounts: [],
|
subAccounts: [],
|
||||||
currentAccountIndex: -1,
|
currentAccountIndex: -1,
|
||||||
submitting: false,
|
submitting: false,
|
||||||
@@ -226,7 +220,7 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapStores(useSettingsStore, useUserStore, useAccountsStore),
|
...mapStores(useSettingsStore, useAccountsStore),
|
||||||
title() {
|
title() {
|
||||||
if (!this.editAccountId) {
|
if (!this.editAccountId) {
|
||||||
return 'Add Account';
|
return 'Add Account';
|
||||||
@@ -284,16 +278,8 @@ export default {
|
|||||||
self.loading = true;
|
self.loading = true;
|
||||||
self.submitting = false;
|
self.submitting = false;
|
||||||
|
|
||||||
self.account.id = null;
|
const newAccount = self.accountsStore.generateNewAccountModel();
|
||||||
self.account.category = 1;
|
setAccountModelByAnotherAccount(self.account, newAccount);
|
||||||
self.account.type = accountConstants.allAccountTypes.SingleAccount;
|
|
||||||
self.account.name = '';
|
|
||||||
self.account.icon = iconConstants.defaultAccountIconId;
|
|
||||||
self.account.color = colorConstants.defaultAccountColor;
|
|
||||||
self.account.currency = self.userStore.currentUserDefaultCurrency;
|
|
||||||
self.account.balance = 0;
|
|
||||||
self.account.comment = '';
|
|
||||||
self.account.visible = true;
|
|
||||||
self.subAccounts = [];
|
self.subAccounts = [];
|
||||||
self.currentAccountIndex = -1;
|
self.currentAccountIndex = -1;
|
||||||
|
|
||||||
@@ -334,23 +320,12 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
addSubAccount() {
|
addSubAccount() {
|
||||||
const self = this;
|
if (this.account.type !== this.allAccountTypes.MultiSubAccounts) {
|
||||||
|
|
||||||
if (self.account.type !== self.allAccountTypes.MultiSubAccounts) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.subAccounts.push({
|
const subAccount = this.accountsStore.generateNewSubAccountModel(this.account);
|
||||||
category: null,
|
this.subAccounts.push(subAccount);
|
||||||
type: null,
|
|
||||||
name: '',
|
|
||||||
icon: self.account.icon,
|
|
||||||
color: self.account.color,
|
|
||||||
currency: self.userStore.currentUserDefaultCurrency,
|
|
||||||
balance: 0,
|
|
||||||
comment: '',
|
|
||||||
visible: true
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
removeSubAccount(subAccount) {
|
removeSubAccount(subAccount) {
|
||||||
const self = this;
|
const self = this;
|
||||||
@@ -389,50 +364,11 @@ export default {
|
|||||||
|
|
||||||
self.submitting = true;
|
self.submitting = true;
|
||||||
|
|
||||||
const subAccounts = [];
|
|
||||||
|
|
||||||
if (self.account.type === self.allAccountTypes.MultiSubAccounts) {
|
|
||||||
for (let i = 0; i < self.subAccounts.length; i++) {
|
|
||||||
const subAccount = self.subAccounts[i];
|
|
||||||
const submitAccount = {
|
|
||||||
category: self.account.category,
|
|
||||||
type: self.allAccountTypes.SingleAccount,
|
|
||||||
name: subAccount.name,
|
|
||||||
icon: subAccount.icon,
|
|
||||||
color: subAccount.color,
|
|
||||||
currency: subAccount.currency,
|
|
||||||
balance: subAccount.balance * 100,
|
|
||||||
comment: subAccount.comment
|
|
||||||
};
|
|
||||||
|
|
||||||
if (self.editAccountId) {
|
|
||||||
submitAccount.id = subAccount.id;
|
|
||||||
submitAccount.hidden = !subAccount.visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
subAccounts.push(submitAccount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const submitAccount = {
|
|
||||||
category: self.account.category,
|
|
||||||
type: self.account.type,
|
|
||||||
name: self.account.name,
|
|
||||||
icon: self.account.icon,
|
|
||||||
color: self.account.color,
|
|
||||||
currency: self.account.type === self.allAccountTypes.SingleAccount ? self.account.currency : currencyConstants.parentAccountCurrencyPlaceholder,
|
|
||||||
balance: self.account.type === self.allAccountTypes.SingleAccount ? self.account.balance * 100 : 0,
|
|
||||||
comment: self.account.comment,
|
|
||||||
subAccounts: self.account.type === self.allAccountTypes.SingleAccount ? null : subAccounts,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (self.editAccountId) {
|
|
||||||
submitAccount.id = self.account.id;
|
|
||||||
submitAccount.hidden = !self.account.visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.accountsStore.saveAccount({
|
self.accountsStore.saveAccount({
|
||||||
account: submitAccount
|
account: self.account,
|
||||||
|
subAccounts: self.subAccounts,
|
||||||
|
isEdit: !!self.editAccountId,
|
||||||
|
isFloatBalance: true
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
self.submitting = false;
|
self.submitting = false;
|
||||||
|
|
||||||
@@ -465,21 +401,7 @@ export default {
|
|||||||
this.showState = false;
|
this.showState = false;
|
||||||
},
|
},
|
||||||
chooseSuitableIcon(oldCategory, newCategory) {
|
chooseSuitableIcon(oldCategory, newCategory) {
|
||||||
for (let i = 0; i < this.allAccountCategories.length; i++) {
|
setAccountSuitableIcon(this.account, oldCategory, newCategory);
|
||||||
if (this.allAccountCategories[i].id === oldCategory) {
|
|
||||||
if (this.account.icon !== this.allAccountCategories[i].defaultAccountIconId) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < this.allAccountCategories.length; i++) {
|
|
||||||
if (this.allAccountCategories[i].id === newCategory) {
|
|
||||||
this.account.icon = this.allAccountCategories[i].defaultAccountIconId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
isInputEmpty() {
|
isInputEmpty() {
|
||||||
const isAccountEmpty = !!this.getInputEmptyProblemMessage(this.account, false);
|
const isAccountEmpty = !!this.getInputEmptyProblemMessage(this.account, false);
|
||||||
@@ -514,35 +436,17 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
setAccount(account) {
|
setAccount(account) {
|
||||||
this.account.id = account.id;
|
setAccountModelByAnotherAccount(this.account, account);
|
||||||
this.account.category = account.category;
|
this.account.balance = this.account.balance / 100;
|
||||||
this.account.type = account.type;
|
|
||||||
this.account.name = account.name;
|
|
||||||
this.account.icon = account.icon;
|
|
||||||
this.account.color = account.color;
|
|
||||||
this.account.currency = account.currency;
|
|
||||||
this.account.balance = account.balance / 100;
|
|
||||||
this.account.comment = account.comment;
|
|
||||||
this.account.visible = !account.hidden;
|
|
||||||
|
|
||||||
this.subAccounts = [];
|
this.subAccounts = [];
|
||||||
|
|
||||||
if (account.subAccounts && account.subAccounts.length > 0) {
|
if (account.subAccounts && account.subAccounts.length > 0) {
|
||||||
for (let i = 0; i < account.subAccounts.length; i++) {
|
for (let i = 0; i < account.subAccounts.length; i++) {
|
||||||
const subAccount = account.subAccounts[i];
|
const subAccount = this.accountsStore.generateNewSubAccountModel(this.account);
|
||||||
|
setAccountModelByAnotherAccount(subAccount, account.subAccounts[i]);
|
||||||
|
subAccount.balance = subAccount.balance / 100;
|
||||||
|
|
||||||
this.subAccounts.push({
|
this.subAccounts.push(subAccount);
|
||||||
id: subAccount.id,
|
|
||||||
category: subAccount.category,
|
|
||||||
type: subAccount.type,
|
|
||||||
name: subAccount.name,
|
|
||||||
icon: subAccount.icon,
|
|
||||||
color: subAccount.color,
|
|
||||||
currency: subAccount.currency,
|
|
||||||
balance: subAccount.balance / 100,
|
|
||||||
comment: subAccount.comment,
|
|
||||||
visible: !subAccount.hidden
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -422,7 +422,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import { mapStores } from 'pinia';
|
import { mapStores } from 'pinia';
|
||||||
import { useSettingsStore } from '@/stores/setting.js';
|
import { useSettingsStore } from '@/stores/setting.js';
|
||||||
import { useUserStore } from '@/stores/user.js';
|
|
||||||
import { useAccountsStore } from '@/stores/account.js';
|
import { useAccountsStore } from '@/stores/account.js';
|
||||||
|
|
||||||
import accountConstants from '@/consts/account.js';
|
import accountConstants from '@/consts/account.js';
|
||||||
@@ -431,6 +430,10 @@ import colorConstants from '@/consts/color.js';
|
|||||||
import currencyConstants from '@/consts/currency.js';
|
import currencyConstants from '@/consts/currency.js';
|
||||||
import transactionConstants from '@/consts/transaction.js';
|
import transactionConstants from '@/consts/transaction.js';
|
||||||
import { getNameByKeyValue } from '@/lib/common.js';
|
import { getNameByKeyValue } from '@/lib/common.js';
|
||||||
|
import {
|
||||||
|
setAccountModelByAnotherAccount,
|
||||||
|
setAccountSuitableIcon
|
||||||
|
} from '@/lib/account.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: [
|
props: [
|
||||||
@@ -438,26 +441,17 @@ export default {
|
|||||||
'f7router'
|
'f7router'
|
||||||
],
|
],
|
||||||
data() {
|
data() {
|
||||||
const userStore = useUserStore();
|
const accountsStore = useAccountsStore();
|
||||||
|
const newAccount = accountsStore.generateNewAccountModel();
|
||||||
|
newAccount.showIconSelectionSheet = false;
|
||||||
|
newAccount.showColorSelectionSheet = false;
|
||||||
|
newAccount.showBalanceSheet = false;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
editAccountId: null,
|
editAccountId: null,
|
||||||
loading: false,
|
loading: false,
|
||||||
loadingError: null,
|
loadingError: null,
|
||||||
account: {
|
account: newAccount,
|
||||||
category: 1,
|
|
||||||
type: accountConstants.allAccountTypes.SingleAccount,
|
|
||||||
name: '',
|
|
||||||
icon: iconConstants.defaultAccountIconId,
|
|
||||||
color: colorConstants.defaultAccountColor,
|
|
||||||
currency: userStore.currentUserDefaultCurrency,
|
|
||||||
balance: 0,
|
|
||||||
comment: '',
|
|
||||||
visible: true,
|
|
||||||
showIconSelectionSheet: false,
|
|
||||||
showColorSelectionSheet: false,
|
|
||||||
showBalanceSheet: false
|
|
||||||
},
|
|
||||||
subAccounts: [],
|
subAccounts: [],
|
||||||
subAccountToDelete: null,
|
subAccountToDelete: null,
|
||||||
submitting: false,
|
submitting: false,
|
||||||
@@ -468,7 +462,7 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapStores(useSettingsStore, useUserStore, useAccountsStore),
|
...mapStores(useSettingsStore, useAccountsStore),
|
||||||
title() {
|
title() {
|
||||||
if (!this.editAccountId) {
|
if (!this.editAccountId) {
|
||||||
return 'Add Account';
|
return 'Add Account';
|
||||||
@@ -530,37 +524,18 @@ export default {
|
|||||||
self.accountsStore.getAccount({
|
self.accountsStore.getAccount({
|
||||||
accountId: self.editAccountId
|
accountId: self.editAccountId
|
||||||
}).then(account => {
|
}).then(account => {
|
||||||
self.account.id = account.id;
|
setAccountModelByAnotherAccount(self.account, account);
|
||||||
self.account.category = account.category;
|
|
||||||
self.account.type = account.type;
|
|
||||||
self.account.name = account.name;
|
|
||||||
self.account.icon = account.icon;
|
|
||||||
self.account.color = account.color;
|
|
||||||
self.account.currency = account.currency;
|
|
||||||
self.account.balance = account.balance;
|
|
||||||
self.account.comment = account.comment;
|
|
||||||
self.account.visible = !account.hidden;
|
|
||||||
self.subAccounts = [];
|
self.subAccounts = [];
|
||||||
|
|
||||||
if (account.subAccounts && account.subAccounts.length > 0) {
|
if (account.subAccounts && account.subAccounts.length > 0) {
|
||||||
for (let i = 0; i < account.subAccounts.length; i++) {
|
for (let i = 0; i < account.subAccounts.length; i++) {
|
||||||
const subAccount = account.subAccounts[i];
|
const subAccount = self.accountsStore.generateNewSubAccountModel(self.account);
|
||||||
|
setAccountModelByAnotherAccount(subAccount, account.subAccounts[i]);
|
||||||
|
subAccount.showIconSelectionSheet = false;
|
||||||
|
subAccount.showColorSelectionSheet = false;
|
||||||
|
subAccount.showBalanceSheet = false;
|
||||||
|
|
||||||
self.subAccounts.push({
|
self.subAccounts.push(subAccount);
|
||||||
id: subAccount.id,
|
|
||||||
category: subAccount.category,
|
|
||||||
type: subAccount.type,
|
|
||||||
name: subAccount.name,
|
|
||||||
icon: subAccount.icon,
|
|
||||||
color: subAccount.color,
|
|
||||||
currency: subAccount.currency,
|
|
||||||
balance: subAccount.balance,
|
|
||||||
comment: subAccount.comment,
|
|
||||||
visible: !subAccount.hidden,
|
|
||||||
showIconSelectionSheet: false,
|
|
||||||
showColorSelectionSheet: false,
|
|
||||||
showBalanceSheet: false
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -582,26 +557,16 @@ export default {
|
|||||||
this.$routeBackOnError(this.f7router, 'loadingError');
|
this.$routeBackOnError(this.f7router, 'loadingError');
|
||||||
},
|
},
|
||||||
addSubAccount() {
|
addSubAccount() {
|
||||||
const self = this;
|
if (this.account.type !== this.allAccountTypes.MultiSubAccounts) {
|
||||||
|
|
||||||
if (self.account.type !== self.allAccountTypes.MultiSubAccounts) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.subAccounts.push({
|
const subAccount = this.accountsStore.generateNewSubAccountModel(this.account);
|
||||||
category: null,
|
subAccount.showIconSelectionSheet = false;
|
||||||
type: null,
|
subAccount.showColorSelectionSheet = false;
|
||||||
name: '',
|
subAccount.showBalanceSheet = false;
|
||||||
icon: self.account.icon,
|
|
||||||
color: self.account.color,
|
this.subAccounts.push(subAccount);
|
||||||
currency: self.userStore.currentUserDefaultCurrency,
|
|
||||||
balance: 0,
|
|
||||||
comment: '',
|
|
||||||
visible: true,
|
|
||||||
showIconSelectionSheet: false,
|
|
||||||
showColorSelectionSheet: false,
|
|
||||||
showBalanceSheet: false
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
removeSubAccount(subAccount, confirm) {
|
removeSubAccount(subAccount, confirm) {
|
||||||
if (!subAccount) {
|
if (!subAccount) {
|
||||||
@@ -648,50 +613,11 @@ export default {
|
|||||||
self.submitting = true;
|
self.submitting = true;
|
||||||
self.$showLoading(() => self.submitting);
|
self.$showLoading(() => self.submitting);
|
||||||
|
|
||||||
const subAccounts = [];
|
|
||||||
|
|
||||||
if (self.account.type === self.allAccountTypes.MultiSubAccounts) {
|
|
||||||
for (let i = 0; i < self.subAccounts.length; i++) {
|
|
||||||
const subAccount = self.subAccounts[i];
|
|
||||||
const submitAccount = {
|
|
||||||
category: self.account.category,
|
|
||||||
type: self.allAccountTypes.SingleAccount,
|
|
||||||
name: subAccount.name,
|
|
||||||
icon: subAccount.icon,
|
|
||||||
color: subAccount.color,
|
|
||||||
currency: subAccount.currency,
|
|
||||||
balance: subAccount.balance,
|
|
||||||
comment: subAccount.comment
|
|
||||||
};
|
|
||||||
|
|
||||||
if (self.editAccountId) {
|
|
||||||
submitAccount.id = subAccount.id;
|
|
||||||
submitAccount.hidden = !subAccount.visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
subAccounts.push(submitAccount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const submitAccount = {
|
|
||||||
category: self.account.category,
|
|
||||||
type: self.account.type,
|
|
||||||
name: self.account.name,
|
|
||||||
icon: self.account.icon,
|
|
||||||
color: self.account.color,
|
|
||||||
currency: self.account.type === self.allAccountTypes.SingleAccount ? self.account.currency : currencyConstants.parentAccountCurrencyPlaceholder,
|
|
||||||
balance: self.account.type === self.allAccountTypes.SingleAccount ? self.account.balance : 0,
|
|
||||||
comment: self.account.comment,
|
|
||||||
subAccounts: self.account.type === self.allAccountTypes.SingleAccount ? null : subAccounts,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (self.editAccountId) {
|
|
||||||
submitAccount.id = self.account.id;
|
|
||||||
submitAccount.hidden = !self.account.visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.accountsStore.saveAccount({
|
self.accountsStore.saveAccount({
|
||||||
account: submitAccount
|
account: self.account,
|
||||||
|
subAccounts: self.subAccounts,
|
||||||
|
isEdit: !!self.editAccountId,
|
||||||
|
isFloatBalance: false
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
self.submitting = false;
|
self.submitting = false;
|
||||||
self.$hideLoading();
|
self.$hideLoading();
|
||||||
@@ -733,21 +659,7 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
chooseSuitableIcon(oldCategory, newCategory) {
|
chooseSuitableIcon(oldCategory, newCategory) {
|
||||||
for (let i = 0; i < this.allAccountCategories.length; i++) {
|
setAccountSuitableIcon(this.account, oldCategory, newCategory);
|
||||||
if (this.allAccountCategories[i].id === oldCategory) {
|
|
||||||
if (this.account.icon !== this.allAccountCategories[i].defaultAccountIconId) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < this.allAccountCategories.length; i++) {
|
|
||||||
if (this.allAccountCategories[i].id === newCategory) {
|
|
||||||
this.account.icon = this.allAccountCategories[i].defaultAccountIconId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
isInputEmpty() {
|
isInputEmpty() {
|
||||||
const isAccountEmpty = !!this.getInputEmptyProblemMessage(this.account, false);
|
const isAccountEmpty = !!this.getInputEmptyProblemMessage(this.account, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user