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.

143 lines
3.1 KiB

  1. let config = require("../../../config/config.js");
  2. let Http = require("../../../utils/HttpBasics");
  3. const util = require("../../../utils/util");
  4. let app = getApp();
  5. Page({
  6. data: {
  7. tabs: [{
  8. key: "all",
  9. name: "全部"
  10. },
  11. {
  12. key: 0,
  13. name: "待付款"
  14. },
  15. {
  16. key: 1,
  17. name: "已完成"
  18. }
  19. ],
  20. list: [],
  21. current: "",
  22. current_scroll: "1",
  23. page: 1,
  24. allow_load: true,
  25. loading: true, //"上拉加载"的变量,默认false,隐藏
  26. content: "",
  27. },
  28. onLoad(e) {
  29. this.getList(e.id, 1);
  30. this.setData({
  31. current_scroll: e.id
  32. });
  33. },
  34. gotopay: function (e) {
  35. console.log("orderId" + e.currentTarget.dataset.id);
  36. wx.navigateTo({
  37. url: `/pages/order/detail/index?orderId=${e.currentTarget.dataset.id}&flag='pay'`
  38. })
  39. },
  40. getList(key, pageNum) {
  41. let that = this;
  42. console.log(key);
  43. /**
  44. * key==0
  45. * 不发送该字段
  46. */
  47. if (key == 'all') {
  48. var variable = {
  49. pageNum: pageNum,
  50. pageSize: 5,
  51. paymentType: 0
  52. };
  53. } else {
  54. var variable = {
  55. pageNum: pageNum,
  56. pageSize: 5,
  57. orderStatus: key,
  58. paymentType: 0
  59. };
  60. }
  61. if (that.data.allow_load) {
  62. that.setData({
  63. loading: true,
  64. content: '小主,我在玩命加载中...'
  65. })
  66. Http.get({
  67. url: config.api.orderList,
  68. data: variable
  69. }).then(res => {
  70. console.log(res);
  71. if (pageNum > res.data.pages) {
  72. that.setData({
  73. allow_load: false
  74. });
  75. setTimeout(function () {
  76. that.setData({
  77. loading: false,
  78. })
  79. }, 1400);
  80. }
  81. setTimeout(function () {
  82. that.setData({
  83. loading: false,
  84. })
  85. }, 1400);
  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. for (let i = 0; i < that.data.list.length; i++) {
  96. that.setData({
  97. createDate: util.fmtDate(that.data.list[i].createDate)
  98. })
  99. }
  100. });
  101. } else {
  102. console.log("加载完成allow_load设置成false");
  103. that.setData({
  104. loading: true,
  105. ccontent: "——— 在拉裤子就掉了啦 ———"
  106. })
  107. setTimeout(function () {
  108. that.setData({
  109. loading: false,
  110. })
  111. }, 1400)
  112. }
  113. },
  114. handleChange({
  115. detail
  116. }) {
  117. this.setData({
  118. current: detail.key
  119. });
  120. },
  121. handleChangeScroll({
  122. detail
  123. }) {
  124. this.setData({
  125. list: [],
  126. allow_load: true,
  127. current_scroll: detail.key
  128. })
  129. this.getList(detail.key, 1);
  130. },
  131. onReachBottom: function () {
  132. var that = this;
  133. that.data.page++;
  134. that.setData({
  135. page: that.data.page
  136. });
  137. that.getList(that.data.current_scroll, that.data.page);
  138. }
  139. });