diff --git a/WeChatProgram/api/comment.js b/WeChatProgram/api/comment.js
new file mode 100644
index 00000000..8c7430c3
--- /dev/null
+++ b/WeChatProgram/api/comment.js
@@ -0,0 +1,24 @@
+const request = require('../utils/request')
+
+module.exports = {
+ listByProduct(productId) {
+ return request({
+ url: `/comment/list/product/${productId}`
+ })
+ },
+
+ create(data) {
+ return request({
+ url: '/comment/create',
+ method: 'POST',
+ data
+ })
+ },
+
+ delete(id) {
+ return request({
+ url: `/comment/delete/${id}`,
+ method: 'DELETE'
+ })
+ }
+}
diff --git a/WeChatProgram/pages/cart/index.js b/WeChatProgram/pages/cart/index.js
index 5cef611a..30aaa61d 100644
--- a/WeChatProgram/pages/cart/index.js
+++ b/WeChatProgram/pages/cart/index.js
@@ -242,11 +242,10 @@ Page({
}
if (selectedCouponKey === NO_COUPON_KEY) {
- const vipCoupons = list
- .filter(item => item.sourceType === 'SYSTEM_VIP')
+ const bestCoupons = list
.sort((left, right) => calculateCouponDiscount(right, subtotalAmount) - calculateCouponDiscount(left, subtotalAmount))
- if (vipCoupons.length) {
- selectedCouponKey = vipCoupons[0].key
+ if (bestCoupons.length) {
+ selectedCouponKey = bestCoupons[0].key
}
}
diff --git a/WeChatProgram/pages/product-detail/index.js b/WeChatProgram/pages/product-detail/index.js
index a646a996..2aab32ec 100644
--- a/WeChatProgram/pages/product-detail/index.js
+++ b/WeChatProgram/pages/product-detail/index.js
@@ -1,6 +1,7 @@
const cartApi = require('../../api/cart')
const productApi = require('../../api/product')
const productLikeApi = require('../../api/product-like')
+const commentApi = require('../../api/comment')
const shopApi = require('../../api/shop')
const wishlistApi = require('../../api/wishlist')
const actionGuard = require('../../utils/action-guard')
@@ -65,6 +66,9 @@ Page({
product: null,
productImages: [],
shopInfo: null,
+ comments: [],
+ commentText: '',
+ replyTarget: null,
isFavorite: false,
isLiked: false,
artistCountText: '门店安排',
@@ -122,8 +126,9 @@ Page({
earliestBookableText: estimateEarliestBookable(shopInfo && shopInfo.businessHours)
})
+ await this.loadComments()
if (auth.isLoggedIn()) {
- this.loadInteractionStatus()
+ await this.loadInteractionStatus()
} else {
this.setData({
isFavorite: false,
@@ -159,6 +164,22 @@ Page({
} catch (error) {}
},
+ async loadComments() {
+ const product = this.data.product
+ if (!product || !product.id) {
+ this.setData({ comments: [] })
+ return
+ }
+ try {
+ const comments = await commentApi.listByProduct(product.id)
+ this.setData({
+ comments: Array.isArray(comments) ? comments : []
+ })
+ } catch (error) {
+ this.setData({ comments: [] })
+ }
+ },
+
handleBack() {
navigation.goBack('/pages/products/index')
},
@@ -323,4 +344,46 @@ Page({
})
}
}
+,
+
+ handleCommentInput(event) {
+ this.setData({
+ commentText: event.detail.value
+ })
+ },
+
+ handleReply(event) {
+ const comment = event.currentTarget.dataset.comment
+ this.setData({
+ replyTarget: comment || null
+ })
+ },
+
+ async handleSubmitComment() {
+ const product = this.data.product
+ const content = String(this.data.commentText || '').trim()
+ if (!product || !product.id || !navigation.ensureLogin('发表评论')) {
+ return
+ }
+ if (!content) {
+ wx.showToast({ title: '请输入评论内容', icon: 'none' })
+ return
+ }
+ try {
+ await commentApi.create({
+ productId: product.id,
+ shopId: product.shopId,
+ parentCommentId: this.data.replyTarget ? this.data.replyTarget.id : null,
+ commentContent: content
+ })
+ this.setData({
+ commentText: '',
+ replyTarget: null
+ })
+ await this.loadComments()
+ wx.showToast({ title: '评论已发布', icon: 'none' })
+ } catch (error) {
+ wx.showToast({ title: error.message || '评论发布失败', icon: 'none' })
+ }
+ }
})
diff --git a/WeChatProgram/pages/product-detail/index.wxml b/WeChatProgram/pages/product-detail/index.wxml
index 0cbfb816..f82c399f 100644
--- a/WeChatProgram/pages/product-detail/index.wxml
+++ b/WeChatProgram/pages/product-detail/index.wxml
@@ -78,6 +78,35 @@
{{product.descriptionText}}
+
+