C端小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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