C端小程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

130 行
2.9 KiB

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