result.ts 2.9 KB

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