order.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // pages/order/order.js
  2. const app = getApp()
  3. const { axios } = app.globalData;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. active: 0,
  10. orderlist: [[], [], [], []],
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. wx.lxd.Ctr({
  17. // nav
  18. title: "我的订单", //标题
  19. })
  20. },
  21. // tabs 切换
  22. tabs (e) {
  23. let { index: active } = e.detail;
  24. this.setData({
  25. active
  26. })
  27. this.orderRequest();
  28. },
  29. // 请求数据
  30. orderlist: [{
  31. totalPage: 1,
  32. currentPage: 1,
  33. }, {
  34. totalPage: 1,
  35. currentPage: 1,
  36. }, {
  37. totalPage: 1,
  38. currentPage: 1,
  39. }, {
  40. totalPage: 1,
  41. currentPage: 1,
  42. }],
  43. orderRequest () {
  44. let { active, orderlist } = this.data,
  45. status = active == 0 ? '' : active, that = this;
  46. if (this.orderlist[active]["totalPage"] < this.orderlist[active]["currentPage"]) return false;
  47. axios({
  48. url: "/order/",
  49. method: 'get',
  50. data: {
  51. status,
  52. limit: 10,
  53. page: that.orderlist[active]["currentPage"]
  54. },
  55. success (res) {
  56. let { totalPage, data } = res.data;
  57. orderlist[active] = [...orderlist[active], ...data];
  58. that.setData({ orderlist });
  59. console.log(orderlist)
  60. that.orderlist[active]["totalPage"] = totalPage;
  61. that.orderlist[active]["currentPage"]++;
  62. }
  63. })
  64. },
  65. /**
  66. * 生命周期函数--监听页面初次渲染完成
  67. */
  68. onReady: function () {
  69. },
  70. /**
  71. * 生命周期函数--监听页面显示
  72. */
  73. onShow: function () {
  74. this.orderRequest()
  75. },
  76. /**
  77. * 生命周期函数--监听页面隐藏
  78. */
  79. onHide: function () {
  80. },
  81. /**
  82. * 生命周期函数--监听页面卸载
  83. */
  84. onUnload: function () {
  85. },
  86. /**
  87. * 页面相关事件处理函数--监听用户下拉动作
  88. */
  89. onPullDownRefresh: function () {
  90. let { active } = this.data;
  91. this.orderlist[active]["totalPage"] = 1;
  92. this.orderlist[active]["currentPage"] = 1;
  93. this.setData({
  94. orderlist: [[], [], [], []],
  95. })
  96. this.orderRequest()
  97. },
  98. /**
  99. * 页面上拉触底事件的处理函数
  100. */
  101. onReachBottom: function () {
  102. this.orderRequest()
  103. },
  104. })