C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

151 行
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. showPage:false
  19. },
  20. //列表
  21. getList: function (page) {
  22. let that = this;
  23. app.couponChannelListCallback = token => {
  24. Http.setToken(token);
  25. /**
  26. * 判断用户是否加载完成
  27. */
  28. if (that.data.allow_load) {
  29. that.setData({
  30. loading: true,
  31. content: '小主,我在玩命加载中...'
  32. })
  33. Http.get({
  34. url: config.api.couponChannelList,
  35. data: {
  36. pageNum: page,
  37. pageSize: 5,
  38. targetAd: 2
  39. }
  40. })
  41. .then(res => {
  42. if(res.code == 200){
  43. that.setData({
  44. showPage:true
  45. })
  46. }
  47. if (page >= res.data.pages) {
  48. that.setData({
  49. allow_load: false
  50. });
  51. setTimeout(function () {
  52. that.setData({
  53. loading: false,
  54. })
  55. }, 1400);
  56. }
  57. setTimeout(function () {
  58. that.setData({
  59. loading: false,
  60. })
  61. }, 1400);
  62. var tmpArr = that.data.list;
  63. tmpArr.push.apply(tmpArr, res.data.list);
  64. that.setData({
  65. list: tmpArr
  66. })
  67. for (let i = 0; i < that.data.list.length; i++) {
  68. var startTime = util.formatTime(that.data.list[i].endTime, "yyyy-MM-dd hh:mm:ss");
  69. var alsell = Math.floor((that.data.list[i].inventory - (that.data.list[i].remainInventory))/(that.data.list[i].inventory)*100);
  70. util.timechuo(startTime);
  71. /**
  72. * 修改list的endtime
  73. * 渲染到页面
  74. */
  75. var endtime = 'list[' + i + '].endtime';
  76. var flags = 'list[' + i + '].flags';
  77. var alsells = 'list[' + i + '].alsells';
  78. if (util.timechuo(startTime).indexOf('-')==0){
  79. that.setData({
  80. [flags]: "end",
  81. [endtime]: util.timechuo(startTime),
  82. [alsells]: alsell
  83. });
  84. }
  85. else{
  86. that.setData({
  87. [endtime]: util.timechuo(startTime),
  88. [alsells]: alsell
  89. });
  90. }
  91. }
  92. })
  93. .catch(err => {
  94. wx.showModal({
  95. title: '提示',
  96. content: err.errMsg,
  97. showCancel:false
  98. })
  99. })
  100. } else {
  101. that.setData({
  102. loading: true,
  103. content: "——— 再拉裤子就掉了啦 ———"
  104. })
  105. setTimeout(function () {
  106. that.setData({
  107. loading: false,
  108. })
  109. }, 1400)
  110. }
  111. };
  112. if (app.globalData.token && app.globalData.token != null) {
  113. app.couponChannelListCallback(app.globalData.token);
  114. }
  115. },
  116. onReady: function () {
  117. let that = this;
  118. that.setData({
  119. list: []
  120. });
  121. that.getList(1);
  122. },
  123. //限时抢购的详情页面
  124. gotodetail: function (e) {
  125. wx.navigateTo({
  126. url: `/pages/coupon/detail/index?couponChannelId=${
  127. e.currentTarget.dataset.couponchannelid
  128. }&couponId=${e.currentTarget.dataset.couponid}`
  129. });
  130. },
  131. /**
  132. * 页面相关事件处理函数--监听用户下拉动作
  133. */
  134. onPullDownRefresh: function () {},
  135. /**
  136. * 页面上拉触底事件的处理函数
  137. */
  138. onReachBottom: function () {
  139. let that = this;
  140. that.data.page++;
  141. that.getList(that.data.page);
  142. },
  143. /**
  144. * 用户点击右上角分享
  145. */
  146. onShareAppMessage: function () {}
  147. });