C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
3.9 KiB

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