C端小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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