support delete account

This commit is contained in:
MaysWind
2020-11-11 23:50:02 +08:00
parent b5a5032bd2
commit e4407c8137
8 changed files with 104 additions and 2 deletions
+43 -2
View File
@@ -41,7 +41,8 @@
<f7-card-header>{{ $t(accountCategory.name) }}</f7-card-header>
<f7-card-content :padding="false">
<f7-list>
<f7-list-item v-for="account in accounts[accountCategory.id]" :key="account.id"
<f7-list-item v-for="account in accounts[accountCategory.id]"
:key="account.id" :id="account | accountDomId"
:title="account.name" :after="account.balance | currency(account.currency)"
link="#" swipeout
>
@@ -140,8 +141,48 @@ export default {
edit() {
},
remove() {
remove(account) {
const self = this;
const app = self.$f7;
const $$ = app.$;
self.$confirm('Are you sure you want to delete this account?', () => {
self.$showLoading();
self.$services.deleteAccount({
id: account.id
}).then(response => {
self.$hideLoading();
const data = response.data;
if (!data || !data.success || !data.result) {
self.$alert('Unable to delete this account');
return;
}
app.swipeout.delete($$(`#${self.$options.filters.accountDomId(account)}`), () => {
const accountList = self.accounts[account.category];
for (let i = 0; i < accountList.length; i++) {
if (accountList[i].id === account.id) {
accountList.splice(i, 1);
}
}
});
}).catch(error => {
self.$hideLoading();
if (error.response && error.response.data && error.response.data.errorMessage) {
self.$alert({error: error.response.data});
} else if (!error.processed) {
self.$alert('Unable to delete this account');
}
});
});
}
},
filters: {
accountDomId(account) {
return 'account_' + account.id;
}
}
};