result.ts 2.5 KB

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