order.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. Page({
  4. data: {
  5. orderList: [],
  6. showType: 0,
  7. page: 1,
  8. limit: 10,
  9. totalPages: 1
  10. },
  11. onLoad: function(options) {
  12. // 页面初始化 options为页面跳转所带来的参数
  13. },
  14. getOrderList() {
  15. wx.showLoading({
  16. title: '加载中',
  17. });
  18. setTimeout(function() {
  19. wx.hideLoading()
  20. }, 2000);
  21. let that = this;
  22. util.request(api.OrderList, {
  23. showType: that.data.showType,
  24. page: that.data.page,
  25. limit: that.data.limit
  26. }).then(function(res) {
  27. if (res.errno === 0) {
  28. that.setData({
  29. orderList: that.data.orderList.concat(res.data.list),
  30. totalPages: res.data.pages
  31. });
  32. wx.hideLoading();
  33. }
  34. });
  35. },
  36. onReachBottom() {
  37. if (this.data.totalPages > this.data.page) {
  38. this.setData({
  39. page: this.data.page + 1
  40. });
  41. this.getOrderList();
  42. } else {
  43. wx.showToast({
  44. title: '没有更多订单了',
  45. icon: 'none',
  46. duration: 2000
  47. });
  48. return false;
  49. }
  50. },
  51. switchTab: function(event) {
  52. let showType = event.currentTarget.dataset.index;
  53. this.setData({
  54. orderList: [],
  55. showType: showType,
  56. page: 1,
  57. limit: 10,
  58. totalPages: 1
  59. });
  60. this.getOrderList();
  61. },
  62. onReady: function() {
  63. // 页面渲染完成
  64. },
  65. onShow: function() {
  66. // 页面显示
  67. this.getOrderList();
  68. },
  69. onHide: function() {
  70. // 页面隐藏
  71. },
  72. onUnload: function() {
  73. // 页面关闭
  74. }
  75. })