diff --git a/components-diy/diy-category-item.vue b/components-diy/diy-category-item.vue index f7a5d29..7754063 100644 --- a/components-diy/diy-category-item.vue +++ b/components-diy/diy-category-item.vue @@ -2,10 +2,50 @@ - - + + - + + + + {{ one.category_name }} + + + + + + + + {{ item.label_name }} + + + + {{ isEnEnv ? item.en_goods_name : item.goods_name }} + + + + + {{ $lang('common.currencySymbol') }} + {{ parseFloat(showPrice(item)).toFixed(2).split('.')[0] }} + .{{ parseFloat(showPrice(item)).toFixed(2).split('.')[1] }} + + + + + + + + + + {{ $lang('components-diy.diy-category.noCategory') }} + + + + {{ category.category_name }} 0) { + 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(targetCategory.category_id); + } }, mounted() { setTimeout(() => { @@ -332,6 +390,18 @@ export default { if (data) this.contentWrapHeight = data.height; }).exec(); }, 1000); + if (this.value.template == 99 && parseInt(this.value.level) == 2 && this.category.child_list && this.category.child_list.length > 0) { + 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(targetCategory.category_id); + } }, watch: { oneCategorySelect: function () { @@ -360,6 +430,18 @@ export default { } else if (this.loadType == 'part') { this.scrollTop = -1; } + if (this.value.template == 99 && parseInt(this.value.level) == 2 && this.category.child_list && this.category.child_list.length > 0) { + 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(targetCategory.category_id); + } }, 'globalStoreInfo.store_id': { handler(nval, oval) { @@ -739,6 +821,48 @@ export default { if (!link) return; this.$util.diyRedirectTo(JSON.parse(link)); }, + selectSecondCategory(category) { + if (this.selectedSecondCategory === category.category_id) { + this.selectedSecondCategory = null; + this.secondCategoryGoodsList = []; + } else { + this.selectedSecondCategory = category.category_id; + this.secondCategoryGoodsList = []; + this.getSecondCategoryGoods(category.category_id); + this.$emit('saveSecondCategory', category.category_name); + } + }, + getSecondCategoryGoods(categoryId) { + this.loading = true; + let order = ''; + let sort = ''; + if (this.value.sortWay) { + if (this.value.sortWay == 'default') { + order = ''; + sort = ''; + } else if (this.value.sortWay == 'sales') { + order = 'sales'; + sort = 'desc'; + } else if (this.value.sortWay == 'price') { + order = 'min_price'; + sort = this.value.sortType == 'desc' ? 'desc' : 'asc'; + } + } + this.$api.goods.getGoodsList({ + category_id: categoryId, + page: this.pageIndex, + page_size: this.pageSize, + order: order, + sort: sort + }).then(res => { + this.loading = false; + if (res.data.data.list) { + this.secondCategoryGoodsList = res.data.data.list; + } + }).catch(err => { + this.loading = false; + }); + }, //加载商品在购物车的总数量 loadGoodsCartNum(isRefresh = false) { this.goodsList.forEach((item) => { diff --git a/components-diy/diy-category.vue b/components-diy/diy-category.vue index e6e01ce..bc17e54 100644 --- a/components-diy/diy-category.vue +++ b/components-diy/diy-category.vue @@ -92,17 +92,18 @@ - + :id="'category-' + index" :style="{ display: value.template == 99 && select != index ? 'none' : 'block' }"> + @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; },