index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // pages/collectionGoods/index.js
  2. const app=getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. parameter: {
  9. 'navbar': '1',
  10. 'return': '1',
  11. 'title': '收藏商品',
  12. 'color': false
  13. },
  14. host_product:[],
  15. loadTitle:'加载更多',
  16. loading:false,
  17. loadend:false,
  18. collectProductList:[],
  19. limit:8,
  20. page:1,
  21. },
  22. /**
  23. * 授权回调
  24. */
  25. onLoadFun:function(){
  26. this.get_user_collect_product();
  27. this.get_host_product();
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: function (options) {
  33. },
  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({ loading: true, loadTitle:''});
  42. app.baseGet(app.U({ c: 'store_api', a:'get_user_collect_product',q:{page:that.data.page,limit:that.data.limit}}),function(res){
  43. var collectProductList=res.data;
  44. var loadend = collectProductList.length < that.data.limit;
  45. console.log(collectProductList.length);
  46. that.data.collectProductList = app.SplitArray(collectProductList, that.data.collectProductList);
  47. that.setData({
  48. collectProductList: that.data.collectProductList,
  49. loadend: loadend,
  50. loadTitle: loadend ? '我也是有底线的':'加载更多',
  51. page:that.data.page+1,
  52. loading: false
  53. });
  54. },function(){
  55. that.setData({ loading: false, loadTitle:"加载更多"})
  56. });
  57. },
  58. /**
  59. * 取消收藏
  60. */
  61. delCollection:function(e){
  62. var id = e.target.dataset.id, that = this, index = e.target.dataset.index;
  63. app.baseGet(app.U({ c: 'store_api', a:'get_user_collect_product_del',q:{pid:id}}),function(res){
  64. return app.Tips({title:'取消收藏成功',icon:'success'},function(){
  65. that.data.collectProductList.splice(index,1);
  66. that.setData({ collectProductList: that.data.collectProductList});
  67. });
  68. });
  69. },
  70. /**
  71. * 获取我的推荐
  72. */
  73. get_host_product: function () {
  74. var that = this;
  75. app.baseGet(app.U({ c: 'public_api', a: "get_hot_product", q: { offset: 1, limit: 4 } }), function (res) {
  76. that.setData({ host_product: res.data });
  77. });
  78. },
  79. /**
  80. * 页面上拉触底事件的处理函数
  81. */
  82. onReachBottom: function () {
  83. this.get_user_collect_product();
  84. }
  85. })