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.

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