Browse Source

修复商品详情页面对比价格列表点击跳转功能

pull/12/head
徐飞洋 2 months ago
parent
commit
2d65a60dd5
  1. 31
      pages/goods-detail/goods-detail.js
  2. 4
      pages/goods-detail/goods-detail.wxml

31
pages/goods-detail/goods-detail.js

@ -502,6 +502,37 @@ Page({
loadingFavorite: false, // 收藏数据加载状态
},
// 点击对比价格列表中的商品,跳转到对应的商品详情页
viewCompareGoodsDetail: function(e) {
const item = e.currentTarget.dataset.item;
if (!item) {
console.error('点击的商品项数据不存在');
return;
}
// 获取商品ID
const productId = item.id || item.productId;
if (!productId) {
console.error('商品ID不存在');
return;
}
// 跳转到商品详情页
wx.navigateTo({
url: `/pages/goods-detail/goods-detail?productId=${productId}`,
success: function() {
console.log('成功跳转到商品详情页,商品ID:', productId);
},
fail: function(error) {
console.error('跳转到商品详情页失败:', error);
wx.showToast({
title: '跳转失败,请稍后重试',
icon: 'none'
});
}
});
},
onLoad: function (options) {
console.log('商品详情页面加载,参数:', options);

4
pages/goods-detail/goods-detail.wxml

@ -220,7 +220,7 @@
<!-- 商品列表 -->
<view class="compare-goods-list">
<block wx:if="{{activeTab === 'home' && homeGoods.length > 0}}">
<view wx:for="{{homeGoods}}" wx:key="id" class="compare-goods-item">
<view wx:for="{{homeGoods}}" wx:key="id" class="compare-goods-item" bindtap="viewCompareGoodsDetail" data-item="{{item}}">
<view class="product-image-wrapper">
<!-- 视频处理:根据mediaItems中的类型字段判断 -->
<video
@ -260,7 +260,7 @@
</block>
<block wx:if="{{activeTab === 'favorite' && favoriteGoods.length > 0}}">
<view wx:for="{{favoriteGoods}}" wx:key="id" class="compare-goods-item">
<view wx:for="{{favoriteGoods}}" wx:key="id" class="compare-goods-item" bindtap="viewCompareGoodsDetail" data-item="{{item}}">
<view class="product-image-wrapper">
<!-- 视频处理:根据mediaItems中的类型字段判断 -->
<video

Loading…
Cancel
Save