|
|
import http from '../../../utils/api'const baseUrl = require('../../../utils/baseUrl')
Page({ data: { baseUrl: baseUrl, loadMoreText: '上拉加载更多', evaluations: [], pageNo: 1, pageSize: 10, total: 0, isLoading: false, hasMore: true },
onLoad() { this.getfeedback(true) },
// 服务评价列表
getfeedback(isRefresh = false) { // 防止重复请求
if (this.data.isLoading) return // 如果没有更多数据且不是刷新,直接返回
if (!this.data.hasMore && !isRefresh) { this.setData({ loadMoreText: '—— 没有更多了 ——' }) return }
this.setData({ isLoading: true }) // 如果是刷新,重置为第一页
if (isRefresh) { this.setData({ pageNo: 1, hasMore: true }) }
// 显示加载提示
if (this.data.pageNo > 1) { this.setData({ loadMoreText: '加载中...' }) }
http.feedback({ data: { type: '服务评价', pageNo: this.data.pageNo, pageSize: this.data.pageSize }, success: res => { console.log('评价列表响应:', res) if (res && res.rows) { const list = res.rows || [] const total = res.total || 0 // 判断是否还有更多数据
const hasMore = this.data.pageNo * this.data.pageSize < total this.setData({ evaluations: isRefresh ? list : this.data.evaluations.concat(list), total: total, hasMore: hasMore, loadMoreText: hasMore ? '上拉加载更多' : '—— 没有更多了 ——', pageNo: this.data.pageNo + 1 }) } else { // 处理异常情况
if (isRefresh) { this.setData({ evaluations: [], hasMore: false, loadMoreText: '—— 没有更多了 ——' }) } } }, fail: err => { console.error('获取评价列表失败:', err) wx.showToast({ title: '加载失败', icon: 'none' }) // 加载失败时,恢复加载提示
this.setData({ loadMoreText: this.data.hasMore ? '点击重试' : '—— 没有更多了 ——' }) }, complete: () => { this.setData({ isLoading: false }) wx.hideNavigationBarLoading() wx.stopPullDownRefresh() } }) },
// 下拉刷新
onPullDownRefresh() { wx.showNavigationBarLoading() this.getfeedback(true) },
// 上拉加载更多
onReachBottom() { if (this.data.hasMore && !this.data.isLoading) { this.getfeedback() } else if (!this.data.hasMore) { this.setData({ loadMoreText: '—— 没有更多了 ——' }) } },
// 重新加载(可用于点击重试)
retryLoad() { if (this.data.evaluations.length === 0) { this.getfeedback(true) } else if (this.data.hasMore) { this.getfeedback() } }})
|