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.

132 lines
3.3 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. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function(options) {},
  22. //列表
  23. getList: function(page) {
  24. let that = this;
  25. app.couponChannelListCallback = token => {
  26. Http.setToken(token);
  27. /**
  28. * 判断用户是否加载完成
  29. */
  30. if (that.data.allow_load) {
  31. wx.showLoading({
  32. title: "加载中"
  33. });
  34. setTimeout(function() {
  35. wx.hideLoading();
  36. }, 1200);
  37. Http.get({
  38. url: config.api.couponChannelList,
  39. data: {
  40. pageNum: page,
  41. pageSize: 5,
  42. targetAd: 2
  43. }
  44. }).then(res => {
  45. console.log(res);
  46. //当前时间与优惠券下架时间做计算
  47. console.log(that.data.day);
  48. if (page >= res.data.pages) {
  49. // wx.showToast({
  50. // title: "加载完成喽",
  51. // icon: "success"
  52. // });
  53. that.setData({
  54. allow_load: false
  55. });
  56. } else {
  57. /**
  58. * 页面上显示的时间
  59. */
  60. that.data.list = that.data.list.concat(res.data.list);
  61. that.setData({
  62. list: that.data.list
  63. });
  64. console.log(that.data.list);
  65. for (let i = 0; i < that.data.list.length; i++) {
  66. var startTime = util.fmtDate(that.data.list[i].endTime);
  67. util.timechuo(startTime);
  68. console.log(util.timechuo(startTime));
  69. /**
  70. * 修改list的endtime
  71. * 渲染到页面
  72. */
  73. var endtime = 'list[' + i + '].endtime'
  74. that.setData({
  75. [endtime]: util.timechuo(startTime)
  76. });
  77. }
  78. }
  79. });
  80. } else {
  81. console.info("allow_load==false 已禁止加载");
  82. }
  83. };
  84. if (app.globalData.token && app.globalData.token != null) {
  85. console.log("couponChannelList init 1");
  86. app.couponChannelListCallback(app.globalData.token);
  87. }
  88. },
  89. onReady: function() {
  90. let that = this;
  91. that.setData({
  92. list: []
  93. });
  94. that.getList(2);
  95. },
  96. //限时抢购的详情页面
  97. gotodetail: function(e) {
  98. console.log(e);
  99. console.log("姐姐在测试");
  100. console.log(e.currentTarget.dataset.couponchannelid);
  101. console.log("couponChannelId");
  102. wx.navigateTo({
  103. url: `/pages/coupon/detail/index?couponChannelId=${
  104. e.currentTarget.dataset.couponchannelid
  105. }&couponId=${e.currentTarget.dataset.couponid}`
  106. });
  107. },
  108. /**
  109. * 页面相关事件处理函数--监听用户下拉动作
  110. */
  111. onPullDownRefresh: function() {},
  112. /**
  113. * 页面上拉触底事件的处理函数
  114. */
  115. onReachBottom: function() {
  116. let that = this;
  117. that.data.page++;
  118. console.log(that.data.page);
  119. that.getList(that.data.page);
  120. console.log("这是第:" + that.data.page);
  121. },
  122. /**
  123. * 用户点击右上角分享
  124. */
  125. onShareAppMessage: function() {}
  126. });