index.js 2.1 KB

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