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. let that = this
  14. try {
  15. var tab = wx.getStorageSync('tab');
  16. this.setData({
  17. showType: tab
  18. });
  19. } catch (e) {}
  20. },
  21. getOrderList() {
  22. let that = this;
  23. util.request(api.OrderList, {
  24. showType: that.data.showType,
  25. page: that.data.page,
  26. limit: that.data.limit
  27. }).then(function(res) {
  28. if (res.errno === 0) {
  29. console.log(res.data);
  30. that.setData({
  31. orderList: that.data.orderList.concat(res.data.list),
  32. totalPages: res.data.pages
  33. });
  34. }
  35. });
  36. },
  37. onReachBottom() {
  38. if (this.data.totalPages > this.data.page) {
  39. this.setData({
  40. page: this.data.page + 1
  41. });
  42. this.getOrderList();
  43. } else {
  44. wx.showToast({
  45. title: '没有更多订单了',
  46. icon: 'none',
  47. duration: 2000
  48. });
  49. return false;
  50. }
  51. },
  52. switchTab: function(event) {
  53. let showType = event.currentTarget.dataset.index;
  54. this.setData({
  55. orderList: [],
  56. showType: showType,
  57. page: 1,
  58. limit: 10,
  59. totalPages: 1
  60. });
  61. this.getOrderList();
  62. },
  63. onReady: function() {
  64. // 页面渲染完成
  65. },
  66. onShow: function() {
  67. // 页面显示
  68. this.getOrderList();
  69. },
  70. onHide: function() {
  71. // 页面隐藏
  72. },
  73. onUnload: function() {
  74. // 页面关闭
  75. }
  76. })