recentOrder.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. if (res.statusCode == 200) {
  32. console.log(res);
  33. this.setData({
  34. order: res.data.data,
  35. links: res.data.links.next
  36. })
  37. }
  38. })
  39. },
  40. //跳转到详情页
  41. skipDetail(e) {
  42. let index = e.currentTarget.dataset.index
  43. wx.navigateTo({
  44. url: '/pages/orderDetail/orderDetail?id=' + this.data.order[index].id + '&index=' + this.data.curPage, //普通订单和日租订单
  45. })
  46. },
  47. //tab切换
  48. choose(e) {
  49. this.setData({
  50. curPage: e.currentTarget.dataset.idx
  51. })
  52. this.getList();
  53. },
  54. onPullDownRefresh: function() {
  55. let self = this;
  56. wx.showLoading({
  57. title: '加载中...',
  58. })
  59. let url = "";
  60. if (self.data.curPage == 1) {
  61. url = 'bike/latelyOrders?page = 1'
  62. } else {
  63. url = 'bike/latelyOrderRent?page =1 '
  64. }
  65. let data = {
  66. bike_id: self.data.id
  67. }
  68. app.request(url, data, 'POST').then(res => {
  69. if (res.statusCode == 200) {
  70. wx.showToast({
  71. title: '刷新成功',
  72. icon: 'none'
  73. })
  74. wx.hideLoading();
  75. wx.stopPullDownRefresh();
  76. self.setData({
  77. order: res.data.data,
  78. links: res.data.links.next
  79. })
  80. }
  81. })
  82. },
  83. onReachBottom: function() {
  84. var that = this;
  85. if (that.data.links != null) {
  86. wx.request({
  87. url: that.data.links,
  88. header: {
  89. 'content-type': 'application/x-www-form-urlencoded',
  90. 'Authorization': 'bearer' + ' ' + wx.getStorageSync('token'),
  91. },
  92. method: 'POST',
  93. data: {
  94. bike_id: that.data.id
  95. },
  96. success: function(res) {
  97. console.log(res)
  98. wx.hideLoading()
  99. that.setData({
  100. order: that.data.order.concat(res.data.data),
  101. links: res.data.links.next
  102. })
  103. }
  104. })
  105. } else {
  106. wx.hideLoading()
  107. wx.showToast({
  108. title: '没数据了~',
  109. icon: 'none'
  110. })
  111. }
  112. },
  113. })