C端小程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

171 Zeilen
3.8 KiB

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