trip.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // pages/trip/trip.js
  2. var app = getApp()
  3. const util = require('../../utils/utils.js')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. orderList: [],
  10. pages: 1,//页码
  11. links:'',//下一页地址
  12. },
  13. onLoad: function (options) {
  14. this.initial()
  15. },
  16. initial: util.throttle(function (e) {
  17. var that = this;
  18. my.showLoading({
  19. content: '加载中...',
  20. mask: true
  21. })
  22. that.getOrder()
  23. }, 1000),
  24. //获取订单列表
  25. getOrder: function () {
  26. let that = this
  27. let data = {
  28. page: that.data.pages
  29. }
  30. app.request('/orders', data, 'GET').then(res => {
  31. console.log(res)
  32. if (res.status == 200) {
  33. let arr=res.data.data
  34. var orderList =that.data.orderList.concat(arr);
  35. if(arr.length==0){
  36. my.showToast({
  37. content: '暂无更多~',
  38. icon:'none'
  39. })
  40. }else{
  41. that.setData({
  42. orderList,
  43. links:res.data.meta.pagination.links
  44. })
  45. }
  46. my.hideLoading({
  47. complete: (res) => { },
  48. })
  49. }
  50. }).catch(err => {
  51. console.log(err)
  52. })
  53. },
  54. //跳转订单详情页面
  55. tripDetail: function (e) {
  56. console.log(e, 'ppppppp')
  57. let status = e.currentTarget.dataset.index.status
  58. let order_no = e.currentTarget.dataset.index.no
  59. if (status == 2) {
  60. my.navigateTo({
  61. url: '/pages/pay/pay?order=' + order_no,
  62. })
  63. } else {
  64. my.navigateTo({
  65. url: '/pages/trip_detail/trip_detail?order_no=' + order_no,
  66. })
  67. }
  68. },
  69. //下拉刷新
  70. onReachBottom: function () {
  71. if(this.data.links==null){
  72. my.showToast({
  73. content: '暂无更多',
  74. icon:'none'
  75. })
  76. return
  77. }else{
  78. let page=this.data.pages++
  79. page++
  80. this.setData({
  81. pages: page
  82. })
  83. this.getOrder()
  84. }
  85. },
  86. onReady: function () {
  87. },
  88. onShow: function () {
  89. },
  90. onHide: function () {
  91. },
  92. onUnload: function () {
  93. },
  94. onPullDownRefresh: function () {
  95. },
  96. onShareAppMessage: function () {
  97. },
  98. })