growth.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // parents/pages/growth/growth.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { GetGrowthRecord } from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData, hasLibraryService, hasVipService } = getApp()
  6. const { baseImgUrl } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. baseImgUrl,
  13. isLoaded: false,
  14. pageNo: 1,
  15. pageSize: 10,
  16. isAll: 0,
  17. list: [],
  18. nodataArray: {
  19. text: '暂没有成长记录',
  20. image: '../../../assets/nodata_2.png'
  21. }
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. options.userId = getGlobalVal('userId')
  28. options.vipId = getGlobalVal('vipId', `vipId_${options.userId}`) || ''
  29. options.libId = getGlobalVal('library').id || ''
  30. this.setData({ options })
  31. this.getData(res => {
  32. this.setData({ isLoaded: 1 })
  33. })
  34. },
  35. /**
  36. * 生命周期函数--监听页面初次渲染完成
  37. */
  38. onReady: function () {
  39. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  40. for (const i in obj) {
  41. this[i] = obj[i]
  42. }
  43. },
  44. /**
  45. * 生命周期函数--监听页面显示
  46. */
  47. onShow: function () {
  48. },
  49. /**
  50. * 生命周期函数--监听页面隐藏
  51. */
  52. onHide: function () {
  53. },
  54. /**
  55. * 生命周期函数--监听页面卸载
  56. */
  57. onUnload: function () {
  58. },
  59. /**
  60. * 页面相关事件处理函数--监听用户下拉动作
  61. */
  62. onPullDownRefresh: function () {
  63. this.setData({ pageNo: 1 })
  64. this.getData(res => {
  65. wx.stopPullDownRefresh()
  66. })
  67. },
  68. /**
  69. * 页面上拉触底事件的处理函数
  70. */
  71. onReachBottom: function () {
  72. },
  73. /**
  74. * 用户点击右上角分享
  75. */
  76. onShareAppMessage: function () {
  77. if (isFn(sharePage)) return sharePage()
  78. },
  79. /**
  80. * 获取数据
  81. */
  82. getData: function (cb) {
  83. const continuousFn = { fn: this.getData, param: { ...arguments } }
  84. const { pageNo, pageSize, options, list } = this.data
  85. const { vipId, libId } = options
  86. GetGrowthRecord({ data: { pageNo, pageSize, vipId, libId }, continuousFn }).then(res => {
  87. const newList = res.data.list
  88. let listTemp = []
  89. if (pageNo == 1) {
  90. listTemp = [].concat(newList)
  91. } else {
  92. listTemp = [].concat(list, newList)
  93. }
  94. this.setData({ list: listTemp, isAll: newList.length < pageSize, pageNo: newList.length == pageSize ? pageNo + 1 : pageNo, isLoaded: true })
  95. cb && cb()
  96. }).catch(res => {
  97. this.setData({ isLoaded: true })
  98. cb && cb()
  99. })
  100. }
  101. })