code refactor

This commit is contained in:
MaysWind
2023-08-13 22:19:59 +08:00
parent 33cbdfbd13
commit 62ded1290c
4 changed files with 169 additions and 246 deletions
+31
View File
@@ -1,5 +1,18 @@
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) {
for (let i = 0; i < accountConstants.allCategories.length; i++) {
if (accountConstants.allCategories[i].id === categoryId) {
@@ -303,3 +316,21 @@ export function isAccountOrSubAccountsHasButNotAllChecked(account, filterAccount
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;
}
}
}