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.

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