index.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import GoodApi from '../../services/good'
  2. import Navi from '../../utils/navi'
  3. // pages/advtag/index.ts
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. albumInput: {
  10. tagId: -1,
  11. skipCount: 0,
  12. maxResultCount: 10,
  13. },
  14. albums: [] as any[],
  15. albumTotal: 0,
  16. loadMoreStatus: 0,
  17. },
  18. loadRecommend(rest = false) {
  19. this.setData({
  20. loadMoreStatus: 1,
  21. })
  22. GoodApi.GetRecommend(this.data.albumInput as any).then((rsp) => {
  23. if (rsp.result) {
  24. const result = rsp.result as any
  25. const { items = [] } = result
  26. const nowItems = rest ? items : this.data.albums.concat(items)
  27. this.setData({
  28. albums: nowItems as any,
  29. albumTotal: result.totalCount || 0,
  30. loadMoreStatus: nowItems.length === result.totalCount ? 2 : 0,
  31. })
  32. }
  33. })
  34. },
  35. /**
  36. * 生命周期函数--监听页面加载
  37. */
  38. onLoad(query: { tag: string }) {
  39. const { tag } = query
  40. this.setData(
  41. {
  42. 'albumInput.tagId': tag,
  43. },
  44. () => {
  45. this.loadRecommend(true)
  46. },
  47. )
  48. },
  49. /**
  50. * 生命周期函数--监听页面初次渲染完成
  51. */
  52. onReady() {},
  53. /**
  54. * 生命周期函数--监听页面显示
  55. */
  56. onShow() {},
  57. /**
  58. * 生命周期函数--监听页面隐藏
  59. */
  60. onHide() {},
  61. /**
  62. * 生命周期函数--监听页面卸载
  63. */
  64. onUnload() {},
  65. /**
  66. * 页面相关事件处理函数--监听用户下拉动作
  67. */
  68. onPullDownRefresh() {},
  69. /**
  70. * 页面上拉触底事件的处理函数
  71. */
  72. onReachBottom() {
  73. if (this.data.loadMoreStatus === 0 && this.data.albums.length < this.data.albumTotal) {
  74. this.setData(
  75. {
  76. albumInput: {
  77. ...this.data.albumInput,
  78. skipCount: this.data.albumInput.skipCount + 10,
  79. },
  80. },
  81. () => {
  82. this.loadRecommend()
  83. },
  84. )
  85. }
  86. },
  87. /**
  88. * 用户点击右上角分享
  89. */
  90. onShareAppMessage() {},
  91. gotoGoodsDetail(e: WechatMiniprogram.CustomEvent<{ goods: WxCateAlbumItemDto; index: number }>) {
  92. const { goods } = e.detail
  93. Navi.navigateTo({
  94. url: '/pages/goods/detail/index?id=' + goods.id + '&cateid=' + goods.cateId,
  95. })
  96. console.log('click', e)
  97. },
  98. })