C端小程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

174 righe
4.0 KiB

  1. const util = require("../../utils/util.js");
  2. const config = require("../../config/config.js");
  3. const Http = require("../../utils/HttpBasics");
  4. const imgurl = require("../../utils/imgurl");
  5. let app = getApp();
  6. Page({
  7. data: {
  8. couponUrl: imgurl.coupon.url,
  9. loadingUrl: imgurl.loading.url,
  10. tabs: [],
  11. list: [],
  12. current: "0",
  13. current_scroll: "0",
  14. page: 1,
  15. allow_load: true,
  16. loading: true, //"上拉加载"的变量,默认false,隐藏
  17. content: "",
  18. mystatus: '',
  19. showPage: false,
  20. },
  21. onLoad() {
  22. this.getList(0, 1);
  23. },
  24. onShow: function () {
  25. let that = this;
  26. wx.setStorage({
  27. key: 'couponNum',
  28. data: "couponNum1",
  29. })
  30. wx.hideTabBarRedDot({
  31. index: 2
  32. })
  33. Http.get({
  34. url: config.api.businessList,
  35. data: {
  36. pageNum: 1,
  37. pageSize: 15,
  38. type: 1
  39. }
  40. }).then(res => {
  41. console.log(res)
  42. let businessObj = [{ id: 0, title: "全部", type: 1 }];
  43. that.setData({
  44. tabs: res.data.list.concat(businessObj).sort(compare("id"))
  45. });
  46. console.log(that.data.tabs)
  47. })
  48. .catch(err => {
  49. wx.showToast({
  50. title: err.errMsg,
  51. icon: 'none',
  52. duration: 2000,
  53. mask: false
  54. });
  55. })
  56. },
  57. //点击跳转到券详情页面
  58. gotouse: function (e) {
  59. console.log(e.currentTarget.dataset.couponid)
  60. wx.navigateTo({
  61. url: `/pages/coupon/detail/index?couponChannelId=${e.currentTarget.dataset.quancode}&couponId=${e.currentTarget.dataset.couponid}`
  62. });
  63. },
  64. getList(key, pageNum) {
  65. var that = this;
  66. // 根据 key == 0 区分全部或其它tab,决定是否传参数 business
  67. if (key == 0) {
  68. var param = {
  69. pageNum: pageNum,
  70. pageSize: 6,
  71. targetAd: 1,
  72. type: "7"
  73. };
  74. } else {
  75. var param = {
  76. pageNum: pageNum,
  77. pageSize: 6,
  78. business: key,
  79. targetAd: 1,
  80. type: "7"
  81. };
  82. }
  83. if (that.data.allow_load) {
  84. that.setData({
  85. loading: true,
  86. content: "小主,我在玩命加载中...",
  87. });
  88. Http.get({
  89. url: config.api.couponChannelList,
  90. data: param
  91. })
  92. .then(res => {
  93. if (res.code == 200) {
  94. that.setData({
  95. showPage: true
  96. })
  97. }
  98. res.data.list.map(file => {
  99. file.expiredTime = util.fmtDate(file.expiredTime);
  100. });
  101. setTimeout(function () {
  102. that.setData({
  103. loading: false
  104. });
  105. }, 1400);
  106. if (pageNum >= res.data.pages) {
  107. that.setData({
  108. allow_load: false
  109. });
  110. }
  111. if (pageNum == 1) {
  112. that.setData({
  113. list: []
  114. })
  115. }
  116. var tmpArr = that.data.list;
  117. tmpArr.push.apply(tmpArr, res.data.list);
  118. that.setData({
  119. list: tmpArr
  120. })
  121. })
  122. .catch(err => {
  123. wx.showModal({
  124. title: '提示',
  125. content: err.errMsg,
  126. showCancel: false
  127. })
  128. })
  129. } else {
  130. that.setData({
  131. loading: true,
  132. content: "——— 再拉裤子就掉了啦 ———"
  133. });
  134. setTimeout(function () {
  135. that.setData({
  136. loading: false
  137. });
  138. }, 1400);
  139. }
  140. },
  141. handleChangeScroll({
  142. detail
  143. }) {
  144. this.setData({
  145. list: [],
  146. allow_load: true,
  147. current_scroll: detail.key,
  148. page: 1,
  149. });
  150. this.getList(detail.key, 1);
  151. },
  152. onReachBottom: function () {
  153. var that = this;
  154. that.data.page++;
  155. that.setData({
  156. page: that.data.page
  157. });
  158. that.getList(that.data.current_scroll, that.data.page);
  159. }
  160. })
  161. function compare(pro) {
  162. return function (obj2, obj1) {
  163. var val1 = obj1[pro];
  164. var val2 = obj2[pro];
  165. if (val1 < val2) {
  166. return 1;
  167. } else if (val1 > val2) {
  168. return -1;
  169. } else {
  170. return 0;
  171. }
  172. }
  173. }