C端小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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