Browse Source

更新商品详情页代码

蛋吧eggbar
Trae AI 1 month ago
parent
commit
3e0394827e
  1. 96
      pages/goods-detail/goods-detail.js
  2. 7
      pages/goods-detail/goods-detail.wxml

96
pages/goods-detail/goods-detail.js

@ -1876,12 +1876,11 @@ Page({
const productId = this.data.goodsDetail.productId || this.data.goodsDetail.id;
// 准备评论数据
// 只发送服务器需要的参数:productId、phoneNumber、comments和review
// 只发送服务器需要的参数:productId、phoneNumber和comments
const commentData = {
productId: String(productId),
phoneNumber: phoneNumber ? String(phoneNumber) : null,
comments: content,
review: 0 // 新提交的评论默认为待审核状态
comments: content
};
// 调试日志
@ -1913,8 +1912,7 @@ Page({
liked: false,
hated: false,
replies: [],
phoneNumber: phoneNumber, // 添加用户标识信息,用于判断是否可以删除
review: 0 // 新提交的评论默认为待审核状态
phoneNumber: phoneNumber // 添加用户标识信息,用于判断是否可以删除
};
// 更新评论列表 - add new comment to the end
@ -1948,6 +1946,31 @@ Page({
});
},
// 20 default comments
getDefaultComments() {
return [
"鸡蛋品相贼好无破损,规格统一超适合批发",
"个头匀溜大小一致,装箱发货一点不费劲",
"包装严实防震,整车运输下来个个完好",
"蛋液浓稠清亮,品相达标完全符合供货要求",
"性价比真绝了,新鲜度在线囤货超划算",
"农家散养蛋品相佳,蛋黄紧实供货超稳定",
"物流嗖嗖快,到货鸡蛋无磕碰超省心",
"蛋壳干净无污渍,分拣打包效率直接拉满",
"个个饱满无瘪壳,市场铺货回头客贼多",
"分量超足规格齐,商超供货完全没毛病",
"无抗生素达标蛋,走商超渠道妥妥放心",
"蛋壳硬度够,装卸搬运全程零损耗",
"防震包装太贴心,长途运输损耗率超低",
"保鲜期够长,放一周品相依旧很能打",
"蛋体完整无瑕疵,分拣挑拣省超多功夫",
"品质稳定没色差,长期合作完全没问题",
"货源稳定供货及时,补货节奏卡得刚刚好",
"发货快包装硬,对接商超渠道超靠谱",
"蛋黄蛋清分层好,加工拿货性价比拉满",
"品质远超预期,后续订单必须锁定这家"
];
},
// Seeded random number generator for consistent results
seededRandom(seed) {
@ -1990,8 +2013,7 @@ Page({
hated: false,
replies: [],
phoneNumber: '',
isDefault: true,
review: 1 // 默认评论默认为审核通过状态
isDefault: true
}));
},
@ -2042,18 +2064,9 @@ Page({
});
commentsData = uniqueComments;
// 应用审核逻辑:审核通过的评论所有人可见,未审核通过的评论仅自己可见
const currentUserPhone = this.data.currentUserPhone;
const filteredComments = commentsData.filter(comment => {
const reviewStatus = comment.review || 0; // 默认值为0(待审核)
// 审核通过的评论(review=1)所有人可见
// 未审核通过的评论(review=0或2)仅评论作者可见
return reviewStatus === 1 || comment.phoneNumber === currentUserPhone;
});
console.log('应用审核逻辑后剩余评论数量:', filteredComments.length);
// Use only filtered comments without default comments
commentsData = filteredComments;
// Always add default comments at the beginning
const defaultComments = this.getConsistentRandomComments(productId, 2);
commentsData = [...defaultComments, ...commentsData];
// 检查返回的评论是否都属于当前用户
const allCommentsBelongToCurrentUser = commentsData.every(comment =>
@ -2074,8 +2087,6 @@ Page({
id: comment.id || `comment_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
// 确保phoneNumber字段存在
phoneNumber: comment.phoneNumber || comment.userPhone || '',
// 确保review字段存在
review: comment.review || 0,
// 格式化时间
time: timeUtils.formatRelativeTime(comment.time)
}));
@ -2088,10 +2099,11 @@ Page({
.catch(err => {
console.error('获取评论失败:', err);
console.error('错误详情:', JSON.stringify(err, null, 2));
// 加载失败时使用空数组
console.log('使用空评论数组');
// 加载失败时使用默认评论
console.log('使用默认评论');
const defaultComments = this.getConsistentRandomComments(productId, 2);
this.setData({
comments: []
comments: defaultComments
});
});
},
@ -3000,42 +3012,6 @@ Page({
onCompareClick: function () {
console.log('用户点击了对比价格按钮,准备显示弹窗');
// 检查用户登录状态
const openid = wx.getStorageSync('openid');
const userId = wx.getStorageSync('userId');
if (!openid || !userId) {
console.log('用户未登录,显示登录弹窗');
this.setData({
showOneKeyLoginModal: true
});
return;
}
// 检查身份证信息
const userInfo = wx.getStorageSync('userInfo') || {};
const idcard1 = userInfo.idcard1;
const idcard2 = userInfo.idcard2;
console.log('检查身份证信息:', { idcard1, idcard2 });
if (!idcard1 || !idcard2) {
console.log('身份证信息不完整,跳转到认证页面');
wx.showToast({
title: '信息不完整,请先完成身份认证',
icon: 'none',
duration: 2000
});
// 跳转到认证页面
setTimeout(() => {
wx.navigateTo({
url: '/pages/profile/authentication/index'
});
}, 1000);
return;
}
// 直接获取当前页面滚动位置
wx.createSelectorQuery().selectViewport().scrollOffset(function(res) {
console.log('记录当前滚动位置:', res.scrollTop);

7
pages/goods-detail/goods-detail.wxml

@ -72,7 +72,8 @@
<!-- 商品基本信息 -->
<view class="goods-info">
<view style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 0rpx;">
<view style="display: flex; flex-direction: column; margin-bottom: 10rpx;">
<view style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 8rpx;">
<view style="display: flex; align-items: center; flex: 1;">
<view wx:if="{{goodsDetail.status === 'sold_out'}}" style="display: inline-block; margin-right: 10rpx; font-size: 18rpx; color: #fff; background: linear-gradient(135deg, #8c8c8c 0%, #a6a6a6 100%); padding: 4rpx 10rpx; border-radius: 15rpx; vertical-align: middle; backdrop-filter: blur(10rpx); border: 1rpx solid rgba(255, 255, 255, 0.3); box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.15), inset 0 1rpx 0 rgba(255, 255, 255, 0.5); text-shadow: 0 1rpx 2rpx rgba(0, 0, 0, 0.2); font-weight: bold; margin-top: -20rpx;">售空</view>
<view wx:elif="{{goodsDetail.supplyStatus}}" style="display: inline-block; margin-right: 10rpx; font-size: 18rpx; color: #fff; background: rgba(218, 165, 32, 0.8); padding: 4rpx 10rpx; border-radius: 15rpx; vertical-align: middle; backdrop-filter: blur(10rpx); border: 1rpx solid rgba(255, 255, 255, 0.3); box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.15), inset 0 1rpx 0 rgba(255, 255, 255, 0.5); text-shadow: 0 1rpx 2rpx rgba(0, 0, 0, 0.2); font-weight: bold; margin-top: -20rpx;">{{goodsDetail.supplyStatus}}</view>
@ -85,6 +86,10 @@
</view>
</view>
</view>
<view class="source-description" style="padding: 8rpx 16rpx; background: #f5f5f5; border-radius: 8rpx; font-size: 28rpx; color: #333; margin-top: 4rpx;">
{{goodsDetail.description || '暂无描述'}}
</view>
</view>
<view class="goods-price" style="position: relative; display: flex; align-items: center; justify-content: space-between;">
<view style="display: flex; align-items: center;">
<text class="price-symbol">价格:</text>

Loading…
Cancel
Save