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

134 lines
3.1 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. });
  44. },
  45. getList(key, pageNum) {
  46. var that = this;
  47. console.log(key);
  48. console.log(pageNum);
  49. if (that.data.allow_load) {
  50. that.setData({
  51. loading: true,
  52. content: "小主,我在玩命加载中..."
  53. });
  54. Http.get({
  55. url: config.api.couponOrderList,
  56. data: {
  57. pageNum: pageNum,
  58. pageSize: 6,
  59. couponOrderStatus: key
  60. }
  61. }).then(res => {
  62. console.log(res);
  63. res.data.list.map(file => {
  64. file.expiredTime = util.fmtDate(file.expiredTime);
  65. });
  66. setTimeout(function() {
  67. that.setData({
  68. loading: false
  69. });
  70. }, 1400);
  71. if (pageNum >= res.data.pages) {
  72. that.setData({
  73. allow_load: false
  74. });
  75. setTimeout(function() {
  76. that.setData({
  77. loading: false
  78. });
  79. }, 1400);
  80. }
  81. /**
  82. * 先赋值后渲染页面
  83. * concat 不会改变原数组值
  84. * push 会改变原数组值,但不会一条一条插入,而是整个数组插入
  85. */
  86. that.data.list = that.data.list.concat(res.data.list);
  87. that.setData({
  88. list: that.data.list
  89. });
  90. });
  91. } else {
  92. console.log("加载完成allow_load设置成false");
  93. that.setData({
  94. loading: true,
  95. content: "^_^再拉裤子就掉啦ʅ(´◔౪◔)ʃ"
  96. });
  97. setTimeout(function() {
  98. that.setData({
  99. loading: false
  100. });
  101. }, 1400);
  102. }
  103. },
  104. handleChange({ detail }) {
  105. console.log(detail);
  106. this.setData({
  107. current: detail.key
  108. });
  109. },
  110. handleChangeScroll({ detail }) {
  111. this.setData({
  112. list: [],
  113. allow_load: true,
  114. current_scroll: detail.key
  115. });
  116. this.getList(detail.key, 1);
  117. this.setData({
  118. current_scroll: detail.key
  119. });
  120. },
  121. onReachBottom: function() {
  122. var that = this;
  123. console.log(that.data.page);
  124. that.data.page++;
  125. console.log(that.data.page);
  126. that.setData({
  127. page: that.data.page
  128. });
  129. console.info("after++ " + that.data.page);
  130. that.getList(that.data.current_scroll, that.data.page);
  131. }
  132. });