C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

141 rader
3.5 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: 1,
  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. that.setData({
  33. loading: true,
  34. content: '小主,我在玩命加载中...'
  35. })
  36. Http.get({
  37. url: config.api.couponChannelList,
  38. data: {
  39. pageNum: page,
  40. pageSize: 5,
  41. targetAd: 2
  42. }
  43. }).then(res => {
  44. console.log(res);
  45. if (page >= res.data.pages) {
  46. that.setData({
  47. allow_load: false
  48. });
  49. setTimeout(function () {
  50. that.setData({
  51. loading: false,
  52. })
  53. }, 1400);
  54. }
  55. setTimeout(function () {
  56. that.setData({
  57. loading: false,
  58. })
  59. }, 1400);
  60. // if (pageNum == 2) {
  61. // that.setData({
  62. // list: []
  63. // })
  64. // }
  65. var tmpArr = that.data.list;
  66. tmpArr.push.apply(tmpArr, res.data.list);
  67. that.setData({
  68. list: tmpArr
  69. })
  70. console.log(tmpArr);
  71. for (let i = 0; i < that.data.list.length; i++) {
  72. var startTime = util.fmtDate(that.data.list[i].endTime);
  73. util.timechuo(startTime);
  74. console.log(util.timechuo(startTime));
  75. /**
  76. * 修改list的endtime
  77. * 渲染到页面
  78. */
  79. var endtime = 'list[' + i + '].endtime'
  80. that.setData({
  81. [endtime]: util.timechuo(startTime)
  82. });
  83. }
  84. });
  85. } else {
  86. console.info("allow_load==false 已禁止加载");
  87. that.setData({
  88. loading: true,
  89. content: "——— 再拉裤子就掉了啦 ———"
  90. })
  91. setTimeout(function () {
  92. that.setData({
  93. loading: false,
  94. })
  95. }, 1400)
  96. }
  97. };
  98. if (app.globalData.token && app.globalData.token != null) {
  99. console.log("couponChannelList init 1");
  100. app.couponChannelListCallback(app.globalData.token);
  101. }
  102. },
  103. onReady: function () {
  104. let that = this;
  105. that.setData({
  106. list: []
  107. });
  108. that.getList(1);
  109. },
  110. //限时抢购的详情页面
  111. gotodetail: function (e) {
  112. wx.navigateTo({
  113. url: `/pages/coupon/detail/index?couponChannelId=${
  114. e.currentTarget.dataset.couponchannelid
  115. }&couponId=${e.currentTarget.dataset.couponid}`
  116. });
  117. },
  118. /**
  119. * 页面相关事件处理函数--监听用户下拉动作
  120. */
  121. onPullDownRefresh: function () {},
  122. /**
  123. * 页面上拉触底事件的处理函数
  124. */
  125. onReachBottom: function () {
  126. let that = this;
  127. that.data.page++;
  128. console.log(that.data.page);
  129. that.getList(that.data.page);
  130. console.log("这是第:" + that.data.page);
  131. },
  132. /**
  133. * 用户点击右上角分享
  134. */
  135. onShareAppMessage: function () {}
  136. });