chore:切换左侧一级分类时,右侧会自动选中第一个二级分类按钮(如"离型纸")
如果用户之前点击过某个二级分类(如"离型膜"),切换一级分类后会自动选中同名的二级分类
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -101,8 +101,9 @@
|
||||
:id="'category-' + index" v-if="select == index">
|
||||
<diy-category-item :category="item" :value="value" ref="categoryItem" :index="index"
|
||||
:select="select" :oneCategorySelect="oneCategorySelect" :isList="isList"
|
||||
:lastSecondCategoryName="lastSecondCategoryName"
|
||||
@tologin="toLogin" @selectsku="selectSku($event, index)" @addCart="addCartPoint"
|
||||
@loadfinish="getHeightArea"></diy-category-item>
|
||||
@loadfinish="getHeightArea" @saveSecondCategory="saveSecondCategoryName"></diy-category-item>
|
||||
</view>
|
||||
<view class="end-tips" ref="endTips" :style="{ opacity: endTips }">{{ $lang('components-diy.diy-category.reachedBottom') }}</view>
|
||||
</scroll-view>
|
||||
@@ -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;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user