orderList.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <view class="container">
  3. <view class="order-tab">
  4. <u-tabs :list="tabList" :is-scroll="false" :current="tabIndex" @change="changeTabs" font-size="30" active-color="#52A63A"
  5. inactive-color="#666666" :bold="false" height="90"></u-tabs>
  6. </view>
  7. <scroll-view class="order-list" scroll-y="true" @scrolltolower="handleLoadMore(1)" v-if="tabIndex==0">
  8. <orderItem v-for="(item, index) in orderList1" :key="index" :orderData="item" :tabIndex="tabIndex + 1"></orderItem>
  9. </scroll-view>
  10. <scroll-view class="order-list" scroll-y="true" @scrolltolower="handleLoadMore(2)" v-else-if="tabIndex==1">
  11. <orderItem v-for="(item, index) in orderList2" :key="index" :orderData="item" :tabIndex="tabIndex + 1" @reasetList="reasetList()"></orderItem>
  12. </scroll-view>
  13. <scroll-view class="order-list" scroll-y="true" @scrolltolower="handleLoadMore(3)" v-else-if="tabIndex==2">
  14. <orderItem v-for="(item, index) in orderList3" :key="index" :orderData="item" :tabIndex="tabIndex + 1" @reasetList="reasetList()"></orderItem>
  15. </scroll-view>
  16. <scroll-view class="order-list" scroll-y="true" @scrolltolower="handleLoadMore(4)" v-else-if="tabIndex==3">
  17. <orderItem v-for="(item, index) in orderList4" :key="index" :orderData="item" :tabIndex="tabIndex + 1" @reasetList="reasetList()"></orderItem>
  18. </scroll-view>
  19. <scroll-view class="order-list" scroll-y="true" @scrolltolower="handleLoadMore(5)" v-else-if="tabIndex==4">
  20. <orderItem v-for="(item, index) in orderList5" :key="index" :orderData="item" :tabIndex="tabIndex + 1" @reasetList="reasetList()"></orderItem>
  21. </scroll-view>
  22. <u-top-tips ref="uTips"></u-top-tips>
  23. </view>
  24. </template>
  25. <script>
  26. const NET = require('@/utils/request')
  27. const API = require('@/config/api')
  28. import orderItem from '@/pagesMain/orderItem.vue'
  29. export default {
  30. components: {
  31. orderItem
  32. },
  33. data() {
  34. return {
  35. tabIndex: 0,
  36. tabList: [{
  37. name: '全部'
  38. }, {
  39. name: '待发货'
  40. }, {
  41. name: '已发货'
  42. }, {
  43. name: '已收货'
  44. }, {
  45. name: '已完成'
  46. }, ],
  47. pageIndex1: 1,
  48. isOver1: false,
  49. orderList1: [],
  50. pageIndex2: 1,
  51. isOver2: false,
  52. orderList2: [],
  53. pageIndex3: 1,
  54. isOver3: false,
  55. orderList3: [],
  56. pageIndex4: 1,
  57. isOver4: false,
  58. orderList4: [],
  59. pageIndex5: 1,
  60. isOver5: false,
  61. orderList5: [],
  62. }
  63. },
  64. onLoad(options) {
  65. this.tabIndex = options.type - 1
  66. },
  67. onShow(options) {
  68. this['pageIndex' + (this.tabIndex + 1)] = 1
  69. this['isOver' + (this.tabIndex + 1)] = false
  70. this['orderList' + (this.tabIndex + 1)] = []
  71. this.getOrderList(this.tabIndex + 1)
  72. },
  73. methods: {
  74. // 切换tab
  75. changeTabs(index) {
  76. this.tabIndex = index;
  77. this.reasetList()
  78. },
  79. // 刷新数据
  80. reasetList() {
  81. this['isOver' + (this.tabIndex + 1)] = false
  82. this['pageIndex' + (this.tabIndex + 1)] = 1
  83. this['orderList' + (this.tabIndex + 1)] = []
  84. this.getOrderList(this.tabIndex + 1)
  85. },
  86. // 懒加载
  87. handleLoadMore(type) {
  88. if (!this['isOver' + type]) {
  89. this['pageIndex' + type]++
  90. this.getOrderList(type)
  91. }
  92. },
  93. // 获取全部订单
  94. getOrderList(type) {
  95. NET.request(API.getOrderList + this['pageIndex' + type] + '/10', {
  96. flag: type,
  97. }, 'GET').then(res => {
  98. this['isOver' + type] = res.data.list.length != 10
  99. this['orderList' + type] = this['orderList' + type].concat(res.data.list)
  100. }).catch(error => {
  101. this.$refs.uTips.show({
  102. title: error.data.msg,
  103. type: 'warning',
  104. })
  105. })
  106. },
  107. }
  108. }
  109. </script>
  110. <style lang="less" scoped>
  111. page {
  112. width: 100%;
  113. height: 100%;
  114. }
  115. .container {
  116. width: 100%;
  117. height: 100%;
  118. float: left;
  119. background-color: #f7f7f7;
  120. .order-tab {
  121. width: 100%;
  122. height: 45px;
  123. float: left;
  124. }
  125. .order-list {
  126. width: calc(100% - 30px);
  127. height: calc(100% - 46px);
  128. float: left;
  129. margin: 0 15px;
  130. box-sizing: border-box;
  131. padding-top: 15px;
  132. }
  133. }
  134. </style>