add default categories backend

This commit is contained in:
MaysWind
2020-12-04 02:42:52 +08:00
parent 9c18bc650e
commit c5cc4dee56
8 changed files with 242 additions and 2 deletions
+5
View File
@@ -228,6 +228,11 @@ export default {
comment
});
},
addTransactionCategoryBatch: ({ categories }) => {
return axios.post('v1/transaction/categories/add_batch.json', {
categories
});
},
modifyTransactionCategory: ({ id, name, icon, color, comment, hidden }) => {
return axios.post('v1/transaction/categories/modify.json', {
id,
+1
View File
@@ -516,6 +516,7 @@ export default {
'Unable to add category': 'Unable to add category',
'Unable to save category': 'Unable to save category',
'You have added a new category': 'You have added a new category',
'You have added default categories': 'You have added default categories',
'You have saved this category': 'You have saved this category',
'Are you sure you want to logout from this session?': 'Are you sure you want to logout from this session?',
'Unable to logout from this session': 'Unable to logout from this session',
+1
View File
@@ -516,6 +516,7 @@ export default {
'Unable to add category': '无法添加分类',
'Unable to save category': '无法保存分类',
'You have added a new category': '您已经添加新分类',
'You have added default categories': '您已经添加默认分类',
'You have saved this category': '您已经保存该分类',
'Are you sure you want to logout from this session?': '您确定要退出该会话?',
'Unable to logout from this session': '无法退出该会话',
@@ -4,7 +4,7 @@
<f7-nav-left :back-link="$t('Back')"></f7-nav-left>
<f7-nav-title :title="$t('Default Categories')"></f7-nav-title>
<f7-nav-right>
<f7-link :text="$t('Save')" :class="{ 'disabled': saving }" @click="save"></f7-link>
<f7-link :text="$t('Save')" :class="{ 'disabled': submitting }" @click="save"></f7-link>
</f7-nav-right>
</f7-navbar>
@@ -50,7 +50,7 @@ export default {
return {
categoryType: '',
allCategories: [],
saving: false
submitting: false
};
},
created() {
@@ -94,7 +94,67 @@ export default {
}
},
save() {
const self = this;
const router = self.$f7router;
self.submitting = true;
self.$showLoading(() => self.submitting);
const categories = [];
for (let i = 0; i < self.allCategories.length; i++) {
const categoryInfo = self.allCategories[i];
for (let j = 0; j < categoryInfo.categories.length; j++) {
const category = categoryInfo.categories[j];
const submitCategory = {
name: self.$t('category.' + category.name),
type: parseInt(categoryInfo.type),
icon: category.categoryIconId,
color: category.color,
subCategories: []
}
for (let k = 0; k < category.subCategories.length; k++) {
const subCategory = category.subCategories[k];
submitCategory.subCategories.push({
name: self.$t('category.' + subCategory.name),
type: parseInt(categoryInfo.type),
icon: subCategory.categoryIconId,
color: subCategory.color
});
}
categories.push(submitCategory);
}
}
self.$services.addTransactionCategoryBatch({
categories: categories
}).then(response => {
self.submitting = false;
self.$hideLoading();
const data = response.data;
if (!data || !data.success || !data.result) {
self.$toast('Unable to add category');
return;
}
self.$toast('You have added default categories');
router.back();
}).catch(error => {
self.$logger.error('failed to save default categories', error);
self.submitting = false;
self.$hideLoading();
if (error.response && error.response.data && error.response.data.errorMessage) {
self.$toast({ error: error.response.data });
} else if (!error.processed) {
self.$toast('Unable to add category');
}
});
}
},
filters: {