chore:template == 1的模板正常

This commit is contained in:
2026-07-17 14:01:40 +08:00
parent 21c342e389
commit b2063418fb

View File

@@ -45,8 +45,8 @@
</view>
</block>
<!-- 模板1: 有子分类时, 按二级分类分别显示各自的商品(图1样式) -->
<block v-else-if="value.template == 1">
<!-- 模板1: 后台配置三级分类 + 有子分类时, 按二级分类分别显示各自的商品(图 f325d5a779 样式) -->
<block v-else-if="isGroupedDisplay">
<block v-for="(one, oneIndex) in category.child_list" :key="oneIndex">
<view :class="['category-title', 'category-title-with-lines']">{{ one.category_name }}</view>
<view class="template1-goods-wrap">
@@ -80,6 +80,39 @@
</block>
</block>
<!-- 模板1: 后台配置二级分类 + 有子分类时, 在一级分类标题下以双列网格显示所有商品(图 c2df0f3d29 样式) -->
<view v-else-if="value.template == 1">
<view :class="['category-title', 'category-title-with-lines']">{{ category.category_name }}</view>
<view class="template1-goods-wrap">
<view class="goods-list double-column show" v-if="template1GoodsList.length">
<view class="goods-item" v-for="(item, index) in template1GoodsList" :key="index">
<view class="goods-img" @tap.stop="toDetail(item)">
<image :src="goodsImg(item.goods_image)" mode="widthFix" @error="template1ImgError(index)" show-menu-by-longpress />
<view class="color-base-bg goods-tag" v-if="item.label_name">{{ item.label_name }}</view>
</view>
<view class="info-wrap">
<view class="name-wrap" @tap.stop="toDetail(item)">
<view class="goods-name">{{ isEnEnv ? item.en_goods_name : item.goods_name }}</view>
</view>
<view class="price-wrap">
<view class="discount-price">
<block v-if="item.isinformation == 0">
<text class="unit price-style small">{{ $lang('common.currencySymbol') }}</text>
<text class="price price-style large">{{ parseFloat(showPrice(item)).toFixed(2).split('.')[0] }}</text>
<text class="unit price-style small">.{{ parseFloat(showPrice(item)).toFixed(2).split('.')[1] }}</text>
</block>
</view>
</view>
</view>
</view>
</view>
<view class="category-goods-empty" v-else-if="!template1Loading">
<image :src="$util.img('public/uniapp/category/empty.png')" mode="widthFix" show-menu-by-longpress></image>
<view class="tips">暂无商品</view>
</view>
</view>
</view>
<!-- 非模板1, 2级分类: 显示二级分类网格,点击跳转到列表页 -->
<block v-else-if="categoryLevel == 2">
<view :class="['category-title', '']">{{ category.category_name }}</view>
@@ -110,7 +143,7 @@
</block>
</block>
<!-- 模板1: 无子分类时, 在一级分类标题下以双列网格显示所有商品(图2样式) -->
<!-- 模板1: 无子分类时(外层块不进入), 在一级分类标题下以双列网格显示所有商品(图 c2df0f3d29 样式) -->
<view v-else-if="value.template == 1 && type == 'category'">
<view :class="['category-title', 'category-title-with-lines']">{{ category.category_name }}</view>
<view class="template1-goods-wrap">
@@ -470,6 +503,15 @@ export default {
}
// 否则按数据层级
return dataLevel;
},
/**
* 模板1: 是否按子分类分组显示
* 后台"展示分类"配置:
* 二级分类 (value.level == 2) → false → 单网格显示所有商品
* 三级分类 (value.level == 3) → true → 按二级分类分别显示各自商品
*/
isGroupedDisplay() {
return this.value.template == 1 && this.value.level == 3;
}
},
created() {
@@ -489,11 +531,11 @@ export default {
// 用当前一级分类下同名二级分类的 id 查商品(而非全局按钮的 id)
this.refreshGoodsByCurrentCategory();
}
// 模板1:按是否有二级分类分别处理
// 有二级分类(child_list.length > 0)时,为每个二级分类分别加载各自的商品(图1按分类分组显示)
// 无二级分类时,直接加载当前一级分类下的所有商品(图2统一网格显示)
// 模板1:根据后台"展示分类"配置 + 数据层级决定加载方式
// 三级分类模式 (isGroupedDisplay) + 有二级分类时,按二级分类分别加载各自商品
// 其他情况(二级分类模式 / 无二级分类),直接加载当前一级分类下的所有商品
if (this.value.template == 1 && this.category && this.category.category_id) {
if (this.category.child_list && this.category.child_list.length) {
if (this.isGroupedDisplay && this.category.child_list && this.category.child_list.length) {
this.category.child_list.forEach(child => {
this.getTemplate1ChildGoods(child.category_id);
});
@@ -563,12 +605,12 @@ export default {
this.refreshGoodsByCurrentCategory();
}
// 模板1:切换一级分类时重新加载该分类下的商品
// 有二级分类时为每个二级分类重新加载,否则直接加载当前分类
// 三级分类模式 + 有二级分类时,按二级分类分别重新加载,否则直接加载当前分类
if (this.value.template == 1 && this.index == this.select && this.category && this.category.category_id) {
this.template1GoodsList = [];
this.template1ChildGoodsList = {};
this.template1ChildLoading = {};
if (this.category.child_list && this.category.child_list.length) {
if (this.isGroupedDisplay && this.category.child_list && this.category.child_list.length) {
this.category.child_list.forEach(child => {
this.getTemplate1ChildGoods(child.category_id);
});