C端小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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