From 23a17d5f6768ac6ef8c86a11910d2801ff1f0f61 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 20 Dec 2020 17:56:55 +0800 Subject: [PATCH] fix bug --- src/views/mobile/categories/Default.vue | 34 ++++++++++++------------- src/views/mobile/categories/Edit.vue | 14 +++++----- src/views/mobile/categories/List.vue | 12 ++++----- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/views/mobile/categories/Default.vue b/src/views/mobile/categories/Default.vue index 952ba82c..9a648c1d 100644 --- a/src/views/mobile/categories/Default.vue +++ b/src/views/mobile/categories/Default.vue @@ -12,7 +12,7 @@ - {{ categoryInfo.type | categoryTypeName | t }} + {{ categoryInfo.type | categoryTypeName($constants.category.allCategoryTypes) | t }} @@ -68,7 +68,7 @@ export default { return { currentLocale: self.$i18n.locale, - categoryType: '', + categoryType: 0, allCategories: [], submitting: false, showMoreActionSheet: false, @@ -85,22 +85,22 @@ export default { const query = self.$f7route.query; const router = self.$f7router; - if (query.type !== '0' && - query.type !== this.$constants.category.allCategoryTypes.Income && - query.type !== this.$constants.category.allCategoryTypes.Expense && - query.type !== this.$constants.category.allCategoryTypes.Transfer) { + self.categoryType = parseInt(query.type); + + if (self.categoryType !== 0 && + self.categoryType !== this.$constants.category.allCategoryTypes.Income && + self.categoryType !== this.$constants.category.allCategoryTypes.Expense && + self.categoryType !== this.$constants.category.allCategoryTypes.Transfer) { self.$toast('Parameter Invalid'); router.back(); return; } - self.categoryType = query.type; - - if (query.type === '0') { + if (self.categoryType === 0) { for (let i = 1; i <= 3; i++) { self.allCategories.push({ - type: i.toString(), - categories: self.$utilities.copyArrayTo(self.getDefaultCategories(i.toString()), []) + type: i, + categories: self.$utilities.copyArrayTo(self.getDefaultCategories(i), []) }); } } else { @@ -139,7 +139,7 @@ export default { const category = categoryInfo.categories[j]; const submitCategory = { name: self.$t('category.' + category.name, self.currentLocale), - type: parseInt(categoryInfo.type), + type: categoryInfo.type, icon: category.categoryIconId, color: category.color, subCategories: [] @@ -149,7 +149,7 @@ export default { const subCategory = category.subCategories[k]; submitCategory.subCategories.push({ name: self.$t('category.' + subCategory.name, self.currentLocale), - type: parseInt(categoryInfo.type), + type: categoryInfo.type, icon: subCategory.categoryIconId, color: subCategory.color }); @@ -188,13 +188,13 @@ export default { } }, filters: { - categoryTypeName(categoryType) { + categoryTypeName(categoryType, allCategoryTypes) { switch (categoryType) { - case this.$constants.category.allCategoryTypes.Income: + case allCategoryTypes.Income: return 'Income Categories'; - case this.$constants.category.allCategoryTypes.Expense: + case allCategoryTypes.Expense: return 'Expense Categories'; - case this.$constants.category.allCategoryTypes.Transfer: + case allCategoryTypes.Transfer: return 'Transfer Categories'; default: return 'Transaction Categories'; diff --git a/src/views/mobile/categories/Edit.vue b/src/views/mobile/categories/Edit.vue index d18f7436..d6a4d702 100644 --- a/src/views/mobile/categories/Edit.vue +++ b/src/views/mobile/categories/Edit.vue @@ -81,7 +81,7 @@ export default { editCategoryId: null, loading: false, category: { - type: query.type, + type: parseInt(query.type), name: '', parentId: query.parentId, icon: self.$constants.icons.defaultCategoryIconId, @@ -158,7 +158,7 @@ export default { const category = data.result; self.category.id = category.id; - self.category.type = category.type.toString(); + self.category.type = category.type; self.category.parentId = category.type.parentId; self.category.name = category.name; self.category.icon = category.icon; @@ -179,9 +179,11 @@ export default { } }); } else if (query.parentId) { - if (query.type !== this.$constants.category.allCategoryTypes.Income && - query.type !== this.$constants.category.allCategoryTypes.Expense && - query.type !== this.$constants.category.allCategoryTypes.Transfer) { + const categoryType = parseInt(query.type); + + if (categoryType !== this.$constants.category.allCategoryTypes.Income && + categoryType !== this.$constants.category.allCategoryTypes.Expense && + categoryType !== this.$constants.category.allCategoryTypes.Transfer) { self.$toast('Parameter Invalid'); router.back(); return; @@ -206,7 +208,7 @@ export default { self.$showLoading(() => self.submitting); const submitCategory = { - type: parseInt(self.category.type), + type: self.category.type, name: self.category.name, parentId: self.category.parentId, icon: self.category.icon, diff --git a/src/views/mobile/categories/List.vue b/src/views/mobile/categories/List.vue index f957624a..c1af0a8c 100644 --- a/src/views/mobile/categories/List.vue +++ b/src/views/mobile/categories/List.vue @@ -88,7 +88,7 @@ export default { return { categories: [], hasSubCategories: false, - categoryType: '', + categoryType: 0, categoryId: '', loading: true, showHidden: false, @@ -145,16 +145,16 @@ export default { const query = self.$f7route.query; const router = self.$f7router; - if (query.type !== this.$constants.category.allCategoryTypes.Income && - query.type !== this.$constants.category.allCategoryTypes.Expense && - query.type !== this.$constants.category.allCategoryTypes.Transfer) { + self.categoryType = parseInt(query.type); + + if (self.categoryType !== this.$constants.category.allCategoryTypes.Income && + self.categoryType !== this.$constants.category.allCategoryTypes.Expense && + self.categoryType !== this.$constants.category.allCategoryTypes.Transfer) { self.$toast('Parameter Invalid'); router.back(); return; } - self.categoryType = query.type; - if (query.id && query.id !== '0') { self.categoryId = query.id; self.hasSubCategories = false;