1
0

goodsActivity.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. var util = require('../../utils/util.js');
  2. var api = require('../../config/api.js');
  3. var app = getApp()
  4. Page({
  5. data: {
  6. // text:"这是一个页面"
  7. activityList: [],
  8. page: 1,
  9. size: 10,
  10. count: 0,
  11. scrollTop: 0,
  12. type: 0,//活动类型 1 2团购
  13. showPage: false
  14. },
  15. onLoad: function (options) {
  16. // 页面初始化 options为页面跳转所带来的参数
  17. this.setData({
  18. type: null!=options.type?parseInt(options.type):0
  19. });
  20. wx.setNavigationBarTitle({
  21. title: '活动'
  22. })
  23. },
  24. onReady: function () {
  25. // 页面渲染完成
  26. },
  27. onShow: function () {
  28. // 页面显示
  29. this.getActivityList();
  30. },
  31. onHide: function () {
  32. // 页面隐藏
  33. },
  34. onUnload: function () {
  35. // 页面关闭
  36. },
  37. nextPage: function (event) {
  38. console.log();
  39. var that = this;
  40. if (this.data.page + 1 > that.data.count / that.data.size) {
  41. return true;
  42. }
  43. that.setData({
  44. "page": parseInt(that.data.page) + 1
  45. });
  46. this.getActivityList();
  47. },
  48. getActivityList: function () {
  49. let that = this;
  50. that.setData({
  51. scrollTop: 0,
  52. showPage: false,
  53. topicList: []
  54. });
  55. // 页面渲染完成
  56. wx.showToast({
  57. title: '加载中...',
  58. icon: 'loading',
  59. duration: 2000
  60. });
  61. util.request(api.ActivityList, { page: that.data.page, size: that.data.size,type:that.data.type }).then(function (res) {
  62. if (res.errno === 0) {
  63. that.setData({
  64. scrollTop: 0,
  65. activityList: res.data.data,
  66. showPage: true,
  67. count: res.data.count
  68. });
  69. }
  70. wx.hideToast();
  71. });
  72. },
  73. prevPage: function (event) {
  74. if (this.data.page <= 1) {
  75. return false;
  76. }
  77. var that = this;
  78. that.setData({
  79. "page": parseInt(that.data.page) - 1
  80. });
  81. this.getActivityList();
  82. },
  83. gotoGroup(event) {
  84. wx.redirectTo({
  85. url: '/pages/group/group?goods_id=' + event.currentTarget.dataset.goodsId
  86. })
  87. },
  88. })