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.

168 rivejä
3.9 KiB

  1. let config = require("../../../config/config.js");
  2. let Http = require("../../../utils/HttpBasics");
  3. const util = require("../../../utils/util");
  4. let app = getApp();
  5. const imgurl = require("../../../utils/imgurl");
  6. Page({
  7. data: {
  8. dingdanUrl: imgurl.dingdan.url,
  9. loadingUrl: imgurl.loading.url,
  10. wmhome: imgurl.wmhome.url,
  11. wmdiscount: imgurl.wmdiscount.url,
  12. wmgive: imgurl.wmgive.url,
  13. tabs: [
  14. {
  15. key: 0,
  16. name: "参与中"
  17. },
  18. {
  19. key: 1,
  20. name: "已过期"
  21. }
  22. ],
  23. list: [],
  24. current: "",
  25. loading: true, //"上拉加载"的变量,默认false,隐藏
  26. current_scroll: "0",
  27. allow_load: true,
  28. page: 1,
  29. content: "",
  30. },
  31. goback: function () {
  32. wx.switchTab({
  33. url: '/pages/main/index',
  34. })
  35. },
  36. onLoad(options) {
  37. this.getList(0, 1);
  38. this.setData({
  39. current_scroll: 0
  40. });
  41. },
  42. //活动详情
  43. gotoDetail:function(e){
  44. wx.navigateTo({
  45. url: `/pages/radetail/index?id=${e.currentTarget.dataset.id}`
  46. })
  47. },
  48. gotopay: function (e) {
  49. wx.navigateTo({
  50. url: `/pages/order/detail/index?orderId=${e.currentTarget.dataset.id}&flag='pay'`
  51. })
  52. },
  53. getList(key, pageNum) {
  54. let that = this;
  55. let variable;
  56. if(key == 0){
  57. variable = {
  58. pageNum: pageNum,
  59. pageSize: 15,
  60. statusStr:"0,1,2"
  61. };
  62. }else if(key == 1){
  63. variable = {
  64. pageNum: pageNum,
  65. pageSize: 15,
  66. status: 3
  67. };
  68. }
  69. if (that.data.allow_load) {
  70. that.setData({
  71. loading: true,
  72. content: '小主,我在玩命加载中...'
  73. })
  74. Http.get({
  75. url: config.api.activityList,
  76. data: variable
  77. }).then(res => {
  78. if (pageNum >= res.data.pages) {
  79. that.setData({
  80. allow_load: false
  81. });
  82. setTimeout(function () {
  83. that.setData({
  84. loading: false,
  85. })
  86. }, 1400);
  87. }
  88. setTimeout(function () {
  89. that.setData({
  90. loading: false,
  91. })
  92. }, 1400);
  93. if (pageNum == 1) {
  94. that.setData({
  95. list: []
  96. })
  97. }
  98. var tmpArr = that.data.list;
  99. tmpArr.push.apply(tmpArr, res.data.list);
  100. // 将砍价的状态过滤出来
  101. console.log(tmpArr)
  102. that.setData({
  103. list: tmpArr
  104. })
  105. for (let i = 0; i < that.data.list.length; i++) {
  106. var activityStartTime1 = util.formatTime(that.data.list[i].activityStartTime, "yyyy-MM-dd hh:mm:ss");
  107. var activityEndTime1 = util.formatTime(that.data.list[i].activityEndTime, "yyyy-MM-dd hh:mm:ss");
  108. /**
  109. * 修改list的endtime
  110. * 渲染到页面
  111. */
  112. var activityStartTime = 'list[' + i + '].activityStartTime'
  113. var activityEndTime = 'list[' + i + '].activityEndTime'
  114. that.setData({
  115. [activityStartTime]: activityStartTime1,
  116. [activityEndTime]: activityEndTime1,
  117. });
  118. }
  119. })
  120. .catch(err => {
  121. wx.showToast({
  122. title: err.errMsg,
  123. icon:"none",
  124. duration:2000
  125. })
  126. })
  127. }
  128. else {
  129. that.setData({
  130. loading: true,
  131. content: "——— 再拉裤子就掉了啦 ———"
  132. })
  133. setTimeout(function () {
  134. that.setData({
  135. loading: false,
  136. })
  137. }, 1400)
  138. }
  139. },
  140. handleChange({
  141. detail
  142. }) {
  143. this.setData({
  144. current: detail.key
  145. });
  146. },
  147. handleChangeScroll({
  148. detail
  149. }) {
  150. this.setData({
  151. list: [],
  152. allow_load: true,
  153. current_scroll: detail.key,
  154. page: 1
  155. })
  156. this.getList(detail.key, 1);
  157. },
  158. onReachBottom: function () {
  159. var that = this;
  160. that.data.page++;
  161. that.setData({
  162. page: that.data.page
  163. });
  164. that.getList(that.data.current_scroll, that.data.page);
  165. },
  166. });