historicalOrder.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. this.setData({
  37. order: res.data.data,
  38. links: res.data.links.next
  39. })
  40. })
  41. },
  42. choose(e) {
  43. this.setData({
  44. curPage: e.currentTarget.dataset.idx
  45. })
  46. this.getList();
  47. },
  48. onPullDownRefresh: function() {
  49. let self = this;
  50. wx.showLoading({
  51. title: '加载中...',
  52. })
  53. let url = "";
  54. if (self.data.curPage == 1) {
  55. url = 'user/order?page = 1'
  56. } else {
  57. url = 'user/orderRent?page =1 '
  58. }
  59. let data = {
  60. user_id: this.data.user_id
  61. }
  62. app.request(url, data, 'GET').then(res => {
  63. wx.showToast({
  64. title: '刷新成功',
  65. icon: 'none'
  66. })
  67. wx.hideLoading();
  68. wx.stopPullDownRefresh();
  69. self.setData({
  70. order: res.data.data,
  71. links: res.data.links.next
  72. })
  73. })
  74. },
  75. onReachBottom: function() {
  76. var that = this;
  77. if (that.data.links != null) {
  78. wx.request({
  79. url: that.data.links,
  80. header: {
  81. 'content-type': 'application/x-www-form-urlencoded',
  82. 'Authorization': 'bearer' + ' ' + wx.getStorageSync('token'),
  83. },
  84. method: 'POST',
  85. data: {
  86. bike_id: that.data.id
  87. },
  88. success: function(res) {
  89. wx.hideLoading()
  90. that.setData({
  91. order: that.data.order.concat(res.data.data),
  92. links: res.data.links.next
  93. })
  94. }
  95. })
  96. } else {
  97. wx.hideLoading()
  98. wx.showToast({
  99. title: '没数据了~',
  100. icon: 'none'
  101. })
  102. }
  103. },
  104. })