功能:完善评论测试与优惠券最优选择
This commit is contained in:
@@ -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' })
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user