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.

129 rivejä
2.7 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. wx.navigateTo({
  37. url: `/pages/passCar/couponDetail/couponDetail?quancode=${
  38. e.currentTarget.dataset.quancode
  39. }`,
  40. success: function (res) {
  41. // success
  42. },
  43. fail: function () {
  44. // fail
  45. },
  46. complete: function () {
  47. // complete
  48. }
  49. });
  50. },
  51. getList(key, pageNum) {
  52. var that = this;
  53. if (that.data.allow_load) {
  54. wx.showLoading({
  55. title: "加载中"
  56. });
  57. Http.get({
  58. url: config.api.couponOrderCarList + "?type=5",
  59. data: {
  60. pageNum: pageNum,
  61. pageSize: 8,
  62. couponOrderStatus: key
  63. }
  64. }).then(res => {
  65. res.data.list.map(file => {
  66. file.expiredTime = format.formatTime(
  67. file.expiredTime,
  68. "yyyy-MM-dd hh:mm:ss"
  69. );
  70. });
  71. setTimeout(function () {
  72. wx.hideLoading();
  73. }, 1200);
  74. if (pageNum > res.data.pages) {
  75. that.setData({
  76. allow_load: false
  77. });
  78. }
  79. /**
  80. * 先赋值后渲染页面
  81. * concat 不会改变原数组值
  82. * push 会改变原数组值,但不会一条一条插入,而是整个数组插入
  83. */
  84. that.data.list = that.data.list.concat(res.data.list);
  85. that.setData({
  86. list: that.data.list
  87. });
  88. })
  89. .catch(err => {
  90. setTimeout(function () {
  91. wx.hideLoading();
  92. }, 1200);
  93. wx.showToast({
  94. title: err.errMsg,
  95. icon: 'none',
  96. duration: 2000,
  97. mask: false
  98. });
  99. })
  100. } else {
  101. }
  102. },
  103. handleChange({ detail }) {
  104. this.setData({
  105. current: detail.key
  106. });
  107. },
  108. handleChangeScroll({ detail }) {
  109. this.setData({
  110. list: [],
  111. allow_load: true,
  112. current_scroll: detail.key
  113. });
  114. this.getList(detail.key, 1);
  115. this.setData({
  116. current_scroll: detail.key
  117. });
  118. },
  119. onReachBottom: function () {
  120. var that = this;
  121. that.data.page++;
  122. that.setData({
  123. page: that.data.page
  124. });
  125. that.getList(that.data.current_scroll, that.data.page);
  126. }
  127. });