Browse Source

feat: 实现商品规格售空状态显示功能

pull/19/head
Default User 1 month ago
parent
commit
ec2d6ecc89
  1. 26
      pages/goods-update/goods-update.js
  2. 17
      pages/goods-update/goods-update.wxml
  3. 12
      pages/goods-update/goods-update.wxss
  4. 9
      server-example/server-mysql.js
  5. 3
      utils/api.js

26
pages/goods-update/goods-update.js

@ -195,7 +195,7 @@ function getUserPhoneNumber() {
}
// 处理净重件数对应数据,支持逗号分隔的价格与规格一一对应
function processWeightAndQuantityData(weightSpecString, quantityString, specString, price = '', costprice = '') {
function processWeightAndQuantityData(weightSpecString, quantityString, specString, price = '', costprice = '', specStatusString = '') {
console.log('===== 处理净重、件数和规格数据 =====');
console.log('输入参数:');
console.log('- weightSpecString:', weightSpecString, '(类型:', typeof weightSpecString, ')');
@ -203,6 +203,7 @@ function processWeightAndQuantityData(weightSpecString, quantityString, specStri
console.log('- specString:', specString, '(类型:', typeof specString, ')');
console.log('- price:', price, '(类型:', typeof price, ')');
console.log('- costprice:', costprice, '(类型:', typeof costprice, ')');
console.log('- specStatusString:', specStatusString, '(类型:', typeof specStatusString, ')');
// 如果没有数据,返回空数组
if (!weightSpecString && !quantityString && !specString) {
@ -254,8 +255,16 @@ function processWeightAndQuantityData(weightSpecString, quantityString, specStri
console.log('将采购价格转换为数组:', costpriceArray);
}
// 处理规格状态字符串,支持逗号分隔的多个状态
let specStatusArray = [];
if (specStatusString && typeof specStatusString === 'string') {
// 支持多种逗号分隔符:英文逗号、中文逗号、全角逗号
specStatusArray = specStatusString.split(/[,,、]/).map(item => item.trim()).filter(item => item);
console.log('从字符串分割得到规格状态数组:', specStatusArray);
}
// 获取最大长度,确保一一对应
const maxLength = Math.max(weightSpecArray.length, quantityArray.length, priceArray.length, costpriceArray.length);
const maxLength = Math.max(weightSpecArray.length, quantityArray.length, priceArray.length, costpriceArray.length, specStatusArray.length);
console.log('最大长度:', maxLength);
const result = [];
@ -264,8 +273,9 @@ function processWeightAndQuantityData(weightSpecString, quantityString, specStri
const quantity = quantityArray[i] || '';
const itemPrice = priceArray[i] || '';
const itemCostprice = costpriceArray[i] || '';
const itemSpecStatus = specStatusArray[i] || '0'; // 默认规格状态为0
console.log(`处理第${i}组数据: weightSpec=${weightSpec}, quantity=${quantity}, price=${itemPrice}, costprice=${itemCostprice}`);
console.log(`处理第${i}组数据: weightSpec=${weightSpec}, quantity=${quantity}, price=${itemPrice}, costprice=${itemCostprice}, specStatus=${itemSpecStatus}`);
// 处理净重规格显示格式 - 根据内容类型添加相应前缀
let weightSpecDisplay = '';
@ -297,9 +307,10 @@ function processWeightAndQuantityData(weightSpecString, quantityString, specStri
weightSpec: weightSpecDisplay,
quantity: quantityDisplay,
price: itemPrice,
costprice: itemCostprice
costprice: itemCostprice,
specStatus: itemSpecStatus
});
console.log(`添加显示对象: weightSpec=${weightSpecDisplay}, quantity=${quantityDisplay}, price=${itemPrice}, costprice=${itemCostprice}`);
console.log(`添加显示对象: weightSpec=${weightSpecDisplay}, quantity=${quantityDisplay}, price=${itemPrice}, costprice=${itemCostprice}, specStatus=${itemSpecStatus}`);
}
}
@ -525,6 +536,9 @@ Page({
console.log('product.specification:', product.specification);
console.log('product.quantity:', product.quantity);
console.log('product.minOrder:', product.minOrder);
// 添加spec_status字段调试
console.log('product.spec_status:', product.spec_status);
console.log('是否包含spec_status字段:', 'spec_status' in product);
if (product.spec && typeof product.spec === 'string' && (product.spec.includes('净重') || product.spec.includes('毛重'))) {
// 如果规格字段包含净重或毛重信息,则使用该字段作为重量规格数据
@ -567,7 +581,7 @@ Page({
quantityString: quantityString
});
const weightQuantityData = processWeightAndQuantityData(weightSpecString, quantityString, '', product.price, product.costprice);
const weightQuantityData = processWeightAndQuantityData(weightSpecString, quantityString, '', product.price, product.costprice, product.spec_status);
console.log('=== 处理结果调试信息 ===');
console.log('weightSpecString:', weightSpecString);

17
pages/goods-update/goods-update.wxml

@ -82,10 +82,19 @@
<view class="wq-block-list">
<block wx:if="{{goodsDetail.weightQuantityData && goodsDetail.weightQuantityData.length > 0}}">
<view class="wq-block-row" wx:for="{{goodsDetail.weightQuantityData}}" wx:key="index">
<view class="wq-block spec-block"><text class="block-text weight-spec-text">{{item.weightSpec}}</text></view>
<view class="wq-block quantity-block"><text class="block-text quantity-text">【{{item.quantity}}】</text></view>
<view class="wq-block costprice-block"><text class="block-text costprice-text" wx:if="{{item.costprice && item.costprice !== '暂无'}}">¥{{item.costprice}}</text></view>
<view class="wq-block price-block"><text class="block-text price-text" wx:if="{{item.price && item.price !== '暂无'}}">¥{{item.price}}</text></view>
<view class="wq-block spec-block" style="color: {{item.specStatus == '1' ? '#999999' : '#333333'}}">
<text class="block-text weight-spec-text">{{item.weightSpec}}</text>
</view>
<view class="wq-block quantity-block" style="color: {{item.specStatus == '1' ? '#999999' : '#333333'}}">
<text class="block-text quantity-text">【{{item.quantity}}】</text>
</view>
<view class="wq-block costprice-block" style="color: {{item.specStatus == '1' ? '#999999' : '#333333'}}">
<text class="block-text costprice-text" wx:if="{{item.costprice && item.costprice !== '暂无'}}">¥{{item.costprice}}</text>
</view>
<view class="wq-block price-block" style="color: {{item.specStatus == '1' ? '#999999' : '#333333'}}">
<text class="block-text price-text" wx:if="{{item.price && item.price !== '暂无'}}">¥{{item.price}}</text>
<text class="sold-out-tag" wx:if="{{item.specStatus == '1'}}">售空</text>
</view>
</view>
</block>
<block wx:elif="{{goodsDetail.specInfo && goodsDetail.specInfo.length > 0}}">

12
pages/goods-update/goods-update.wxss

@ -1662,3 +1662,15 @@ video.slider-media .wx-video-volume-icon {
line-height: 1.6;
font-weight: 500;
}
/* 售空标识样式 */
.sold-out-tag {
font-size: 20rpx;
color: #ffffff;
background-color: #ff4d4f;
border-radius: 10rpx;
padding: 4rpx 10rpx;
margin-left: 8rpx;
font-weight: 400;
vertical-align: middle;
}

9
server-example/server-mysql.js

@ -919,6 +919,13 @@ Product.init({
this.setDataValue('product_log', JSON.stringify(value));
}
}
},
// 规格状态字段
spec_status: {
type: DataTypes.STRING(100),
allowNull: true,
comment: '规格状态',
defaultValue: '0'
}
}, {
sequelize,
@ -4157,7 +4164,7 @@ app.post('/api/products/detail', async (req, res) => {
// 查询商品详情 - 排除hidden状态商品,直接使用Product表中的reservedCount字段
const product = await Product.findOne({
attributes: ['productId', 'productName', 'price', 'quantity', 'grossWeight', 'imageUrls', 'created_at', 'specification', 'yolk', 'sourceType', 'supplyStatus', 'producting', 'product_contact', 'contact_phone', 'region', 'freshness', 'costprice','description', 'frequency', 'product_log'],
attributes: ['productId', 'productName', 'price', 'quantity', 'grossWeight', 'imageUrls', 'created_at', 'specification', 'yolk', 'sourceType', 'supplyStatus', 'producting', 'product_contact', 'contact_phone', 'region', 'freshness', 'costprice','description', 'frequency', 'product_log', 'spec_status'],
where: {
productId,
status: { [Sequelize.Op.not]: 'hidden' }

3
utils/api.js

@ -3886,6 +3886,9 @@ module.exports = {
console.log('- contact_phone值:', data.data.contact_phone);
console.log('- 是否包含producting字段:', 'producting' in data.data);
console.log('- producting值:', data.data.producting);
// 添加spec_status字段检查
console.log('- 是否包含spec_status:', 'spec_status' in data.data);
console.log('- spec_status值:', data.data.spec_status);
console.log('- 完整字段:', Object.keys(data.data));
}
return data;

Loading…
Cancel
Save