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.

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