C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
3.3 KiB

  1. const util = require("../../../utils/util.js");
  2. const config = require("../../../config/config.js");
  3. const Http = require("../../../utils/HttpBasics");
  4. Page({
  5. data: {
  6. tabs: [
  7. {
  8. key: 0,
  9. name: "未使用"
  10. },
  11. {
  12. key: 1,
  13. name: "已使用"
  14. },
  15. {
  16. key: 2,
  17. name: "已过期"
  18. },
  19. {
  20. key: 3,
  21. name: "已退款"
  22. }
  23. ],
  24. list: [],
  25. current: "0",
  26. current_scroll: "0",
  27. page: 1,
  28. allow_load: true,
  29. loading: true, //"上拉加载"的变量,默认false,隐藏
  30. content:"",
  31. },
  32. onLoad() {
  33. this.getList(0, 0);
  34. },
  35. //点击跳转到券详情页面
  36. gotouse: function(e) {
  37. console.log(e.currentTarget.dataset.quancode);
  38. console.log("点击跳转到券详情");
  39. wx.navigateTo({
  40. url: `/pages/couponorder/detail/index?quancode=${
  41. e.currentTarget.dataset.quancode
  42. }`,
  43. success: function(res) {
  44. // success
  45. console.log("点击跳转到券详情页面");
  46. },
  47. fail: function() {
  48. // fail
  49. },
  50. complete: function() {
  51. // complete
  52. }
  53. });
  54. },
  55. getList(key, pageNum) {
  56. var that = this;
  57. console.log(key);
  58. console.log(pageNum);
  59. if (that.data.allow_load) {
  60. that.setData({
  61. loading:true,
  62. content:'小主,我在玩命加载中...'
  63. })
  64. Http.get({
  65. url: config.api.couponOrderList,
  66. data: {
  67. pageNum: pageNum,
  68. pageSize: 8,
  69. couponOrderStatus: key
  70. }
  71. }).then(res => {
  72. console.log(res);
  73. res.data.list.map(file => {
  74. file.expiredTime = util.fmtDate(file.expiredTime);
  75. });
  76. setTimeout(function() {
  77. that.setData({
  78. loading:false,
  79. })
  80. }, 1400);
  81. if (pageNum >= res.data.pages) {
  82. that.setData({
  83. allow_load: false
  84. });
  85. setTimeout(function() {
  86. that.setData({
  87. loading:false,
  88. })
  89. }, 1400);
  90. }
  91. /**
  92. * 先赋值后渲染页面
  93. * concat 不会改变原数组值
  94. * push 会改变原数组值,但不会一条一条插入,而是整个数组插入
  95. */
  96. that.data.list = that.data.list.concat(res.data.list);
  97. that.setData({
  98. list: that.data.list
  99. });
  100. });
  101. } else {
  102. console.log("加载完成allow_load设置成false");
  103. that.setData({
  104. loading:true,
  105. content:"^_^再拉裤子就掉啦ʅ(´◔౪◔)ʃ"
  106. })
  107. setTimeout(function(){
  108. that.setData({
  109. loading:false,
  110. })
  111. },1400)
  112. }
  113. },
  114. handleChange({ detail }) {
  115. console.log(detail);
  116. this.setData({
  117. current: detail.key
  118. });
  119. },
  120. handleChangeScroll({ detail }) {
  121. this.setData({
  122. list: [],
  123. allow_load: true,
  124. current_scroll: detail.key
  125. });
  126. this.getList(detail.key, 1);
  127. this.setData({
  128. current_scroll: detail.key
  129. });
  130. },
  131. onReachBottom: function() {
  132. var that = this;
  133. console.log(that.data.page);
  134. that.data.page++;
  135. console.log(that.data.page);
  136. that.setData({
  137. page: that.data.page
  138. });
  139. console.info("after++ " + that.data.page);
  140. that.getList(that.data.current_scroll, that.data.page);
  141. }
  142. });