C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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