C端小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

126 řádky
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. wx.showToast({
  91. title: err.errMsg,
  92. icon: 'none',
  93. duration: 2000,
  94. mask: false
  95. });
  96. })
  97. } else {
  98. }
  99. },
  100. handleChange({ detail }) {
  101. this.setData({
  102. current: detail.key
  103. });
  104. },
  105. handleChangeScroll({ detail }) {
  106. this.setData({
  107. list: [],
  108. allow_load: true,
  109. current_scroll: detail.key
  110. });
  111. this.getList(detail.key, 1);
  112. this.setData({
  113. current_scroll: detail.key
  114. });
  115. },
  116. onReachBottom: function () {
  117. var that = this;
  118. that.data.page++;
  119. that.setData({
  120. page: that.data.page
  121. });
  122. that.getList(that.data.current_scroll, that.data.page);
  123. }
  124. });