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.

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