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.

113 line
2.3 KiB

  1. let config = require("../../../config/config.js");
  2. let Http = require("../../../utils/HttpBasics");
  3. let app = getApp();
  4. Page({
  5. data: {
  6. tabs: [
  7. {
  8. key: 0,
  9. name: "全部"
  10. },
  11. {
  12. key: 1,
  13. name: "待付款"
  14. },
  15. {
  16. key: 2,
  17. name: "已完成"
  18. }
  19. ],
  20. list: [],
  21. current: "",
  22. current_scroll: "1",
  23. page: 1,
  24. allow_load: true
  25. },
  26. onLoad(e) {
  27. this.getList(e.id, 1);
  28. this.setData({
  29. current_scroll: e.id
  30. });
  31. },
  32. getList(key, pageNum) {
  33. let that = this;
  34. console.log(key);
  35. /**
  36. * key==0
  37. * 不发送该字段
  38. */
  39. if (key == 0) {
  40. var variable = {
  41. pageNum: pageNum,
  42. pageSize: 5
  43. };
  44. } else {
  45. var variable = {
  46. pageNum: pageNum,
  47. pageSize: 5,
  48. orderStatus: key
  49. };
  50. }
  51. if (that.data.allow_load) {
  52. wx.showLoading({
  53. title: "加载中"
  54. });
  55. Http.get({
  56. url: config.api.orderList,
  57. data: variable
  58. }).then(res => {
  59. console.log(res);
  60. console.log("姐姐的订单列表");
  61. setTimeout(function() {
  62. wx.hideLoading();
  63. }, 1200);
  64. if (pageNum >= res.data.pages) {
  65. that.setData({
  66. allow_load: false
  67. });
  68. }
  69. /**
  70. * 先赋值后渲染页面
  71. * concat 不会改变原数组值
  72. * push 会改变原数组值,但不会一条一条插入,而是整个数组插入
  73. */
  74. that.data.list = that.data.list.concat(res.data.list);
  75. that.setData({
  76. list: that.data.list
  77. });
  78. });
  79. } else {
  80. console.log("加载完成allow_load设置成false");
  81. }
  82. },
  83. handleChange({ detail }) {
  84. this.setData({
  85. current: detail.key
  86. });
  87. },
  88. handleChangeScroll({ detail }) {
  89. this.setData({
  90. list:[],
  91. allow_load: true,
  92. current_scroll: detail.key
  93. })
  94. this.getList(detail.key, 1);
  95. },
  96. onReachBottom: function() {
  97. var that = this;
  98. console.log(that.data.page);
  99. that.data.page++;
  100. console.log(that.data.page);
  101. that.setData({
  102. page: that.data.page
  103. });
  104. console.info("after++ " + that.data.page);
  105. that.getList(that.data.current_scroll, that.data.page);
  106. }
  107. });