commentList.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // pages/commentList/commentList.js
  2. import {
  3. imgUrl
  4. } from "../api/request"
  5. import {
  6. request,
  7. baseUrl
  8. } from "../api/canteen-request.js"
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. // 图片前缀
  15. imgUrl: imgUrl,
  16. // 服务器地址
  17. baseUrl: baseUrl + '/',
  18. // 评论次数
  19. commentCount: '',
  20. // 点赞次数
  21. compliment: '',
  22. // 评论列表
  23. commentList: [],
  24. // 评论页数
  25. page: 1,
  26. // 餐厅ID
  27. canteenId: '',
  28. // 食品ID
  29. dishesId: '',
  30. height: '93vh'
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad: function (options) {
  36. if (options.commentCount != undefined && options.compliment != undefined) {
  37. this.setData({
  38. commentCount: options.commentCount,
  39. compliment: options.compliment,
  40. canteenId: options.canteenId,
  41. dishesId: options.dishesId
  42. })
  43. } else {
  44. this.setData({
  45. canteenId: options.canteenId,
  46. dishesId: options.dishesId,
  47. height: '100vh'
  48. })
  49. }
  50. this.getCommentById();
  51. },
  52. imageError(e) {
  53. let temp = this.data.commentList;
  54. temp[e.currentTarget.dataset.index].imgUrl = '';
  55. this.setData({
  56. commentList: temp
  57. })
  58. },
  59. getCommentById() {
  60. wx.showToast({
  61. title: '加载中',
  62. icon: 'loading',
  63. duration: 1500
  64. })
  65. request({
  66. url: '/mini/canteen/getDetailByDishesId?canteenId=' + this.data.canteenId + '&dishesId=' + this.data.dishesId + "&limit=10&page=" + this.data.page,
  67. method: 'GET'
  68. }).then(res => {
  69. if (res.data.length > 0) {
  70. let temp = res.data;
  71. temp = this.data.commentList.concat(temp);
  72. this.setData({
  73. commentList: temp
  74. })
  75. wx.hideToast();
  76. } else {
  77. wx.showToast({
  78. title: '已加载全部数据',
  79. icon: 'success',
  80. duration: 1000
  81. })
  82. }
  83. })
  84. },
  85. // 触底
  86. scrollBottom(e) {
  87. this.setData({
  88. page: this.data.page + 1
  89. })
  90. this.getCommentById()
  91. },
  92. /**
  93. * 生命周期函数--监听页面初次渲染完成
  94. */
  95. onReady: function () {
  96. },
  97. /**
  98. * 生命周期函数--监听页面显示
  99. */
  100. onShow: function () {
  101. },
  102. /**
  103. * 生命周期函数--监听页面隐藏
  104. */
  105. onHide: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面卸载
  109. */
  110. onUnload: function () {
  111. },
  112. /**
  113. * 页面相关事件处理函数--监听用户下拉动作
  114. */
  115. onPullDownRefresh: function () {
  116. },
  117. /**
  118. * 页面上拉触底事件的处理函数
  119. */
  120. onReachBottom: function () {
  121. },
  122. /**
  123. * 用户点击右上角分享
  124. */
  125. onShareAppMessage: function () {
  126. return {
  127. title: '菜品评论列表'
  128. }
  129. }
  130. })