trip.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. if (app.globalData.req) {
  23. that.getOrder()
  24. }
  25. }, 1000),
  26. //获取订单列表
  27. getOrder: function () {
  28. let that = this
  29. let data = {
  30. page: that.data.pages
  31. }
  32. app.request('/orders', data, 'GET', app.globalData.req).then(res => {
  33. console.log(res)
  34. if (res.status == 200) {
  35. let arr=res.data.data
  36. var orderList =that.data.orderList.concat(arr);
  37. if(arr.length==0){
  38. my.showToast({
  39. content: '暂无更多~',
  40. icon:'none'
  41. })
  42. }else{
  43. that.setData({
  44. orderList,
  45. links:res.data.meta.pagination.links
  46. })
  47. }
  48. my.hideLoading({
  49. complete: (res) => { },
  50. })
  51. }
  52. }).catch(err => {
  53. console.log(err)
  54. })
  55. },
  56. //跳转订单详情页面
  57. tripDetail: function (e) {
  58. console.log(e, 'ppppppp')
  59. let status = e.currentTarget.dataset.index.status
  60. let order_no = e.currentTarget.dataset.index.no
  61. if (status == 2) {
  62. my.navigateTo({
  63. url: '/pages/pay/pay?order=' + order_no,
  64. })
  65. } else {
  66. my.navigateTo({
  67. url: '/pages/trip_detail/trip_detail?order_no=' + order_no,
  68. })
  69. }
  70. },
  71. //下拉刷新
  72. onReachBottom: function () {
  73. if(this.data.links==null){
  74. my.showToast({
  75. content: '暂无更多',
  76. icon:'none'
  77. })
  78. return
  79. }else{
  80. let page=this.data.pages++
  81. page++
  82. this.setData({
  83. pages: page
  84. })
  85. this.getOrder()
  86. }
  87. },
  88. onReady: function () {
  89. },
  90. onShow: function () {
  91. },
  92. onHide: function () {
  93. },
  94. onUnload: function () {
  95. },
  96. onPullDownRefresh: function () {
  97. },
  98. onShareAppMessage: function () {
  99. },
  100. })