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.

172 line
3.9 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: 5,
  72. };
  73. } else {
  74. var param = {
  75. pageNum: pageNum,
  76. pageSize: 6,
  77. business: key,
  78. targetAd: 5,
  79. };
  80. }
  81. if (that.data.allow_load) {
  82. that.setData({
  83. loading: true,
  84. content: "小主,我在玩命加载中...",
  85. });
  86. Http.get({
  87. url: config.api.couponChannelList,
  88. data: param
  89. })
  90. .then(res => {
  91. if (res.code == 200) {
  92. that.setData({
  93. showPage: true
  94. })
  95. }
  96. res.data.list.map(file => {
  97. file.expiredTime = util.fmtDate(file.expiredTime);
  98. });
  99. setTimeout(function () {
  100. that.setData({
  101. loading: false
  102. });
  103. }, 1400);
  104. if (pageNum >= res.data.pages) {
  105. that.setData({
  106. allow_load: false
  107. });
  108. }
  109. if (pageNum == 1) {
  110. that.setData({
  111. list: []
  112. })
  113. }
  114. var tmpArr = that.data.list;
  115. tmpArr.push.apply(tmpArr, res.data.list);
  116. that.setData({
  117. list: tmpArr
  118. })
  119. })
  120. .catch(err => {
  121. wx.showModal({
  122. title: '提示',
  123. content: err.errMsg,
  124. showCancel: false
  125. })
  126. })
  127. } else {
  128. that.setData({
  129. loading: true,
  130. content: "——— 再拉裤子就掉了啦 ———"
  131. });
  132. setTimeout(function () {
  133. that.setData({
  134. loading: false
  135. });
  136. }, 1400);
  137. }
  138. },
  139. handleChangeScroll({
  140. detail
  141. }) {
  142. this.setData({
  143. list: [],
  144. allow_load: true,
  145. current_scroll: detail.key,
  146. page: 1,
  147. });
  148. this.getList(detail.key, 1);
  149. },
  150. onReachBottom: function () {
  151. var that = this;
  152. that.data.page++;
  153. that.setData({
  154. page: that.data.page
  155. });
  156. that.getList(that.data.current_scroll, that.data.page);
  157. }
  158. })
  159. function compare(pro) {
  160. return function (obj2, obj1) {
  161. var val1 = obj1[pro];
  162. var val2 = obj2[pro];
  163. if (val1 < val2) {
  164. return 1;
  165. } else if (val1 > val2) {
  166. return -1;
  167. } else {
  168. return 0;
  169. }
  170. }
  171. }