historicalOrder.js 2.3 KB

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