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.

148 lines
3.9 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. var tmpArr = that.data.list;
  61. tmpArr.push.apply(tmpArr, res.data.list);
  62. that.setData({
  63. list: tmpArr
  64. })
  65. for (let i = 0; i < that.data.list.length; i++) {
  66. var startTime = util.formatTime(that.data.list[i].endTime, "yyyy-MM-dddd hh:mm:ss");
  67. var alsell = Math.floor((that.data.list[i].inventory - (that.data.list[i].remainInventory))/(that.data.list[i].inventory)*100);
  68. util.timechuo(startTime);
  69. console.log(alsell);
  70. /**
  71. * 修改list的endtime
  72. * 渲染到页面
  73. */
  74. var endtime = 'list[' + i + '].endtime';
  75. var flags = 'list[' + i + '].flags';
  76. var alsells = 'list[' + i + '].alsells';
  77. if (util.timechuo(startTime).indexOf('-')==0){
  78. that.setData({
  79. [flags]: "end",
  80. [endtime]: util.timechuo(startTime),
  81. [alsells]: alsell
  82. });
  83. }
  84. else{
  85. that.setData({
  86. [endtime]: util.timechuo(startTime),
  87. [alsells]: alsell
  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(1);
  116. },
  117. //限时抢购的详情页面
  118. gotodetail: function (e) {
  119. wx.navigateTo({
  120. url: `/pages/coupon/detail/index?couponChannelId=${
  121. e.currentTarget.dataset.couponchannelid
  122. }&couponId=${e.currentTarget.dataset.couponid}`
  123. });
  124. },
  125. /**
  126. * 页面相关事件处理函数--监听用户下拉动作
  127. */
  128. onPullDownRefresh: function () {},
  129. /**
  130. * 页面上拉触底事件的处理函数
  131. */
  132. onReachBottom: function () {
  133. let that = this;
  134. that.data.page++;
  135. console.log(that.data.page);
  136. that.getList(that.data.page);
  137. console.log("这是第:" + that.data.page);
  138. },
  139. /**
  140. * 用户点击右上角分享
  141. */
  142. onShareAppMessage: function () {}
  143. });