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.

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