From 224c0df14f1a129fb56efcdfa83f54e413573d70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Sat, 6 Dec 2025 15:01:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=BC=96=E8=BE=91=E8=B4=A7?= =?UTF-8?q?=E6=BA=90=E9=A1=B5=E9=9D=A2=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=8C=85?= =?UTF-8?q?=E6=8B=AC=E6=96=87=E6=9C=AC=E5=B7=A6=E5=AF=B9=E9=BD=90=E5=92=8C?= =?UTF-8?q?=E5=8F=B3=E4=BE=A7=E7=95=99=E7=99=BD=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/buyer/index.js | 2 + pages/goods-detail/goods-detail.js | 64 ++++++++++++++++++++++++--- pages/goods-detail/goods-detail.wxml | 37 +++++++++------- pages/seller/index.js | 23 +++++----- pages/seller/index.wxml | 66 ++++++++++++++-------------- 5 files changed, 125 insertions(+), 67 deletions(-) diff --git a/pages/buyer/index.js b/pages/buyer/index.js index 540d5e4..7d5d0df 100644 --- a/pages/buyer/index.js +++ b/pages/buyer/index.js @@ -645,6 +645,8 @@ Page({ imageUrls: product.imageUrls || [], reservedCount: reservedCount, createdAt: product.created_at || product.createTime || null, + product_contact: product.product_contact || '', + contact_phone: product.contact_phone || '', isReserved: reservedGoodsIds.some(id => String(id) === String(product.id) || String(id) === String(product.productId) diff --git a/pages/goods-detail/goods-detail.js b/pages/goods-detail/goods-detail.js index 6845cf0..39bae10 100644 --- a/pages/goods-detail/goods-detail.js +++ b/pages/goods-detail/goods-detail.js @@ -30,6 +30,7 @@ Page({ showImagePreview: false, // 控制图片预览弹窗显示 previewImageUrls: [], // 预览的图片URL列表 previewImageIndex: 0, // 当前预览图片的索引 + fromSeller: false, // 是否来自seller页面 // 图片缩放相关状态 scale: 1, // 当前缩放比例 lastScale: 1, // 上一次缩放比例 @@ -45,6 +46,9 @@ Page({ onLoad(options) { console.log('商品详情页面加载,参数:', options); + // 检查是否来自seller页面 + const fromSeller = options.fromSeller === '1' ? true : false; + // 支持两种参数传递方式:直接传递商品数据或仅传递商品ID if (options.goodsData) { try { @@ -52,9 +56,50 @@ Page({ const goodsData = JSON.parse(decodeURIComponent(options.goodsData)); console.log('解析后的商品数据:', goodsData); - // 设置商品详情数据 + // 从本地存储获取已预约商品ID列表 + const reservedGoodsIds = wx.getStorageSync('reservedGoodsIds') || []; + const product = goodsData; + + // 确保商品ID的一致性 + const productIdStr = String(product.productId || product.id); + + // 增强的预约人数计算逻辑 + const selectedValue = product.selected; + const reservedCountValue = product.reservedCount; + const reservationCountValue = product.reservationCount; + + const finalReservationCount = selectedValue !== undefined && selectedValue !== null ? selectedValue : + (reservedCountValue !== undefined && reservedCountValue !== null ? reservedCountValue : + (reservationCountValue || 0)); + + // 处理grossWeight为null或无效的情况,返回空字符串以支持文字输入 + const grossWeightValue = product.grossWeight !== null && product.grossWeight !== undefined ? product.grossWeight : ''; + + // 转换商品数据格式,与loadGoodsDetail保持一致 + const formattedGoods = { + id: productIdStr, + productId: productIdStr, + name: product.productName, + price: product.price, + minOrder: product.quantity, + yolk: product.yolk, + spec: product.specification, + region: product.region, + contact_phone: product.contact_phone || product.contactPhone, + product_contact: product.product_contact || product.contactName, + imageUrls: product.imageUrls || product.images || [], + displayGrossWeight: formatGrossWeight(grossWeightValue, product.weight), + isReserved: reservedGoodsIds.some(itemId => String(itemId) === productIdStr), + reservedCount: finalReservationCount, + created_at: product.created_at || product.createdAt, + updated_at: product.updated_at || product.updatedAt, + status: product.status || 'published' + }; + + // 设置商品详情数据和来源标识 this.setData({ - goodsDetail: goodsData + goodsDetail: formattedGoods, + fromSeller: fromSeller }); } catch (error) { console.error('解析商品数据失败:', error); @@ -71,6 +116,11 @@ Page({ } else if (options.id) { // 如果只传递了商品ID,则从服务器加载商品详情 this.loadGoodsDetail(options.id); + + // 设置来源标识 + this.setData({ + fromSeller: fromSeller + }); } else { wx.showToast({ title: '参数错误', @@ -123,14 +173,14 @@ Page({ yolk: product.yolk, spec: product.specification, region: product.region, - contact_phone: product.contactPhone, - product_contact: product.contactName, - imageUrls: product.images || [], + contact_phone: product.contact_phone || product.contactPhone, + product_contact: product.product_contact || product.contactName, + imageUrls: product.imageUrls || product.images || [], displayGrossWeight: formatGrossWeight(grossWeightValue, product.weight), isReserved: reservedGoodsIds.some(itemId => String(itemId) === productIdStr), reservedCount: finalReservationCount, - created_at: product.createdAt, - updated_at: product.updatedAt + created_at: product.created_at || product.createdAt, + updated_at: product.updated_at || product.updatedAt }; this.setData({ diff --git a/pages/goods-detail/goods-detail.wxml b/pages/goods-detail/goods-detail.wxml index ca26da4..e852ffc 100644 --- a/pages/goods-detail/goods-detail.wxml +++ b/pages/goods-detail/goods-detail.wxml @@ -1,30 +1,28 @@ - - - - - 商品详情 - - - × - - - - + @@ -99,7 +97,7 @@ - + 联系信息 @@ -119,7 +117,7 @@ - + + diff --git a/pages/seller/index.js b/pages/seller/index.js index 9f7d39b..a2a4da6 100644 --- a/pages/seller/index.js +++ b/pages/seller/index.js @@ -1917,6 +1917,7 @@ Page({ console.log(`从服务器获取到${type}类型商品数据,共`, res.products.length, '条'); // 处理服务器返回的商品数据 + console.log('【调试】服务器返回的商品数据:', res.products); const serverSupplies = res.products .filter(product => product.status !== 'hidden') .map(serverProduct => { @@ -1933,6 +1934,7 @@ Page({ return { id: serverProduct.productId, name: serverProduct.productName, + productName: serverProduct.productName, // 【新增】同时设置productName字段 price: serverProduct.price, minOrder: serverProduct.quantity, grossWeight: serverProduct.grossWeight, @@ -1945,7 +1947,10 @@ Page({ imageUrls: imageUrls, created_at: createdAt, formattedCreatedAt: formattedCreatedAt, - currentImageIndex: 0 + currentImageIndex: 0, + // 添加联系信息字段,确保与买蛋页面一致 + product_contact: serverProduct.product_contact || '', + contact_phone: serverProduct.contact_phone || '' }; }); @@ -2603,11 +2608,6 @@ Page({ pageScrollLock: true }) } - - // iOS设备特殊处理:阻止触摸事件 - if (this.isIOS()) { - this.blockTouchMove() - } }, // 启用页面滚动 @@ -2620,11 +2620,6 @@ Page({ pageScrollLock: false }) } - - // iOS设备特殊处理:恢复触摸事件 - if (this.isIOS()) { - this.unblockTouchMove() - } }, // 输入内容处理 @@ -3298,9 +3293,9 @@ Page({ } const goodsItem = e.currentTarget.dataset.item; - // 跳转到商品详情页面,并传递商品数据,使用encodeURIComponent编码JSON字符串 + // 跳转到商品详情页面,并传递商品数据和来源标识,使用encodeURIComponent编码JSON字符串 wx.navigateTo({ - url: '/pages/goods-detail/goods-detail?goodsData=' + encodeURIComponent(JSON.stringify(goodsItem)) + url: '/pages/goods-detail/goods-detail?goodsData=' + encodeURIComponent(JSON.stringify(goodsItem)) + '&fromSeller=1' }); }, @@ -3587,6 +3582,7 @@ Page({ editSupplyRegionArray = supply.region.split(' ').filter(item => item.trim() !== ''); } + console.log('【调试】supply对象完整结构:', supply); console.log('【调试】编辑弹窗数据设置:', { supplyRegion: supply.region, editSupplyRegion: supplyWithFormattedTime.region, @@ -4280,6 +4276,7 @@ Page({ showRejectReasonModal: false // 注意:这里不立即清空 currentRejectSupply,确保后续操作能使用 }); + // 恢复页面滚动 this.enablePageScroll(); }, diff --git a/pages/seller/index.wxml b/pages/seller/index.wxml index 48419aa..c48864c 100644 --- a/pages/seller/index.wxml +++ b/pages/seller/index.wxml @@ -121,7 +121,7 @@ - - - - + + + + @@ -674,13 +677,12 @@ - {{rejectReason}} + {{rejectReason}} - - - + +