Browse Source

将库存显示修改为合并总数:minOrder + quantity = totalStock

pull/3/head
徐飞洋 2 months ago
parent
commit
4126fbbcb1
  1. 36
      pages/index/index.js
  2. 6
      pages/index/index.wxml
  3. 16
      pages/index/index.wxss

36
pages/index/index.js

@ -47,9 +47,6 @@ Page({
page: 1,
pageSize: 8,
// 库存总数
totalInventory: 0,
// 商品数据缓存
goodsCache: [],
categoryQueryCache: {},
@ -420,19 +417,6 @@ Page({
return "";
},
// 计算商品库存总数
calculateTotalInventory: function(goodsList) {
let total = 0;
goodsList.forEach(good => {
if (good.minOrder && !isNaN(parseInt(good.minOrder))) {
total += parseInt(good.minOrder);
} else if (good.quantity && !isNaN(parseInt(good.quantity))) {
total += parseInt(good.quantity);
}
});
return total;
},
// 提取地区中的省份信息
extractProvince: function(region) {
if (!region || typeof region !== 'string') {
@ -466,6 +450,11 @@ Page({
// 确保商品ID的一致性
const productId = product.productId || product.id;
// 计算库存总数
const minOrder = parseInt(product.minOrder) || 0;
const quantity = parseInt(product.quantity) || 0;
const totalStock = minOrder + quantity;
return {
...product,
id: productId, // 统一使用id字段
@ -488,7 +477,8 @@ Page({
isReserved: false,
isFavorite: false,
currentImageIndex: 0,
imageUrls: formattedImageUrls
imageUrls: formattedImageUrls,
totalStock: totalStock // 合并后的库存总数
}
})
@ -557,16 +547,12 @@ Page({
console.log('filteredGoods[1].category:', filteredGoods[1] ? filteredGoods[1].category : 'N/A')
}
// 计算库存总数
const totalInventory = this.calculateTotalInventory(updatedGoods);
this.setData({
goods: updatedGoods,
filteredGoods: filteredGoods,
loadingMore: false,
isLoading: false,
page: this.data.page + 1,
totalInventory: totalInventory
page: this.data.page + 1
})
},
@ -625,16 +611,12 @@ Page({
const filteredGoods = this.applyFilters(updatedGoods, false)
// 计算库存总数
const totalInventory = this.calculateTotalInventory(updatedGoods);
this.setData({
goods: updatedGoods,
filteredGoods: filteredGoods,
loadingMore: false,
isLoading: false,
page: this.data.page + 1,
totalInventory: totalInventory
page: this.data.page + 1
})
},

6
pages/index/index.wxml

@ -120,10 +120,6 @@
<!-- 商品列表区域 -->
<view class="goods-section">
<!-- 库存总数显示 -->
<view wx:if="{{totalInventory > 0}}" class="total-inventory-section">
<text class="total-inventory-text">库存总数:{{totalInventory}}件</text>
</view>
<scroll-view
class="goods-list"
id="goodsScrollView"
@ -168,7 +164,7 @@
<view class="product-status-row">
<view class="status-tag source-{{item.sourceType === '三方认证' ? 'third' : (item.sourceType === '平台货源' ? 'platform' : 'unverified')}}">{{item.sourceType || ''}}</view>
<view class="status-tag negotiate-{{item.negotiateStatus === '可议价' ? 'yes' : 'no'}}">{{item.negotiateStatus}}</view>
<view class="status-tag item-count">库存:{{item.minOrder || item.quantity || '暂无'}}</view>
<view class="status-tag item-count">库存:{{item.totalStock || '暂无'}}</view>
</view>
<view class="product-meta">
<text class="sales-count">已有{{item.reservedCount || 0}}人收藏</text>

16
pages/index/index.wxss

@ -148,21 +148,7 @@ page {
padding-bottom: calc(env(safe-area-inset-bottom) );
}
/* 库存总数显示样式 */
.total-inventory-section {
background: #fff;
padding: 20rpx 30rpx;
border-bottom: 1rpx solid #eee;
text-align: center;
}
.total-inventory-text {
font-size: 32rpx;
font-weight: bold;
color: #333;
}
.goods-list {
.goods-list {
height: auto;
box-sizing: border-box;
background: #f5f5f5;

Loading…
Cancel
Save