diff --git a/pages/goods-detail/goods-detail.js b/pages/goods-detail/goods-detail.js
index e29ca53..79b8b3a 100644
--- a/pages/goods-detail/goods-detail.js
+++ b/pages/goods-detail/goods-detail.js
@@ -64,6 +64,86 @@ function extractProvince(region) {
return region;
}
+// 处理净重、件数和规格数据,将逗号分隔的字符串转换为一一对应的数组
+function processWeightAndQuantityData(weightSpecString, quantityString, specString) {
+ console.log('===== 处理净重、件数和规格数据 =====');
+ console.log('输入参数:');
+ console.log('- weightSpecString:', weightSpecString, '(类型:', typeof weightSpecString, ')');
+ console.log('- quantityString:', quantityString, '(类型:', typeof quantityString, ')');
+ console.log('- specString:', specString, '(类型:', typeof specString, ')');
+
+ // 如果没有数据,返回空数组
+ if (!weightSpecString && !quantityString && !specString) {
+ console.log('没有数据,返回空数组');
+ return [];
+ }
+
+ // 处理净重/规格字符串(它可能包含净重信息)
+ let weightSpecArray = [];
+ if (weightSpecString && typeof weightSpecString === 'string') {
+ // 支持多种逗号分隔符:英文逗号、中文逗号、全角逗号
+ weightSpecArray = weightSpecString.split(/[,,、]/).map(item => item.trim()).filter(item => item);
+ console.log('从字符串分割得到净重规格数组:', weightSpecArray);
+ } else if (weightSpecString) {
+ weightSpecArray = [String(weightSpecString)];
+ console.log('将净重规格转换为数组:', weightSpecArray);
+ }
+
+ // 处理件数字符串
+ let quantityArray = [];
+ if (quantityString && typeof quantityString === 'string') {
+ // 支持多种逗号分隔符:英文逗号、中文逗号、全角逗号
+ quantityArray = quantityString.split(/[,,、]/).map(item => item.trim()).filter(item => item);
+ console.log('从字符串分割得到数量数组:', quantityArray);
+ } else if (quantityString) {
+ quantityArray = [String(quantityString)];
+ console.log('将数量转换为数组:', quantityArray);
+ }
+
+ // 获取最大长度,确保一一对应
+ const maxLength = Math.max(weightSpecArray.length, quantityArray.length);
+ console.log('最大长度:', maxLength);
+ const result = [];
+
+ for (let i = 0; i < maxLength; i++) {
+ const weightSpec = weightSpecArray[i] || '';
+ const quantity = quantityArray[i] || '';
+
+ console.log(`处理第${i}组数据: weightSpec=${weightSpec}, quantity=${quantity}`);
+
+ // 处理净重规格显示格式 - 保持原始格式,如果包含"净重"则保持,否则添加
+ let weightSpecDisplay = '';
+ if (weightSpec) {
+ if (weightSpec.includes('净重')) {
+ weightSpecDisplay = weightSpec;
+ } else {
+ weightSpecDisplay = `净重${weightSpec}`;
+ }
+ }
+
+ // 组合显示:格式为"净重信息————件数"
+ let display = '';
+ if (weightSpecDisplay && quantity) {
+ display = `${weightSpecDisplay}————${quantity}件`;
+ } else if (weightSpecDisplay) {
+ display = weightSpecDisplay;
+ } else if (quantity) {
+ display = `${quantity}件`;
+ }
+
+ console.log(`第${i}组数据处理结果: weightSpecDisplay=${weightSpecDisplay}, quantity=${quantity}, display=${display}`);
+
+ result.push({
+ weightSpec: weightSpecDisplay,
+ quantity: quantity,
+ display: display
+ });
+ }
+
+ console.log('最终处理结果:', result);
+ return result;
+}
+
Page({
// 分享给朋友/群聊
onShareAppMessage() {
@@ -240,6 +320,71 @@ Page({
// 处理grossWeight为null或无效的情况,返回空字符串以支持文字输入
const grossWeightValue = product.grossWeight !== null && product.grossWeight !== undefined ? product.grossWeight : '';
+
+ // 处理净重、件数据和规格数据,获取一一对应的显示数组
+ // 注意:数据库中的规格字段包含净重信息,我们需要与件数数据正确匹配
+ // 修复:根据用户反馈,数据库中的规格字段内容为:净重46-47,净重44-43,净重47-48
+ // 我们需要将件数数据正确分割并与净重信息对应
+
+ // 首先处理净重和规格数据(它们可能都在spec字段中)
+ let weightSpecString = '';
+ let quantityString = '';
+
+ // 检查规格字段是否包含净重信息
+ console.log('=== 数据库字段调试信息 ===');
+ console.log('product.spec:', product.spec);
+ console.log('product.specification:', product.specification);
+ console.log('product.quantity:', product.quantity);
+ console.log('product.minOrder:', product.minOrder);
+ console.log('product.grossWeight:', grossWeightValue);
+
+ if (product.spec && typeof product.spec === 'string' && product.spec.includes('净重')) {
+ // 如果规格字段包含净重信息,则使用该字段作为净重规格数据
+ weightSpecString = product.spec;
+ console.log('使用规格字段作为净重规格数据:', weightSpecString);
+ } else if (product.specification && typeof product.specification === 'string' && product.specification.includes('净重')) {
+ // 检查specification字段
+ weightSpecString = product.specification;
+ console.log('使用specification字段作为净重规格数据:', weightSpecString);
+ } else if (grossWeightValue) {
+ // 如果有单独的净重字段,则使用净重字段
+ weightSpecString = grossWeightValue;
+ console.log('使用净重字段作为净重规格数据:', weightSpecString);
+ } else {
+ console.log('未找到净重规格数据');
+ }
+
+ // 处理件数数据
+ console.log('=== 件数数据调试信息 ===');
+ console.log('原始件数数据:', product.quantity);
+ console.log('原始minOrder数据:', product.minOrder);
+
+ // 修复:与格式化数据保持一致,优先使用minOrder
+ if (product.minOrder) {
+ quantityString = String(product.minOrder);
+ console.log('使用minOrder作为件数数据:', quantityString);
+ } else if (product.quantity && typeof product.quantity === 'string') {
+ quantityString = product.quantity;
+ console.log('件数数据为字符串:', quantityString);
+ } else if (product.quantity) {
+ // 如果件数不是字符串,转换为字符串
+ quantityString = String(product.quantity);
+ console.log('件数数据转换为字符串:', quantityString);
+ } else {
+ console.log('未找到件数数据');
+ }
+
+ console.log('准备传递给processWeightAndQuantityData的数据:', {
+ weightSpecString: weightSpecString,
+ quantityString: quantityString
+ });
+
+ const weightQuantityData = processWeightAndQuantityData(weightSpecString, quantityString, '');
+
+ console.log('=== 处理结果调试信息 ===');
+ console.log('weightSpecString:', weightSpecString);
+ console.log('quantityString:', quantityString);
+ console.log('weightQuantityData处理结果:', weightQuantityData);
// 转换supplyStatus字段值
let supplyStatusValue = product.supplyStatus || '';
@@ -326,7 +471,9 @@ Page({
product_contact: contactName,
contact_phone: contactPhone,
// 确保reservedCount字段使用我们计算得到的值,放在最后以覆盖其他来源的值
- reservedCount: finalReservationCount
+ reservedCount: finalReservationCount,
+ // 添加净重和件数的一一对应数据
+ weightQuantityData: weightQuantityData
};
console.log('最终格式化后的数据:', {
diff --git a/pages/goods-detail/goods-detail.wxml b/pages/goods-detail/goods-detail.wxml
index 615552f..f151a57 100644
--- a/pages/goods-detail/goods-detail.wxml
+++ b/pages/goods-detail/goods-detail.wxml
@@ -54,6 +54,7 @@
bindtap="onFavoriteClick"
style="display: flex; align-items: center;"
>
+ 收藏
{{isFavorite ? '❤️' : '🤍'}}
@@ -98,23 +99,18 @@
-
-
-
- 件数
-
-
- {{goodsDetail.minOrder || '暂无'}}
-
-
-
-
- 规格
-
-
- {{goodsDetail.spec || '暂无'}}
+
+
+
+
+
+ 规格信息
+
+
+
+ {{item.display}}
-
+
diff --git a/pages/goods-detail/goods-detail.wxss b/pages/goods-detail/goods-detail.wxss
index 74453c9..0439b3b 100644
--- a/pages/goods-detail/goods-detail.wxss
+++ b/pages/goods-detail/goods-detail.wxss
@@ -654,4 +654,61 @@
.auth-cancel-button::after {
border: none;
+}
+
+/* 净重件数对应信息样式 */
+.weight-quantity-info {
+ background-color: #ffffff;
+ margin: 16rpx;
+ padding: 24rpx;
+ border-radius: 12rpx;
+ box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
+ border: 1rpx solid #f0f0f0;
+}
+
+.wq-title {
+ font-size: 32rpx;
+ font-weight: 600;
+ color: #262626;
+ margin-bottom: 16rpx;
+ padding-bottom: 12rpx;
+ border-bottom: 1rpx solid #f0f0f0;
+ position: relative;
+}
+
+.wq-title::after {
+ content: '';
+ position: absolute;
+ bottom: -1rpx;
+ left: 0;
+ width: 60rpx;
+ height: 4rpx;
+ background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
+ border-radius: 2rpx;
+}
+
+.wq-list {
+ display: flex;
+ flex-direction: column;
+ gap: 12rpx;
+}
+
+.wq-item {
+ background-color: #f8f9fa;
+ padding: 16rpx 20rpx;
+ border-radius: 8rpx;
+ border-left: 4rpx solid #1890ff;
+ transition: all 0.3s ease;
+}
+
+.wq-item:active {
+ background-color: #e6f7ff;
+ transform: translateX(4rpx);
+}
+
+.wq-text {
+ font-size: 28rpx;
+ color: #595959;
+ line-height: 1.5;
+ font-weight: 500;
}
\ No newline at end of file