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.

150 linhas
3.8 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. if (page >= res.data.pages) {
  45. that.setData({
  46. allow_load: false
  47. });
  48. setTimeout(function () {
  49. that.setData({
  50. loading: false,
  51. })
  52. }, 1400);
  53. }
  54. setTimeout(function () {
  55. that.setData({
  56. loading: false,
  57. })
  58. }, 1400);
  59. var tmpArr = that.data.list;
  60. tmpArr.push.apply(tmpArr, res.data.list);
  61. that.setData({
  62. list: tmpArr
  63. })
  64. for (let i = 0; i < that.data.list.length; i++) {
  65. var startTime = util.formatTime(that.data.list[i].endTime, "yyyy-MM-dd hh:mm:ss");
  66. var alsell = Math.floor((that.data.list[i].inventory - (that.data.list[i].remainInventory))/(that.data.list[i].inventory)*100);
  67. util.timechuo(startTime);
  68. /**
  69. * 修改list的endtime
  70. * 渲染到页面
  71. */
  72. var endtime = 'list[' + i + '].endtime';
  73. var flags = 'list[' + i + '].flags';
  74. var alsells = 'list[' + i + '].alsells';
  75. if (util.timechuo(startTime).indexOf('-')==0){
  76. that.setData({
  77. [flags]: "end",
  78. [endtime]: util.timechuo(startTime),
  79. [alsells]: alsell
  80. });
  81. }
  82. else{
  83. that.setData({
  84. [endtime]: util.timechuo(startTime),
  85. [alsells]: alsell
  86. });
  87. }
  88. }
  89. })
  90. .catch(err => {
  91. wx.showToast({
  92. title: err.errMsg,
  93. icon: 'none',
  94. duration: 2000,
  95. mask: false
  96. });
  97. })
  98. } else {
  99. that.setData({
  100. loading: true,
  101. content: "——— 再拉裤子就掉了啦 ———"
  102. })
  103. setTimeout(function () {
  104. that.setData({
  105. loading: false,
  106. })
  107. }, 1400)
  108. }
  109. };
  110. if (app.globalData.token && app.globalData.token != null) {
  111. app.couponChannelListCallback(app.globalData.token);
  112. }
  113. },
  114. onReady: function () {
  115. let that = this;
  116. that.setData({
  117. list: []
  118. });
  119. that.getList(1);
  120. },
  121. //限时抢购的详情页面
  122. gotodetail: function (e) {
  123. wx.navigateTo({
  124. url: `/pages/coupon/detail/index?couponChannelId=${
  125. e.currentTarget.dataset.couponchannelid
  126. }&couponId=${e.currentTarget.dataset.couponid}`
  127. });
  128. },
  129. /**
  130. * 页面相关事件处理函数--监听用户下拉动作
  131. */
  132. onPullDownRefresh: function () {},
  133. /**
  134. * 页面上拉触底事件的处理函数
  135. */
  136. onReachBottom: function () {
  137. let that = this;
  138. that.data.page++;
  139. that.getList(that.data.page);
  140. },
  141. /**
  142. * 用户点击右上角分享
  143. */
  144. onShareAppMessage: function () {}
  145. });