index.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import GoodApi from '../../../services/good'
  2. // pages/goods/comments/index.ts
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. seartInput: {
  9. gid: 'HcVJnL5DAA',
  10. skipCount: 0,
  11. maxResultCount: 10,
  12. },
  13. totalCount: 0,
  14. items: [] as any[],
  15. loadMoreStatus: 0,
  16. loading: true,
  17. commentType: '',
  18. goodCount: 0,
  19. middleCount: 0,
  20. badCount: 0,
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad() {
  26. this.load(true)
  27. },
  28. load(rest = false) {
  29. this.setData({
  30. loadMoreStatus: 1,
  31. })
  32. GoodApi.GetCommentlist(this.data.seartInput).then((rsp) => {
  33. if (rsp.result) {
  34. const result = rsp.result
  35. const { items = [], totalCount = 0, goodCount = 0, badCount = 0, middleCount = 0 } = result
  36. const nowItems = rest ? items : this.data.items.concat(items)
  37. this.setData({
  38. items: nowItems,
  39. totalCount,
  40. goodCount,
  41. badCount,
  42. middleCount,
  43. loadMoreStatus: nowItems.length === result.totalCount ? 2 : 0,
  44. loading: false,
  45. })
  46. console.log(nowItems)
  47. }
  48. })
  49. },
  50. /**
  51. * 页面相关事件处理函数--监听用户下拉动作
  52. */
  53. onPullDownRefresh() {
  54. if (!this.data.loading && this.data.loadMoreStatus === 0) {
  55. this.setData(
  56. {
  57. albumInput: {
  58. ...this.data.seartInput,
  59. skipCount: 0,
  60. },
  61. loading: true,
  62. },
  63. () => {
  64. wx.stopPullDownRefresh()
  65. this.load(true)
  66. },
  67. )
  68. }
  69. },
  70. /**
  71. * 页面上拉触底事件的处理函数
  72. */
  73. onReachBottom() {
  74. console.log(this.data.items.length, this.data.totalCount)
  75. if (this.data.loadMoreStatus === 0 && this.data.items.length < this.data.totalCount) {
  76. this.setData(
  77. {
  78. albumInput: {
  79. ...this.data.seartInput,
  80. skipCount: this.data.seartInput.skipCount + 10,
  81. },
  82. },
  83. () => {
  84. this.load()
  85. },
  86. )
  87. }
  88. },
  89. /**
  90. * 生命周期函数--监听页面初次渲染完成
  91. */
  92. onReady() {},
  93. /**
  94. * 生命周期函数--监听页面显示
  95. */
  96. onShow() {},
  97. /**
  98. * 生命周期函数--监听页面隐藏
  99. */
  100. onHide() {},
  101. /**
  102. * 生命周期函数--监听页面卸载
  103. */
  104. onUnload() {},
  105. /**
  106. * 用户点击右上角分享
  107. */
  108. onShareAppMessage() {},
  109. changeTag(e: WechatMiniprogram.BaseEvent<{ commenttype: string }>) {
  110. const { commenttype } = e.currentTarget.dataset
  111. this.setData({
  112. commentType: commenttype,
  113. })
  114. },
  115. })