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.

171 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. console.log(that.data.list[i].activityStatus)
  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. console.log(beginTime)
  85. if (that.data.list[i].activityStatus==0){
  86. if (util.timechuo(beginTime).indexOf('-') == 0) {
  87. that.setData({
  88. [flags]: "end",
  89. [beginTime]: util.timechuo(beginTimes),
  90. [alsells]: alsell
  91. });
  92. }
  93. else {
  94. that.setData({
  95. [beginTime]: util.timechuo(beginTimes),
  96. [alsells]: alsell
  97. });
  98. }
  99. } if (that.data.list[i].activityStatus != 0) {
  100. //活动已经开始
  101. if (util.timechuo(startTime).indexOf('-') == 0) {
  102. that.setData({
  103. [flags]: "end",
  104. [endtime]: util.timechuo(startTime),
  105. [alsells]: alsell
  106. });
  107. }
  108. else {
  109. that.setData({
  110. [endtime]: util.timechuo(startTime),
  111. [alsells]: alsell
  112. });
  113. }
  114. }
  115. }
  116. })
  117. .catch(err => {
  118. wx.showModal({
  119. title: '提示',
  120. content: err.errMsg,
  121. showCancel:false
  122. })
  123. })
  124. } else {
  125. that.setData({
  126. loading: true,
  127. content: "——— 再拉裤子就掉了啦 ———"
  128. })
  129. setTimeout(function () {
  130. that.setData({
  131. loading: false,
  132. })
  133. }, 1400)
  134. }
  135. };
  136. if (app.globalData.token && app.globalData.token != null) {
  137. app.couponChannelListCallback(app.globalData.token);
  138. }
  139. },
  140. onReady: function () {
  141. let that = this;
  142. that.setData({
  143. list: []
  144. });
  145. that.getList(1);
  146. },
  147. //限时抢购的详情页面
  148. gotodetail: function (e) {
  149. wx.navigateTo({
  150. url: `/pages/coupon/detail/index?couponChannelId=${
  151. e.currentTarget.dataset.couponchannelid
  152. }&couponId=${e.currentTarget.dataset.couponid}`
  153. });
  154. },
  155. /**
  156. * 页面相关事件处理函数--监听用户下拉动作
  157. */
  158. onPullDownRefresh: function () {},
  159. /**
  160. * 页面上拉触底事件的处理函数
  161. */
  162. onReachBottom: function () {
  163. let that = this;
  164. that.data.page++;
  165. that.getList(that.data.page);
  166. },
  167. });