C端小程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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