C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

185 rader
5.0 KiB

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