index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // pages/bargain-list/index.js
  2. import { getBargainList } from '../../../api/activity.js';
  3. import { openBargainSubscribe } from '../../../utils/SubscribeMessage.js';
  4. const app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. bargainList:[],
  11. page:0,
  12. limit:20,
  13. loading:false,
  14. loadend:false,
  15. userInfo:{},
  16. navH:''
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) {
  22. this.setData({
  23. navH: app.globalData.navHeight
  24. });
  25. },
  26. goBack:function(){
  27. wx.navigateBack({ delta: 1 })
  28. },
  29. onLoadFun: function (e) {
  30. this.getBargainList();
  31. this.setData({
  32. userInfo: e.detail
  33. })
  34. },
  35. openSubscribe:function(e){
  36. let page = e.currentTarget.dataset.url;
  37. wx.showLoading({
  38. title: '正在加载',
  39. })
  40. openBargainSubscribe().then(res => {
  41. wx.hideLoading();
  42. wx.navigateTo({
  43. url: page,
  44. });
  45. }).catch(() => {
  46. wx.hideLoading();
  47. });
  48. },
  49. getBargainList:function(){
  50. var that = this;
  51. if (that.data.loadend) return;
  52. if (that.data.loading) return;
  53. that.setData({loading:true});
  54. getBargainList({page:that.data.page,limit:that.data.limit}).then(function (res) {
  55. that.setData({
  56. bargainList: that.data.bargainList.concat(res.data),
  57. page: that.data.page+1,
  58. loadend: that.data.limit > res.data.length,
  59. loading:false
  60. });
  61. }).catch(res=>{
  62. that.setData({loading:false});
  63. });
  64. },
  65. /**
  66. * 生命周期函数--监听页面初次渲染完成
  67. */
  68. onReady: function () {
  69. },
  70. /**
  71. * 生命周期函数--监听页面显示
  72. */
  73. onShow: function () {
  74. },
  75. /**
  76. * 生命周期函数--监听页面隐藏
  77. */
  78. onHide: function () {
  79. },
  80. /**
  81. * 生命周期函数--监听页面卸载
  82. */
  83. onUnload: function () {
  84. },
  85. /**
  86. * 页面相关事件处理函数--监听用户下拉动作
  87. */
  88. onPullDownRefresh: function () {
  89. },
  90. /**
  91. * 页面上拉触底事件的处理函数
  92. */
  93. onReachBottom: function () {
  94. this.getBargainList();
  95. },
  96. })