diff --git a/components-diy/diy-category-item.vue b/components-diy/diy-category-item.vue index 52a23a0..b91076d 100644 --- a/components-diy/diy-category-item.vue +++ b/components-diy/diy-category-item.vue @@ -323,6 +323,10 @@ export default { isList: { type: Boolean, default: false + }, + lastSecondCategoryName: { + type: String, + default: '' } }, mixins: [DiyMinx], @@ -353,9 +357,16 @@ export default { if (this.index == this.select && this.pageIndex == 0) this.getGoodsList(); this.loadType = this.value.goodsLevel == 1 && this.value.loadType == 'all' ? 'all' : 'part'; if (this.index == this.select && parseInt(this.value.level) == 2 && this.category.child_list && this.category.child_list.length > 0) { - this.selectedSecondCategory = this.category.child_list[0].category_id; + let targetCategory = null; + if (this.lastSecondCategoryName) { + targetCategory = this.category.child_list.find(item => item.category_name === this.lastSecondCategoryName); + } + if (!targetCategory) { + targetCategory = this.category.child_list[0]; + } + this.selectedSecondCategory = targetCategory.category_id; this.secondCategoryGoodsList = []; - this.getSecondCategoryGoods(this.category.child_list[0].category_id); + this.getSecondCategoryGoods(targetCategory.category_id); } }, mounted() { @@ -367,9 +378,16 @@ export default { }).exec(); }, 1000); if (parseInt(this.value.level) == 2 && this.category.child_list && this.category.child_list.length > 0) { - this.selectedSecondCategory = this.category.child_list[0].category_id; + let targetCategory = null; + if (this.lastSecondCategoryName) { + targetCategory = this.category.child_list.find(item => item.category_name === this.lastSecondCategoryName); + } + if (!targetCategory) { + targetCategory = this.category.child_list[0]; + } + this.selectedSecondCategory = targetCategory.category_id; this.secondCategoryGoodsList = []; - this.getSecondCategoryGoods(this.category.child_list[0].category_id); + this.getSecondCategoryGoods(targetCategory.category_id); } }, watch: { @@ -400,9 +418,16 @@ export default { this.scrollTop = -1; } if (parseInt(this.value.level) == 2 && this.category.child_list && this.category.child_list.length > 0) { - this.selectedSecondCategory = this.category.child_list[0].category_id; + let targetCategory = null; + if (this.lastSecondCategoryName) { + targetCategory = this.category.child_list.find(item => item.category_name === this.lastSecondCategoryName); + } + if (!targetCategory) { + targetCategory = this.category.child_list[0]; + } + this.selectedSecondCategory = targetCategory.category_id; this.secondCategoryGoodsList = []; - this.getSecondCategoryGoods(this.category.child_list[0].category_id); + this.getSecondCategoryGoods(targetCategory.category_id); } }, 'globalStoreInfo.store_id': { @@ -791,6 +816,7 @@ export default { this.selectedSecondCategory = category.category_id; this.secondCategoryGoodsList = []; this.getSecondCategoryGoods(category.category_id); + this.$emit('saveSecondCategory', category.category_name); } }, getSecondCategoryGoods(categoryId) { diff --git a/components-diy/diy-category.vue b/components-diy/diy-category.vue index 5ff3844..330fd40 100644 --- a/components-diy/diy-category.vue +++ b/components-diy/diy-category.vue @@ -101,8 +101,9 @@ :id="'category-' + index" v-if="select == index"> + @loadfinish="getHeightArea" @saveSecondCategory="saveSecondCategoryName"> {{ $lang('components-diy.diy-category.reachedBottom') }} @@ -194,7 +195,8 @@ export default { loadType: '', templateFourData: [], isList: false, - lang: uni.getStorageSync("lang")//en-us 英文 + lang: uni.getStorageSync("lang"), + lastSecondCategoryName: '' }; }, created() { @@ -373,9 +375,11 @@ export default { if (index >= this.categoryTree.length) return; this.select = index; this.categoryId = 'category-' + index; - // 阻止切换分类之后滚动事件也立即执行 this.scrollLock = true; }, + saveSecondCategoryName(name) { + this.lastSecondCategoryName = name; + }, touchStart() { this.scrollLock = false; },