order.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. const App = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. isLoading: true,
  8. dataType: -1,
  9. page: 1,
  10. no_more: false,
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function(options) {
  16. // 设置swiper的高度
  17. this.setSwiperHeight();
  18. },
  19. /**
  20. * 生命周期函数--监听页面显示
  21. */
  22. onShow: function() {
  23. // 获取订单列表
  24. this.getOrderList();
  25. },
  26. /**
  27. * 获取订单列表
  28. */
  29. getOrderList: function(isNextPage, page) {
  30. let _this = this;
  31. App._get('user.dealer.order/lists', {
  32. settled: _this.data.dataType,
  33. page: page || 1,
  34. }, function(result) {
  35. // 创建页面数据
  36. _this.setData(_this.createData(result.data, isNextPage));
  37. });
  38. },
  39. /**
  40. * 创建页面数据
  41. */
  42. createData: function(data, isNextPage) {
  43. data['isLoading'] = false;
  44. // 列表数据
  45. let dataList = this.data.list;
  46. if (isNextPage == true && (typeof dataList !== 'undefined')) {
  47. data.list.data = dataList.data.concat(data.list.data)
  48. }
  49. // 设置当前页面标题
  50. wx.setNavigationBarTitle({
  51. title: data.words.order.title.value
  52. })
  53. // 当前用户id
  54. data['user_id'] = App.getUserId();
  55. // 导航栏数据
  56. data['tabList'] = [{
  57. value: -1,
  58. text: data.words.order.words.all.value,
  59. }, {
  60. value: 0,
  61. text: data.words.order.words.unsettled.value,
  62. }, {
  63. value: 1,
  64. text: data.words.order.words.settled.value,
  65. }];
  66. return data;
  67. },
  68. /**
  69. * 设置swiper的高度
  70. */
  71. setSwiperHeight: function() {
  72. // 获取系统信息(拿到屏幕宽度)
  73. let systemInfo = wx.getSystemInfoSync(),
  74. rpx = systemInfo.windowWidth / 750, // 计算rpx
  75. tapHeight = Math.floor(rpx * 82), // tap高度
  76. swiperHeight = systemInfo.windowHeight - tapHeight; // swiper高度
  77. this.setData({
  78. swiperHeight
  79. });
  80. },
  81. /**
  82. * 点击tab切换
  83. */
  84. swichNav: function(e) {
  85. let _this = this;
  86. _this.setData({
  87. dataType: e.target.dataset.current,
  88. list: {},
  89. page: 1,
  90. no_more: false,
  91. isLoading: true,
  92. }, function() {
  93. // 获取订单列表
  94. _this.getOrderList();
  95. });
  96. },
  97. /**
  98. * 下拉到底加载数据
  99. */
  100. triggerDownLoad: function() {
  101. // 已经是最后一页
  102. if (this.data.page >= this.data.list.last_page) {
  103. this.setData({
  104. no_more: true
  105. });
  106. return false;
  107. }
  108. // 获取订单列表
  109. this.getOrderList(true, ++this.data.page);
  110. },
  111. })