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.

147 lines
3.7 KiB

  1. let config = require("../../config/config.js");
  2. let Http = require("../../utils/HttpBasics");
  3. const util = require("../../utils/util");
  4. const app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. list: [],
  11. page: 2,
  12. allow_load: true,
  13. day: "",
  14. hour: "",
  15. minute: "",
  16. loading: true, //"上拉加载"的变量,默认false,隐藏
  17. content:"",
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function(options) {},
  23. //列表
  24. getList: function(page) {
  25. let that = this;
  26. app.couponChannelListCallback = token => {
  27. Http.setToken(token);
  28. /**
  29. * 判断用户是否加载完成
  30. */
  31. if (that.data.allow_load) {
  32. // wx.showLoading({
  33. // title: "加载中"
  34. // });
  35. that.setData({
  36. loading:true,
  37. content:'小主,我在玩命加载中...'
  38. })
  39. // setTimeout(function() {
  40. // wx.hideLoading();
  41. // }, 1200);
  42. Http.get({
  43. url: config.api.couponChannelList,
  44. data: {
  45. pageNum: page,
  46. pageSize: 5,
  47. targetAd: 2
  48. }
  49. }).then(res => {
  50. console.log(res);
  51. if (page > res.data.pages) {
  52. that.setData({
  53. allow_load: false
  54. });
  55. setTimeout(function() {
  56. that.setData({
  57. loading:false,
  58. })
  59. }, 1400);
  60. } else {
  61. setTimeout(function() {
  62. that.setData({
  63. loading:false,
  64. })
  65. }, 1400);
  66. /**
  67. * 页面上显示的时间
  68. */
  69. console.log(that.data.list);
  70. that.data.list = that.data.list.concat(res.data.list);
  71. that.setData({
  72. list: that.data.list
  73. });
  74. console.log(that.data.list);
  75. for (let i = 0; i < that.data.list.length; i++) {
  76. var startTime = util.fmtDate(that.data.list[i].endTime);
  77. util.timechuo(startTime);
  78. console.log(util.timechuo(startTime));
  79. /**
  80. * 修改list的endtime
  81. * 渲染到页面
  82. */
  83. var endtime = 'list[' + i + '].endtime'
  84. that.setData({
  85. [endtime]: util.timechuo(startTime)
  86. });
  87. }
  88. }
  89. });
  90. } else {
  91. console.info("allow_load==false 已禁止加载");
  92. that.setData({
  93. loading:true,
  94. content: "——— 在拉裤子就掉了啦 ———"
  95. })
  96. setTimeout(function(){
  97. that.setData({
  98. loading:false,
  99. })
  100. },1400)
  101. }
  102. };
  103. if (app.globalData.token && app.globalData.token != null) {
  104. console.log("couponChannelList init 1");
  105. app.couponChannelListCallback(app.globalData.token);
  106. }
  107. },
  108. onReady: function() {
  109. let that = this;
  110. that.setData({
  111. list: []
  112. });
  113. that.getList(2);
  114. },
  115. //限时抢购的详情页面
  116. gotodetail: function(e) {
  117. wx.navigateTo({
  118. url: `/pages/coupon/detail/index?couponChannelId=${
  119. e.currentTarget.dataset.couponchannelid
  120. }&couponId=${e.currentTarget.dataset.couponid}`
  121. });
  122. },
  123. /**
  124. * 页面相关事件处理函数--监听用户下拉动作
  125. */
  126. onPullDownRefresh: function() {},
  127. /**
  128. * 页面上拉触底事件的处理函数
  129. */
  130. onReachBottom: function() {
  131. let that = this;
  132. that.data.page++;
  133. console.log(that.data.page);
  134. that.getList(that.data.page);
  135. console.log("这是第:" + that.data.page);
  136. },
  137. /**
  138. * 用户点击右上角分享
  139. */
  140. onShareAppMessage: function() {}
  141. });