comment.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // pages/user/comment.js
  2. import api from '../../utils/api.js'
  3. import util from '../../utils/util.js'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. commentParams: {
  10. page: 1,
  11. offset: 10
  12. },
  13. commentlist: [],
  14. commentCount: 0
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. this.getComemntData()
  21. },
  22. getComemntData: function () {
  23. api.getMyGameCommentList(this.data.commentParams).then(res => {
  24. if (res.code === 200) {
  25. res.data.list.forEach((item, ids) => {
  26. item.create_time = util.formatTime(item.create_time, 'yyyy/MM/dd hh:mm')
  27. })
  28. this.setData({
  29. commentlist: this.data.commentlist.concat(res.data.list),
  30. commentCount: res.data.count || 0
  31. })
  32. }
  33. })
  34. },
  35. /**
  36. * 页面上拉触底事件的处理函数
  37. */
  38. onReachBottom: function () {
  39. if (this.data.commentCount <= this.data.commentlist.length) {
  40. return false;
  41. }
  42. this.data.commentParams.page = ++this.data.commentParams.page
  43. this.setData({
  44. commentParams: this.data.commentParams
  45. })
  46. this.getComemntData()
  47. }
  48. })