C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

156 linhas
4.1 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-dd 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. .catch(err => {
  93. wx.showToast({
  94. title: err.errMsg,
  95. icon: 'none',
  96. duration: 2000,
  97. mask: false
  98. });
  99. })
  100. } else {
  101. console.info("allow_load==false 已禁止加载");
  102. that.setData({
  103. loading: true,
  104. content: "——— 再拉裤子就掉了啦 ———"
  105. })
  106. setTimeout(function () {
  107. that.setData({
  108. loading: false,
  109. })
  110. }, 1400)
  111. }
  112. };
  113. if (app.globalData.token && app.globalData.token != null) {
  114. console.log("couponChannelList init 1");
  115. app.couponChannelListCallback(app.globalData.token);
  116. }
  117. },
  118. onReady: function () {
  119. let that = this;
  120. that.setData({
  121. list: []
  122. });
  123. that.getList(1);
  124. },
  125. //限时抢购的详情页面
  126. gotodetail: function (e) {
  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. });