C端小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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