order.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. let app = getApp();
  2. let host = app.globalData.servsers; // 请求的url
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. state:null, // 请求状态]
  9. orderList:[], // 订单列表
  10. host: host,
  11. rows:1, //默认第一页
  12. requestState:true, //请求状态,默认是true
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. this.setData({
  19. state:options.state
  20. })
  21. },
  22. /**
  23. * 生命周期函数--监听页面初次渲染完成
  24. */
  25. onReady: function () {
  26. },
  27. /**
  28. * 生命周期函数--监听页面显示
  29. */
  30. onShow: function () {
  31. this.getOrderList(this, this.data.state, this.data.rows)
  32. },
  33. /**
  34. * 生命周期函数--监听页面隐藏
  35. */
  36. onHide: function () {
  37. },
  38. /**
  39. * 生命周期函数--监听页面卸载
  40. */
  41. onUnload: function () {
  42. },
  43. /**
  44. * 页面相关事件处理函数--监听用户下拉动作
  45. */
  46. onPullDownRefresh: function () {
  47. console.log("上拉")
  48. },
  49. /**
  50. * 页面上拉触底事件的处理函数
  51. */
  52. onReachBottom: function () {
  53. if(this.data.requestState){
  54. this.getOrderList(this,this.data.state,this.data.rows + 1)
  55. }
  56. console.log('到底了')
  57. },
  58. /**
  59. * 用户点击右上角分享
  60. */
  61. onShareAppMessage: function () {
  62. },
  63. getOrderList(that, state, rows){
  64. let orderList = that.data.orderList;
  65. wx.showLoading({
  66. title: '加载中...',
  67. })
  68. wx.request({
  69. url: host + '/queryOrderCustomerByUserId',
  70. method:'get',
  71. header: {
  72. 'content-type': 'application/x-www-form-urlencoded'
  73. },
  74. data:{
  75. userId:app.globalData.user_id,
  76. orderStatus: state, //订单状态 0未支付\\1: 待定制\\2: 待发货\\3: 已发货\\4: 已完成\\5: 取消'
  77. limit:10,
  78. offset: rows,
  79. },
  80. success(res){
  81. console.log(res,"orderList")
  82. orderList.push(...res.data)
  83. if(res.data.length < 10){
  84. that.setData({
  85. requestState:false,
  86. })
  87. }
  88. that.setData({
  89. orderList: orderList
  90. })
  91. console.log(that.data.orderList,"orderList")
  92. },
  93. complete(){
  94. wx.hideLoading()
  95. }
  96. })
  97. }
  98. })