mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-14 06:57:35 +08:00
support pull to refresh in account list page
This commit is contained in:
@@ -26,6 +26,23 @@ function isBoolean(val) {
|
||||
return typeof(val) === 'boolean';
|
||||
}
|
||||
|
||||
function getCategorizedAccounts(allAccounts) {
|
||||
const ret = {};
|
||||
|
||||
for (let i = 0; i < allAccounts.length; i++) {
|
||||
const account = allAccounts[i];
|
||||
|
||||
if (!ret[account.category]) {
|
||||
ret[account.category] = [];
|
||||
}
|
||||
|
||||
const accountList = ret[account.category];
|
||||
accountList.push(account);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
export default {
|
||||
isFunction,
|
||||
isObject,
|
||||
@@ -33,4 +50,5 @@ export default {
|
||||
isString,
|
||||
isNumber,
|
||||
isBoolean,
|
||||
getCategorizedAccounts,
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<f7-page>
|
||||
<f7-page ptr @ptr:refresh="reload">
|
||||
<f7-navbar>
|
||||
<f7-nav-left :back-link="$t('Back')"></f7-nav-left>
|
||||
<f7-nav-title :title="$t('Account List')" :back-link="$t('Back')"></f7-nav-title>
|
||||
@@ -97,18 +97,7 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
self.accounts = {};
|
||||
|
||||
for (let i = 0; i < data.result.length; i++) {
|
||||
const account = data.result[i];
|
||||
|
||||
if (!self.accounts[account.category]) {
|
||||
self.accounts[account.category] = [];
|
||||
}
|
||||
|
||||
const accountList = self.accounts[account.category];
|
||||
accountList.push(account);
|
||||
}
|
||||
self.accounts = self.$utils.getCategorizedAccounts(data.result);
|
||||
}).catch(error => {
|
||||
self.loading = false;
|
||||
|
||||
@@ -124,6 +113,30 @@ export default {
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
reload(done) {
|
||||
const self = this;
|
||||
|
||||
self.$services.getAllAccounts().then(response => {
|
||||
done();
|
||||
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
self.$toast('Unable to get account list');
|
||||
return;
|
||||
}
|
||||
|
||||
self.accounts = self.$utils.getCategorizedAccounts(data.result);
|
||||
}).catch(error => {
|
||||
done();
|
||||
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
self.$toast({ error: error.response.data });
|
||||
} else if (!error.processed) {
|
||||
self.$toast('Unable to get account list');
|
||||
}
|
||||
});
|
||||
},
|
||||
edit() {
|
||||
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user