C端小程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

157 行
4.0 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. // wx.showToast({
  56. // title: "加载完成喽",
  57. // icon: "success"
  58. // });
  59. that.setData({
  60. allow_load: false
  61. });
  62. setTimeout(function() {
  63. that.setData({
  64. loading:false,
  65. })
  66. }, 1400);
  67. } else {
  68. setTimeout(function() {
  69. that.setData({
  70. loading:false,
  71. })
  72. }, 1400);
  73. /**
  74. * 页面上显示的时间
  75. */
  76. that.data.list = that.data.list.concat(res.data.list);
  77. that.setData({
  78. list: that.data.list
  79. });
  80. console.log(that.data.list);
  81. for (let i = 0; i < that.data.list.length; i++) {
  82. var startTime = util.fmtDate(that.data.list[i].endTime);
  83. util.timechuo(startTime);
  84. console.log(util.timechuo(startTime));
  85. /**
  86. * 修改list的endtime
  87. * 渲染到页面
  88. */
  89. var endtime = 'list[' + i + '].endtime'
  90. that.setData({
  91. [endtime]: util.timechuo(startTime)
  92. });
  93. }
  94. }
  95. });
  96. } else {
  97. console.info("allow_load==false 已禁止加载");
  98. that.setData({
  99. loading:true,
  100. content:"^_^再拉裤子就掉啦ʅ(´◔౪◔)ʃ"
  101. })
  102. setTimeout(function(){
  103. that.setData({
  104. loading:false,
  105. })
  106. },1400)
  107. }
  108. };
  109. if (app.globalData.token && app.globalData.token != null) {
  110. console.log("couponChannelList init 1");
  111. app.couponChannelListCallback(app.globalData.token);
  112. }
  113. },
  114. onReady: function() {
  115. let that = this;
  116. that.setData({
  117. list: []
  118. });
  119. that.getList(2);
  120. },
  121. //限时抢购的详情页面
  122. gotodetail: function(e) {
  123. console.log(e);
  124. console.log("姐姐在测试");
  125. console.log(e.currentTarget.dataset.couponchannelid);
  126. console.log("couponChannelId");
  127. wx.navigateTo({
  128. url: `/pages/coupon/detail/index?couponChannelId=${
  129. e.currentTarget.dataset.couponchannelid
  130. }&couponId=${e.currentTarget.dataset.couponid}`
  131. });
  132. },
  133. /**
  134. * 页面相关事件处理函数--监听用户下拉动作
  135. */
  136. onPullDownRefresh: function() {},
  137. /**
  138. * 页面上拉触底事件的处理函数
  139. */
  140. onReachBottom: function() {
  141. let that = this;
  142. that.data.page++;
  143. console.log(that.data.page);
  144. that.getList(that.data.page);
  145. console.log("这是第:" + that.data.page);
  146. },
  147. /**
  148. * 用户点击右上角分享
  149. */
  150. onShareAppMessage: function() {}
  151. });