chore:后台开启商品分类模板一的三级分类按钮,如果切换一级标题时三级分类标题没有商品,就不要显示没有商品的三级标题,
This commit is contained in:
@@ -57,9 +57,10 @@
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<!-- 模板1: 后台配置三级分类 + 有子分类时, 按二级分类分别显示各自的商品(图 f325d5a779 样式) -->
|
||||
<!-- 模板1: 后台配置三级分类 + 有子分类时, 按二级分类分别显示各自的商品(图 f325d5a779 样式)
|
||||
只渲染 filteredGroupedChildren(过滤掉无商品的二级分类), 没商品时整块(标题+网格)都不显示 -->
|
||||
<block v-else-if="isGroupedDisplay">
|
||||
<block v-for="(one, oneIndex) in category.child_list" :key="oneIndex">
|
||||
<block v-for="(one, oneIndex) in filteredGroupedChildren" :key="one.category_id">
|
||||
<view :class="['category-title', 'category-title-with-lines']">{{ one.category_name }}</view>
|
||||
<view class="template1-goods-wrap">
|
||||
<view class="goods-list show" :class="{ 'double-column': !isList, 'single-column': isList }" v-if="template1ChildGoodsList[one.category_id] && template1ChildGoodsList[one.category_id].length">
|
||||
@@ -92,10 +93,7 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="category-goods-empty" v-else-if="!template1ChildLoading[one.category_id]">
|
||||
<image :src="$util.img('public/uniapp/category/empty.png')" mode="widthFix" show-menu-by-longpress></image>
|
||||
<view class="tips">暂无商品</view>
|
||||
</view>
|
||||
<!-- filteredGroupedChildren 已保证加载完成且 length > 0, 此处无需再渲染空状态 -->
|
||||
</view>
|
||||
</block>
|
||||
</block>
|
||||
@@ -619,6 +617,25 @@ export default {
|
||||
isGroupedDisplay() {
|
||||
return this.value.template == 1 && this.value.level == 3;
|
||||
},
|
||||
/**
|
||||
* 模板1三级分类: 只渲染"有商品"的二级分类, 过滤掉空分类
|
||||
* 切换一级分类 / 装修刷新时, 重新计算过滤结果, 没商品的标题和空状态都不再显示
|
||||
* 注意: 加载中(template1ChildLoading[id] === true)的二级分类,
|
||||
* 暂视为"未确定" → 不计入过滤结果(等接口返回后再显示),
|
||||
* 避免闪烁显示空标题
|
||||
*/
|
||||
filteredGroupedChildren() {
|
||||
if (!this.isGroupedDisplay) return [];
|
||||
if (!this.category || !this.category.child_list || !this.category.child_list.length) return [];
|
||||
return this.category.child_list.filter(one => {
|
||||
const loading = this.template1ChildLoading[one.category_id];
|
||||
const list = this.template1ChildGoodsList[one.category_id];
|
||||
// 还在加载中: 暂不渲染(避免闪烁显示空标题)
|
||||
if (loading) return false;
|
||||
// 加载完成且有商品: 显示; 没商品: 整块不渲染
|
||||
return Array.isArray(list) && list.length > 0;
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 渲染类型: 模板1/99 用分类树卡片(category), 其它模板用商品卡片(goods)
|
||||
* 用计算属性而非 created() 里的一次性赋值:
|
||||
|
||||
Reference in New Issue
Block a user