index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // pages/collectionGoods/index.js
  2. import { getCollectUserList, getProductHot, collectDel } from '../../api/store.js'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. parameter: {
  10. navbar: '1',
  11. return: '1',
  12. title: '收藏',
  13. color: false
  14. },
  15. host_product: [],
  16. loadTitle: '加载更多',
  17. loading: false,
  18. loadend: false,
  19. collectProductList: [],
  20. limit: 8,
  21. page: 1
  22. },
  23. /**
  24. * 授权回调
  25. */
  26. onLoadFun: function () {
  27. this.get_user_collect_product()
  28. this.get_host_product()
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: function (options) {},
  34. /**
  35. * 获取收藏产品
  36. */
  37. get_user_collect_product: function () {
  38. var that = this
  39. if (this.data.loading) return
  40. if (this.data.loadend) return
  41. that.setData({
  42. loading: true,
  43. loadTitle: ''
  44. })
  45. getCollectUserList({
  46. page: that.data.page,
  47. limit: that.data.limit
  48. })
  49. .then(res => {
  50. var collectProductList = res.data
  51. var loadend = collectProductList.length < that.data.limit
  52. console.log(collectProductList.length)
  53. that.data.collectProductList = app.SplitArray(collectProductList, that.data.collectProductList)
  54. that.setData({
  55. collectProductList: that.data.collectProductList,
  56. loadend: loadend,
  57. loadTitle: loadend ? '我也是有底线的' : '加载更多',
  58. page: that.data.page + 1,
  59. loading: false
  60. })
  61. })
  62. .catch(err => {
  63. that.setData({
  64. loading: false,
  65. loadTitle: '加载更多'
  66. })
  67. })
  68. },
  69. /**
  70. * 取消收藏
  71. */
  72. delCollection: function (e) {
  73. var id = e.target.dataset.id,
  74. that = this,
  75. index = e.target.dataset.index
  76. collectDel(id).then(res => {
  77. return app.Tips(
  78. {
  79. title: '取消收藏成功',
  80. icon: 'success'
  81. },
  82. function () {
  83. that.data.collectProductList.splice(index, 1)
  84. that.setData({
  85. collectProductList: that.data.collectProductList
  86. })
  87. }
  88. )
  89. })
  90. },
  91. /**
  92. * 获取我的推荐
  93. */
  94. get_host_product: function () {
  95. var that = this
  96. getProductHot().then(res => {
  97. that.setData({
  98. host_product: res.data
  99. })
  100. })
  101. },
  102. /**
  103. * 页面上拉触底事件的处理函数
  104. */
  105. onReachBottom: function () {
  106. this.get_user_collect_product()
  107. }
  108. })