This commit is contained in:
MaysWind
2021-01-08 23:57:29 +08:00
parent d10726d45e
commit 6576bb946c
4 changed files with 53 additions and 9 deletions
+7
View File
@@ -18,6 +18,7 @@ import {
UPDATE_ACCOUNT_LIST_INVALID_STATE,
LOAD_TRANSACTION_LIST,
COLLAPSE_MONTH_IN_TRANSACTION_LIST,
SAVE_TRANSACTION_IN_TRANSACTION_LIST,
REMOVE_TRANSACTION_FROM_TRANSACTION_LIST,
UPDATE_TRANSACTION_LIST_INVALID_STATE,
@@ -343,6 +344,11 @@ const stores = {
state.transactionsNextTimeId = -1;
}
},
[COLLAPSE_MONTH_IN_TRANSACTION_LIST] (state, { month, collapse }) {
if (month) {
month.opened = !collapse;
}
},
[SAVE_TRANSACTION_IN_TRANSACTION_LIST] (state, { transaction, defaultCurrency, accountId }) {
for (let i = 0; i < state.transactions.length; i++) {
const transactionMonthList = state.transactions[i];
@@ -581,6 +587,7 @@ const stores = {
getTransaction: transaction.getTransaction,
saveTransaction: transaction.saveTransaction,
deleteTransaction: transaction.deleteTransaction,
collapseMonthInTransactionList: transaction.collapseMonthInTransactionList,
loadAllCategories: transactionCategory.loadAllCategories,
getCategory: transactionCategory.getCategory,
+1
View File
@@ -14,6 +14,7 @@ export const REMOVE_ACCOUNT_FROM_ACCOUNT_LIST = 'REMOVE_ACCOUNT_FROM_ACCOUNT_LIS
export const UPDATE_ACCOUNT_LIST_INVALID_STATE = 'UPDATE_ACCOUNT_LIST_INVALID_STATE';
export const LOAD_TRANSACTION_LIST = 'LOAD_TRANSACTION_LIST';
export const COLLAPSE_MONTH_IN_TRANSACTION_LIST = 'COLLAPSE_MONTH_IN_TRANSACTION_LIST';
export const SAVE_TRANSACTION_IN_TRANSACTION_LIST = 'SAVE_TRANSACTION_IN_TRANSACTION_LIST';
export const REMOVE_TRANSACTION_FROM_TRANSACTION_LIST = 'REMOVE_TRANSACTION_FROM_TRANSACTION_LIST';
export const UPDATE_TRANSACTION_LIST_INVALID_STATE = 'UPDATE_TRANSACTION_LIST_INVALID_STATE';
+37 -1
View File
@@ -6,16 +6,22 @@ import utils from '../lib/utils.js';
import {
LOAD_TRANSACTION_LIST,
COLLAPSE_MONTH_IN_TRANSACTION_LIST,
REMOVE_TRANSACTION_FROM_TRANSACTION_LIST,
UPDATE_TRANSACTION_LIST_INVALID_STATE,
UPDATE_ACCOUNT_LIST_INVALID_STATE,
} from './mutations.js';
const emptyTransactionResult = {
items: [],
transactionsNextTimeId: 0
};
function getTransactions(context, { reload, autoExpand, defaultCurrency, maxTime, minTime, type, categoryId, accountId, keyword }) {
let actualMaxTime = context.state.transactionsNextTimeId;
if (reload && maxTime > 0) {
actualMaxTime = maxTime * 1000 + 999;
actualMaxTime = maxTime;
} else if (reload && maxTime <= 0) {
actualMaxTime = 0;
}
@@ -32,6 +38,17 @@ function getTransactions(context, { reload, autoExpand, defaultCurrency, maxTime
const data = response.data;
if (!data || !data.success || !data.result) {
if (reload) {
context.commit(LOAD_TRANSACTION_LIST, {
transactions: emptyTransactionResult,
reload: reload,
autoExpand: autoExpand,
defaultCurrency: defaultCurrency,
accountId: accountId
});
context.commit(UPDATE_TRANSACTION_LIST_INVALID_STATE, true);
}
reject({ message: 'Unable to get transaction list' });
return;
}
@@ -52,6 +69,17 @@ function getTransactions(context, { reload, autoExpand, defaultCurrency, maxTime
}).catch(error => {
logger.error('failed to load transaction list', error);
if (reload) {
context.commit(LOAD_TRANSACTION_LIST, {
transactions: emptyTransactionResult,
reload: reload,
autoExpand: autoExpand,
defaultCurrency: defaultCurrency,
accountId: accountId
});
context.commit(UPDATE_TRANSACTION_LIST_INVALID_STATE, true);
}
if (error.response && error.response.data && error.response.data.errorMessage) {
reject({ error: error.response.data });
} else if (!error.processed) {
@@ -184,6 +212,13 @@ function deleteTransaction(context, { transaction, defaultCurrency, accountId, b
});
}
function collapseMonthInTransactionList(context, { month, collapse }) {
context.commit(COLLAPSE_MONTH_IN_TRANSACTION_LIST, {
month: month,
collapse: collapse
});
}
function noTransaction(state) {
for (let i = 0; i < state.transactions.length; i++) {
const transactionMonthList = state.transactions[i];
@@ -263,6 +298,7 @@ export default {
getTransaction,
saveTransaction,
deleteTransaction,
collapseMonthInTransactionList,
noTransaction,
hasMoreTransaction,
calculateMonthTotalAmount
+8 -8
View File
@@ -132,8 +132,8 @@
<f7-card v-for="transactionMonthList in transactions" :key="transactionMonthList.yearMonth">
<f7-accordion-item :opened="transactionMonthList.opened"
@accordion:open="transactionMonthList.opened = true"
@accordion:close="transactionMonthList.opened = false">
@accordion:open="collapseTransactionMonthList(transactionMonthList, false)"
@accordion:close="collapseTransactionMonthList(transactionMonthList, true)">
<f7-card-header>
<f7-accordion-toggle class="full-line">
<small :style="{ opacity: 0.6 }">
@@ -521,6 +521,12 @@ export default {
}
});
},
collapseTransactionMonthList(month, collapse) {
this.$store.dispatch('collapseMonthInTransactionList', {
month: month,
collapse: collapse
});
},
changeDateFilter(dateType) {
if (dateType === 11) { // Custom
this.showCustomDateRangeSheet = true;
@@ -567,7 +573,6 @@ export default {
return;
}
this.transactions = [];
this.query.dateType = dateType;
this.showDatePopover = false;
@@ -581,7 +586,6 @@ export default {
this.query.maxTime = maxTime;
this.query.minTime = minTime;
this.transactions = [];
this.query.dateType = 11;
this.showCustomDateRangeSheet = false;
@@ -601,7 +605,6 @@ export default {
}
}
this.transactions = [];
this.query.type = type;
this.showTypePopover = false;
this.reload(null);
@@ -611,7 +614,6 @@ export default {
return;
}
this.transactions = [];
this.query.categoryId = categoryId;
this.showCategoryPopover = false;
this.reload(null);
@@ -621,7 +623,6 @@ export default {
return;
}
this.transactions = [];
this.query.accountId = accountId;
this.showAccountPopover = false;
this.reload(null);
@@ -631,7 +632,6 @@ export default {
return;
}
this.transactions = [];
this.query.keyword = keyword;
this.reload(null);
},