grouponList.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // pages/groupon/grouponList/grouponList.js
  2. var util = require('../../../utils/util.js');
  3. var api = require('../../../config/api.js');
  4. var app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. grouponList: [],
  11. page: 1,
  12. limit: 10,
  13. count: 0,
  14. scrollTop: 0,
  15. showPage: false
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function(options) {
  21. this.getGrouponList();
  22. },
  23. /**
  24. * 生命周期函数--监听页面初次渲染完成
  25. */
  26. onReady: function() {
  27. },
  28. /**
  29. * 生命周期函数--监听页面显示
  30. */
  31. onShow: function() {
  32. },
  33. /**
  34. * 生命周期函数--监听页面隐藏
  35. */
  36. onHide: function() {
  37. },
  38. /**
  39. * 生命周期函数--监听页面卸载
  40. */
  41. onUnload: function() {
  42. },
  43. /**
  44. * 页面相关事件处理函数--监听用户下拉动作
  45. */
  46. onPullDownRefresh: function() {
  47. },
  48. /**
  49. * 页面上拉触底事件的处理函数
  50. */
  51. onReachBottom: function() {
  52. },
  53. /**
  54. * 用户点击右上角分享
  55. */
  56. onShareAppMessage: function() {
  57. },
  58. getGrouponList: function() {
  59. let that = this;
  60. that.setData({
  61. scrollTop: 0,
  62. showPage: false,
  63. grouponList: []
  64. });
  65. // 页面渲染完成
  66. wx.showToast({
  67. title: '加载中...',
  68. icon: 'loading',
  69. duration: 2000
  70. });
  71. util.request(api.GroupOnList, {
  72. page: that.data.page,
  73. limit: that.data.limit
  74. }).then(function(res) {
  75. if (res.errno === 0) {
  76. that.setData({
  77. scrollTop: 0,
  78. grouponList: res.data.list,
  79. showPage: true,
  80. count: res.data.total
  81. });
  82. }
  83. wx.hideToast();
  84. });
  85. },
  86. nextPage: function(event) {
  87. var that = this;
  88. if (this.data.page > that.data.count / that.data.limit) {
  89. return true;
  90. }
  91. that.setData({
  92. page: that.data.page + 1
  93. });
  94. this.getGrouponList();
  95. },
  96. prevPage: function(event) {
  97. if (this.data.page <= 1) {
  98. return false;
  99. }
  100. var that = this;
  101. that.setData({
  102. page: that.data.page - 1
  103. });
  104. this.getGrouponList();
  105. }
  106. })