index.ts 3.0 KB

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