功能:完善评论测试与优惠券最优选择

This commit is contained in:
xiaowang
2026-05-16 14:28:42 +08:00
parent 1f05e0ab44
commit 4563dd2538
31 changed files with 1130 additions and 581 deletions
@@ -0,0 +1,71 @@
const commentApi = require('../../api/comment')
Page({
data: {
loading: false,
keyword: '',
comments: []
},
onShow() {
this.loadComments()
},
async onPullDownRefresh() {
await this.loadComments()
wx.stopPullDownRefresh()
},
handleKeywordInput(event) {
this.setData({
keyword: event.detail.value
})
},
async loadComments() {
this.setData({ loading: true })
try {
const comments = await commentApi.listComments({
keyword: this.data.keyword || undefined
})
this.setData({
comments: Array.isArray(comments) ? comments : []
})
} catch (error) {
wx.showToast({
title: error.message || '评论加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
handleSearch() {
this.loadComments()
},
handleDelete(event) {
const id = event.currentTarget.dataset.id
if (!id) {
return
}
wx.showModal({
title: '删除评论',
content: '确认删除这条评论?',
confirmText: '删除',
success: async res => {
if (!res.confirm) {
return
}
try {
await commentApi.deleteComment(id)
wx.showToast({ title: '评论已删除', icon: 'none' })
this.loadComments()
} catch (error) {
wx.showToast({ title: error.message || '删除失败', icon: 'none' })
}
}
})
}
})