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.

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