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.

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