C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
2.7 KiB

  1. // pages/index/sw/index.js
  2. let config = require("../../config/config.js");
  3. let Http = require("../../utils/HttpBasics");
  4. const app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. list: [],
  11. page: 2,
  12. allow_load: true
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function(options) {},
  18. //列表
  19. getList: function(page) {
  20. let that = this;
  21. app.couponChannelListCallback = token => {
  22. Http.setToken(token);
  23. /**
  24. * 判断用户是否加载完成
  25. */
  26. if (that.data.allow_load) {
  27. wx.showLoading({
  28. title: "加载中"
  29. });
  30. setTimeout(function() {
  31. wx.hideLoading();
  32. }, 1200);
  33. Http.get({
  34. url: config.api.couponChannelList,
  35. data: {
  36. pageNum: page,
  37. pageSize: 5,
  38. targetAd: 2
  39. }
  40. }).then(res => {
  41. console.log(res);
  42. if (page >= res.data.pages) {
  43. wx.showToast({
  44. title: "加载完成喽",
  45. icon: "success"
  46. });
  47. that.setData({
  48. allow_load: false
  49. });
  50. }
  51. that.data.list = that.data.list.concat(res.data.list);
  52. that.setData({
  53. list: that.data.list
  54. });
  55. });
  56. } else {
  57. console.info("allow_load==false 已禁止加载");
  58. }
  59. };
  60. if (app.globalData.token && app.globalData.token != null) {
  61. console.log("couponChannelList init 1");
  62. app.couponChannelListCallback(app.globalData.token);
  63. }
  64. },
  65. onReady: function() {
  66. let that = this;
  67. that.setData({
  68. list: []
  69. });
  70. that.getList(2);
  71. },
  72. //限时抢购的强请页面
  73. gotodetail: function(e) {
  74. console.log(e);
  75. console.log("姐姐在测试");
  76. console.log(e.currentTarget.dataset.couponid);
  77. console.log(e.currentTarget.dataset.targetad);
  78. wx.navigateTo({
  79. url: `/pages/coupon/detail/index?id=${
  80. e.currentTarget.dataset.couponid
  81. }&targetAd=${e.currentTarget.dataset.targetad}`,
  82. success: function(res) {
  83. // success
  84. },
  85. fail: function() {
  86. // fail
  87. },
  88. complete: function() {
  89. // complete
  90. }
  91. });
  92. },
  93. /**
  94. * 页面相关事件处理函数--监听用户下拉动作
  95. */
  96. onPullDownRefresh: function() {},
  97. /**
  98. * 页面上拉触底事件的处理函数
  99. */
  100. onReachBottom: function() {
  101. let that = this;
  102. that.data.page++;
  103. console.log(that.data.page);
  104. that.getList(that.data.page);
  105. console.log("这是第:" + that.data.page);
  106. },
  107. /**
  108. * 用户点击右上角分享
  109. */
  110. onShareAppMessage: function() {}
  111. });