mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-21 02:04:26 +08:00
code refactor
This commit is contained in:
@@ -248,23 +248,37 @@ export const useTransactionCategoriesStore = defineStore('transactionCategories'
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
saveCategory({ category }) {
|
saveCategory({ category, isEdit }) {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
|
const submitCategory = {
|
||||||
|
type: category.type,
|
||||||
|
name: category.name,
|
||||||
|
parentId: category.parentId,
|
||||||
|
icon: category.icon,
|
||||||
|
color: category.color,
|
||||||
|
comment: category.comment
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isEdit) {
|
||||||
|
submitCategory.id = category.id;
|
||||||
|
submitCategory.hidden = !category.visible;
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let promise = null;
|
let promise = null;
|
||||||
|
|
||||||
if (!category.id) {
|
if (!submitCategory.id) {
|
||||||
promise = services.addTransactionCategory(category);
|
promise = services.addTransactionCategory(submitCategory);
|
||||||
} else {
|
} else {
|
||||||
promise = services.modifyTransactionCategory(category);
|
promise = services.modifyTransactionCategory(submitCategory);
|
||||||
}
|
}
|
||||||
|
|
||||||
promise.then(response => {
|
promise.then(response => {
|
||||||
const data = response.data;
|
const data = response.data;
|
||||||
|
|
||||||
if (!data || !data.success || !data.result) {
|
if (!data || !data.success || !data.result) {
|
||||||
if (!category.id) {
|
if (!submitCategory.id) {
|
||||||
reject({ message: 'Unable to add category' });
|
reject({ message: 'Unable to add category' });
|
||||||
} else {
|
} else {
|
||||||
reject({ message: 'Unable to save category' });
|
reject({ message: 'Unable to save category' });
|
||||||
@@ -276,7 +290,7 @@ export const useTransactionCategoriesStore = defineStore('transactionCategories'
|
|||||||
data.result.subCategories = [];
|
data.result.subCategories = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!category.id) {
|
if (!submitCategory.id) {
|
||||||
addCategoryToTransactionCategoryList(self, data.result);
|
addCategoryToTransactionCategoryList(self, data.result);
|
||||||
} else {
|
} else {
|
||||||
updateCategoryInTransactionCategoryList(self, data.result);
|
updateCategoryInTransactionCategoryList(self, data.result);
|
||||||
@@ -289,7 +303,7 @@ export const useTransactionCategoriesStore = defineStore('transactionCategories'
|
|||||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||||
reject({ error: error.response.data });
|
reject({ error: error.response.data });
|
||||||
} else if (!error.processed) {
|
} else if (!error.processed) {
|
||||||
if (!category.id) {
|
if (!submitCategory.id) {
|
||||||
reject({ message: 'Unable to add category' });
|
reject({ message: 'Unable to add category' });
|
||||||
} else {
|
} else {
|
||||||
reject({ message: 'Unable to save category' });
|
reject({ message: 'Unable to save category' });
|
||||||
|
|||||||
@@ -209,22 +209,9 @@ export default {
|
|||||||
|
|
||||||
self.submitting = true;
|
self.submitting = true;
|
||||||
|
|
||||||
const submitCategory = {
|
|
||||||
type: self.category.type,
|
|
||||||
name: self.category.name,
|
|
||||||
parentId: self.category.parentId,
|
|
||||||
icon: self.category.icon,
|
|
||||||
color: self.category.color,
|
|
||||||
comment: self.category.comment
|
|
||||||
};
|
|
||||||
|
|
||||||
if (self.editCategoryId) {
|
|
||||||
submitCategory.id = self.category.id;
|
|
||||||
submitCategory.hidden = !self.category.visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.transactionCategoriesStore.saveCategory({
|
self.transactionCategoriesStore.saveCategory({
|
||||||
category: submitCategory
|
category: self.category,
|
||||||
|
isEdit: !!self.editCategoryId
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
self.submitting = false;
|
self.submitting = false;
|
||||||
|
|
||||||
|
|||||||
@@ -252,22 +252,9 @@ export default {
|
|||||||
self.submitting = true;
|
self.submitting = true;
|
||||||
self.$showLoading(() => self.submitting);
|
self.$showLoading(() => self.submitting);
|
||||||
|
|
||||||
const submitCategory = {
|
|
||||||
type: self.category.type,
|
|
||||||
name: self.category.name,
|
|
||||||
parentId: self.category.parentId,
|
|
||||||
icon: self.category.icon,
|
|
||||||
color: self.category.color,
|
|
||||||
comment: self.category.comment
|
|
||||||
};
|
|
||||||
|
|
||||||
if (self.editCategoryId) {
|
|
||||||
submitCategory.id = self.category.id;
|
|
||||||
submitCategory.hidden = !self.category.visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.transactionCategoriesStore.saveCategory({
|
self.transactionCategoriesStore.saveCategory({
|
||||||
category: submitCategory
|
category: self.category,
|
||||||
|
isEdit: !!self.editCategoryId
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
self.submitting = false;
|
self.submitting = false;
|
||||||
self.$hideLoading();
|
self.$hideLoading();
|
||||||
|
|||||||
Reference in New Issue
Block a user