Browse Source

可正常显示对比价格中的图片

Xfy
User 1 week ago
parent
commit
bda89eedef
  1. 61
      pages/compare_price/index.js
  2. 21
      pages/compare_price/index.wxml
  3. 2
      pages/goods-detail/goods-detail.wxml

61
pages/compare_price/index.js

@ -41,6 +41,45 @@ Page({
console.log('图片加载完成:', e);
},
// 跳转到商品详情页面
navigateToGoodsDetail: function (e) {
const item = e.currentTarget.dataset.item;
if (!item) {
console.error('商品信息为空');
return;
}
console.log('跳转到商品详情页面,商品信息:', item);
// 传递完整的商品数据,避免API调用失败
const goodsData = encodeURIComponent(JSON.stringify(item));
// 跳转到商品详情页面,传递完整的商品数据
wx.navigateTo({
url: `/pages/goods-detail/goods-detail?goodsData=${goodsData}`,
success: function () {
console.log('成功跳转到商品详情页面');
},
fail: function (error) {
console.error('跳转到商品详情页面失败:', error);
wx.showToast({
title: '跳转失败,请稍后重试',
icon: 'none'
});
}
});
},
// 重置选择,返回类别选择页面
resetSelection: function () {
this.setData({
selectedOption: '',
goods: [],
loading: false
});
console.log('已重置选择,返回类别选择页面');
},
// 关闭提示弹窗
closeTips: function () {
this.setData({
@ -73,6 +112,7 @@ Page({
// 清理 mediaItems 中的 URL,去除反引号和空格
// 同时处理 imageUrls 字段,将其转换为 mediaItems 格式
// 处理库存显示逻辑
const cleanedGoods = filteredGoods.map(item => {
// 首先清理 imageUrls 字段(如果存在)
if (item.imageUrls && Array.isArray(item.imageUrls)) {
@ -99,6 +139,27 @@ Page({
return media;
});
}
// 处理库存显示逻辑(参考首页的处理方式)
const quantity = item.quantity || item.minOrder || item.stock || item.inventory || item.availableStock || item.totalAvailable;
const totalStock = quantity;
let displayStock;
if (totalStock >= 10000) {
// 库存>=10000时显示"库存充足"
displayStock = '充足';
} else if (totalStock === 0) {
// 库存=0时显示"暂无"
displayStock = '暂无';
} else {
// 其他情况显示具体数字
displayStock = totalStock;
}
// 更新商品的库存显示
item.totalStock = displayStock;
item.originalTotalStock = totalStock;
return item;
});

21
pages/compare_price/index.wxml

@ -4,6 +4,8 @@
<image src="../../images/background.png" mode="aspectFill" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></image>
<scroll-view style="position: relative; z-index: 10; width: 100%; height: 100%;" scroll-y="true" enable-back-to-top="true">
<view style="width: 100%; display: flex; flex-direction: column; align-items: center; padding: 20rpx; padding-bottom: 100rpx;">
<!-- 类别选择区域 -->
<view wx:if="{{!selectedOption}}">
<view style="background-color: rgba(255, 255, 255, 0.8); border-radius: 10rpx; padding: 20rpx; margin-bottom: 20rpx;">
<text style="font-size: 32rpx; font-weight: bold; color: #333; text-align: center;">请选择想要了解的商品</text>
</view>
@ -12,6 +14,12 @@
<button style="background-color: rgba(255, 255, 255, 0.8); color: #333; border-radius: 8rpx; padding: 20rpx; font-size: 28rpx;" bindtap="selectOption" data-option="粉壳">粉壳</button>
<button style="background-color: rgba(255, 255, 255, 0.8); color: #333; border-radius: 8rpx; padding: 20rpx; font-size: 28rpx;" bindtap="selectOption" data-option="褐壳">褐壳</button>
</view>
</view>
<!-- 返回按钮(选择后显示) -->
<view wx:else style="margin-bottom: 20rpx; width: 100%; max-width: 400rpx;">
<button style="background-color: rgba(255, 255, 255, 0.8); color: #333; border-radius: 8rpx; padding: 20rpx; font-size: 28rpx;" bindtap="resetSelection">返回选择</button>
</view>
<!-- 商品列表 -->
<view wx:if="{{loading}}" style="margin-top: 40rpx; color: #fff; text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.5);">
@ -21,7 +29,7 @@
<view wx:else>
<view wx:if="{{goods.length > 0}}" style="margin-top: 40rpx; width: 100%; max-width: 750rpx;">
<view style="background-color: rgba(255, 255, 255, 0.8); border-radius: 10rpx; padding: 20rpx; margin-bottom: 20rpx;">
<text style="font-size: 28rpx; font-weight: bold; color: #333; text-align: center; display: block;">{{selectedOption}}商品列表</text>
<text style="font-size: 28rpx; font-weight: bold; color: #333; text-align: center; display: block;">{{selectedOption}}在售商品</text>
</view>
<!-- 商品卡片列表 -->
@ -33,6 +41,7 @@
wx:key="id"
wx:if="{{index % 2 === 0}}"
data-item="{{item}}"
bindtap="navigateToGoodsDetail"
>
<view class="product-card {{item.status === 'sold_out' ? 'sold-out-grayscale' : ''}}" style="position: relative; background-color: rgba(255, 255, 255, 0.8); border-radius: 16rpx; overflow: hidden;">
<!-- 售空商品白色覆盖层 -->
@ -94,6 +103,7 @@
wx:key="id"
wx:if="{{index % 2 === 1}}"
data-item="{{item}}"
bindtap="navigateToGoodsDetail"
>
<view class="product-card {{item.status === 'sold_out' ? 'sold-out-grayscale' : ''}}" style="position: relative; background-color: rgba(255, 255, 255, 0.8); border-radius: 16rpx; overflow: hidden;">
<!-- 售空商品白色覆盖层 -->
@ -152,7 +162,7 @@
</view>
<view wx:else style="margin-top: 40rpx; color: #fff; text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.5);">
<text>暂无商品数据</text>
<text>暂无在售数据</text>
</view>
</view>
</view>
@ -160,8 +170,11 @@
<!-- 透明弹窗提示 -->
<view wx:if="{{showTips}}" style="position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 100; background-color: rgba(0, 0, 0, 0.3); display: flex; justify-content: center; align-items: center;">
<view style="background-color: rgba(255, 255, 255, 0.9); border-radius: 16rpx; padding: 40rpx; width: 80%; max-width: 500rpx; text-align: center;">
<text style="font-size: 32rpx; font-weight: bold; color: #333; margin-bottom: 20rpx; display: block;">提示</text>
<text style="font-size: 28rpx; color: #666; line-height: 40rpx;">欢迎使用对比价格功能,此页面用于对比不同商品的价格信息。</text>
<text style="font-size: 32rpx; font-weight: bold; color: #333; margin-bottom: 20rpx; display: block;">欢迎使用对比价格功能</text>
<text style="font-size: 28rpx; color: #666; line-height: 40rpx;">此页面用于对比不同商品的价格信息。</text>
<text style="font-size: 28rpx; color: #f10b0bff; line-height: 40rpx;">对比同种商品,不同规格</text>
<text style="font-size: 28rpx; color: #666; line-height: 40rpx;">的商品价格信息。</text>
<view style="margin-top: 40rpx;">
<button style="background-color: #ff6b81; color: #fff; border-radius: 8rpx; padding: 12rpx 40rpx; font-size: 28rpx;" bindtap="closeTips">我知道了</button>
</view>

2
pages/goods-detail/goods-detail.wxml

@ -319,7 +319,7 @@
bindtap="switchTab"
data-tab="home"
>
首页相同规格数据
相同规格的同种类型
</view>
<view
class="compare-tab {{activeTab === 'favorite' ? 'active' : ''}}"

Loading…
Cancel
Save