与牧同行-兽医端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.0 KiB

  1. import http from '../../../utils/api'
  2. const baseUrl = require('../../../utils/baseUrl')
  3. Page({
  4. data: {
  5. baseUrl: baseUrl,
  6. loadMoreText: '上拉加载更多',
  7. evaluations: [],
  8. pageNo: 1,
  9. pageSize: 10,
  10. total: 0,
  11. isLoading: false,
  12. hasMore: true
  13. },
  14. onLoad() {
  15. this.getfeedback(true)
  16. },
  17. // 服务评价列表
  18. getfeedback(isRefresh = false) {
  19. // 防止重复请求
  20. if (this.data.isLoading) return
  21. // 如果没有更多数据且不是刷新,直接返回
  22. if (!this.data.hasMore && !isRefresh) {
  23. this.setData({
  24. loadMoreText: '—— 没有更多了 ——'
  25. })
  26. return
  27. }
  28. this.setData({ isLoading: true })
  29. // 如果是刷新,重置为第一页
  30. if (isRefresh) {
  31. this.setData({
  32. pageNo: 1,
  33. hasMore: true
  34. })
  35. }
  36. // 显示加载提示
  37. if (this.data.pageNo > 1) {
  38. this.setData({ loadMoreText: '加载中...' })
  39. }
  40. http.feedback({
  41. data: {
  42. type: '服务评价',
  43. pageNo: this.data.pageNo,
  44. pageSize: this.data.pageSize
  45. },
  46. success: res => {
  47. console.log('评价列表响应:', res)
  48. if (res && res.rows) {
  49. const list = res.rows || []
  50. const total = res.total || 0
  51. // 判断是否还有更多数据
  52. const hasMore = this.data.pageNo * this.data.pageSize < total
  53. this.setData({
  54. evaluations: isRefresh ? list : this.data.evaluations.concat(list),
  55. total: total,
  56. hasMore: hasMore,
  57. loadMoreText: hasMore ? '上拉加载更多' : '—— 没有更多了 ——',
  58. pageNo: this.data.pageNo + 1
  59. })
  60. } else {
  61. // 处理异常情况
  62. if (isRefresh) {
  63. this.setData({
  64. evaluations: [],
  65. hasMore: false,
  66. loadMoreText: '—— 没有更多了 ——'
  67. })
  68. }
  69. }
  70. },
  71. fail: err => {
  72. console.error('获取评价列表失败:', err)
  73. wx.showToast({
  74. title: '加载失败',
  75. icon: 'none'
  76. })
  77. // 加载失败时,恢复加载提示
  78. this.setData({
  79. loadMoreText: this.data.hasMore ? '点击重试' : '—— 没有更多了 ——'
  80. })
  81. },
  82. complete: () => {
  83. this.setData({ isLoading: false })
  84. wx.hideNavigationBarLoading()
  85. wx.stopPullDownRefresh()
  86. }
  87. })
  88. },
  89. // 下拉刷新
  90. onPullDownRefresh() {
  91. wx.showNavigationBarLoading()
  92. this.getfeedback(true)
  93. },
  94. // 上拉加载更多
  95. onReachBottom() {
  96. if (this.data.hasMore && !this.data.isLoading) {
  97. this.getfeedback()
  98. } else if (!this.data.hasMore) {
  99. this.setData({
  100. loadMoreText: '—— 没有更多了 ——'
  101. })
  102. }
  103. },
  104. // 重新加载(可用于点击重试)
  105. retryLoad() {
  106. if (this.data.evaluations.length === 0) {
  107. this.getfeedback(true)
  108. } else if (this.data.hasMore) {
  109. this.getfeedback()
  110. }
  111. }
  112. })