C端小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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