From 173215d4c17cb1b5755fb39cb4e1d4139e945ab7 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Mon, 21 Dec 2020 01:22:44 +0800 Subject: [PATCH] modify account selection sheet --- .../TwoColumnListItemSelectionSheet.vue | 64 +++++++++++--- src/lib/utils.js | 60 ++++++++++++-- src/views/mobile/accounts/List.vue | 57 +++++++------ src/views/mobile/transactions/Edit.vue | 83 ++++++++----------- 4 files changed, 171 insertions(+), 93 deletions(-) diff --git a/src/components/mobile/TwoColumnListItemSelectionSheet.vue b/src/components/mobile/TwoColumnListItemSelectionSheet.vue index e829ced3..f3adec23 100644 --- a/src/components/mobile/TwoColumnListItemSelectionSheet.vue +++ b/src/components/mobile/TwoColumnListItemSelectionSheet.vue @@ -15,7 +15,7 @@ v-for="item in items" :key="primaryKeyField ? item[primaryKeyField] : item" :value="primaryValueField ? item[primaryValueField] : item" - :title="primaryTitleField ? item[primaryTitleField] : item" + :title="primaryTitleField ? (primaryTitleI18n ? $t(item[primaryTitleField]) : item[primaryTitleField]) : (primaryTitleI18n ? $t(item) : item)" @click="onPrimaryItemClicked(item)"> - true); + const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.categorizedAccounts, () => true); let netAssets = 0; let hasUnCalculatedAmount = false; @@ -299,7 +301,7 @@ export default { return '***'; } - const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.accounts, account => account.isAsset); + const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.categorizedAccounts, account => account.isAsset); let totalAssets = 0; let hasUnCalculatedAmount = false; @@ -329,7 +331,7 @@ export default { return '***'; } - const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.accounts, account => account.isLiability); + const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.categorizedAccounts, account => account.isLiability); let totalLiabilities = 0; let hasUnCalculatedAmount = false; @@ -370,7 +372,7 @@ export default { return; } - self.accounts = self.$utilities.getCategorizedAccounts(data.result); + self.categorizedAccounts = self.$utilities.getCategorizedAccounts(data.result); self.loading = false; }).catch(error => { self.$logger.error('failed to load account list', error); @@ -413,7 +415,7 @@ export default { return; } - self.accounts = self.$utilities.getCategorizedAccounts(data.result); + self.categorizedAccounts = self.$utilities.getCategorizedAccounts(data.result); }).catch(error => { self.$logger.error('failed to reload account list', error); @@ -429,14 +431,16 @@ export default { }); }, hasShownAccount(accountCategory) { - if (!this.accounts[accountCategory.id].length) { + if (!this.categorizedAccounts[accountCategory.id] || + !this.categorizedAccounts[accountCategory.id].accounts || + !this.categorizedAccounts[accountCategory.id].accounts.length) { return false; } let shownCount = 0; - for (let i = 0; i < this.accounts[accountCategory.id].length; i++) { - const account = this.accounts[accountCategory.id][i]; + for (let i = 0; i < this.categorizedAccounts[accountCategory.id].accounts.length; i++) { + const account = this.categorizedAccounts[accountCategory.id].accounts[i]; if (!account.hidden) { shownCount++; @@ -465,7 +469,7 @@ export default { return '***'; } - const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.accounts, account => account.category === accountCategory.id); + const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.categorizedAccounts, account => account.category === accountCategory.id); let totalBalance = 0; let hasUnCalculatedAmount = false; @@ -506,14 +510,17 @@ export default { } const id = event.el.id.substr(8); // account_ - const account = this.$utilities.getAccountByAccountId(this.accounts, id); + const account = this.$utilities.getAccountByAccountId(this.categorizedAccounts, id); - if (!account || !this.accounts[account.category] || !this.accounts[account.category][event.to]) { + if (!account || + !this.categorizedAccounts[account.category] || + !this.categorizedAccounts[account.category].accounts || + !this.categorizedAccounts[account.category].accounts[event.to]) { this.$toast('Unable to move account'); return; } - const accountList = this.accounts[account.category]; + const accountList = this.categorizedAccounts[account.category].accounts; accountList.splice(event.to, 0, accountList.splice(event.from, 1)[0]); this.displayOrderModified = true; @@ -530,12 +537,12 @@ export default { self.displayOrderSaving = true; - for (let category in self.accounts) { - if (!Object.prototype.hasOwnProperty.call(self.accounts, category)) { + for (let category in self.categorizedAccounts) { + if (!Object.prototype.hasOwnProperty.call(self.categorizedAccounts, category)) { continue; } - const accountList = self.accounts[category]; + const accountList = self.categorizedAccounts[category].accounts; for (let i = 0; i < accountList.length; i++) { newDisplayOrders.push({ @@ -650,7 +657,7 @@ export default { } app.swipeout.delete($$(`#${self.$options.filters.accountDomId(account)}`), () => { - const accountList = self.accounts[account.category]; + const accountList = self.categorizedAccounts[account.category].accounts; for (let i = 0; i < accountList.length; i++) { if (accountList[i].id === account.id) { accountList.splice(i, 1); diff --git a/src/views/mobile/transactions/Edit.vue b/src/views/mobile/transactions/Edit.vue index 9ead7b44..4d7a6d30 100644 --- a/src/views/mobile/transactions/Edit.vue +++ b/src/views/mobile/transactions/Edit.vue @@ -144,36 +144,40 @@