recentOrder.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. var app = getApp()
  2. Page({
  3. data: {
  4. order: [],
  5. links: null,
  6. id: '',
  7. curPage: 1,
  8. },
  9. onLoad: function(options) {
  10. this.setData({
  11. id: options.id
  12. })
  13. this.getList();
  14. },
  15. //获取列表
  16. getList() {
  17. wx.showLoading({
  18. title: '加载中...',
  19. })
  20. let url = '';
  21. if (this.data.curPage == 1) {
  22. url = 'bike/latelyOrders?page = 1';
  23. } else {
  24. url = 'bike/latelyOrderRent?page = 1'
  25. }
  26. let data = {
  27. bike_id: this.data.id
  28. }
  29. app.request(url, data, 'POST').then(res => {
  30. wx.hideLoading();
  31. console.log(res);
  32. this.setData({
  33. order: res.data.data,
  34. links: res.data.links.next
  35. })
  36. })
  37. },
  38. //跳转到详情页
  39. skipDetail(e) {
  40. let index = e.currentTarget.dataset.index
  41. wx.navigateTo({
  42. url: '/pages/orderDetail/orderDetail?id=' + this.data.order[index].id + '&index=' + this.data.curPage, //普通订单和日租订单
  43. })
  44. },
  45. //tab切换
  46. choose(e) {
  47. this.setData({
  48. curPage: e.currentTarget.dataset.idx
  49. })
  50. this.getList();
  51. },
  52. onPullDownRefresh: function() {
  53. let self = this;
  54. wx.showLoading({
  55. title: '加载中...',
  56. })
  57. let url = "";
  58. if (self.data.curPage == 1) {
  59. url = 'bike/latelyOrders?page = 1'
  60. } else {
  61. url = 'bike/latelyOrderRent?page =1 '
  62. }
  63. let data = {
  64. bike_id: self.data.id
  65. }
  66. app.request(url, data, 'POST').then(res => {
  67. console.log(res)
  68. wx.showToast({
  69. title: '刷新成功',
  70. icon: 'none'
  71. })
  72. wx.hideLoading();
  73. wx.stopPullDownRefresh();
  74. self.setData({
  75. order: res.data.data,
  76. links: res.data.links.next
  77. })
  78. })
  79. },
  80. onReachBottom: function() {
  81. var that = this;
  82. if (that.data.links != null) {
  83. wx.request({
  84. url: that.data.links,
  85. header: {
  86. 'content-type': 'application/x-www-form-urlencoded',
  87. 'Authorization': 'bearer' + ' ' + wx.getStorageSync('token'),
  88. },
  89. method: 'POST',
  90. data: {
  91. bike_id: that.data.id
  92. },
  93. success: function(res) {
  94. console.log(res)
  95. wx.hideLoading()
  96. that.setData({
  97. order: that.data.order.concat(res.data.data),
  98. links: res.data.links.next
  99. })
  100. }
  101. })
  102. } else {
  103. wx.hideLoading()
  104. wx.showToast({
  105. title: '没数据了~',
  106. icon: 'none'
  107. })
  108. }
  109. },
  110. })