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.

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