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