orderList.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. onPullDownRefresh() {
  74. this['pageIndex' + (this.tabIndex + 1)] = 1
  75. this['isOver' + (this.tabIndex + 1)] = false
  76. this['orderList' + (this.tabIndex + 1)] = []
  77. this.getOrderList(this.tabIndex + 1, 'refresh')
  78. },
  79. methods: {
  80. // 切换tab
  81. changeTabs(index) {
  82. this.tabIndex = index;
  83. this.reasetList()
  84. },
  85. // 刷新数据
  86. reasetList() {
  87. this['isOver' + (this.tabIndex + 1)] = false
  88. this['pageIndex' + (this.tabIndex + 1)] = 1
  89. this['orderList' + (this.tabIndex + 1)] = []
  90. this.getOrderList(this.tabIndex + 1)
  91. },
  92. // 懒加载
  93. handleLoadMore(type) {
  94. if (!this['isOver' + type]) {
  95. this['pageIndex' + type]++
  96. this.getOrderList(type)
  97. }
  98. },
  99. // 获取全部订单
  100. getOrderList(type, refresh) {
  101. NET.request(API.getOrderList + this['pageIndex' + type] + '/10', {
  102. flag: type,
  103. }, 'GET').then(res => {
  104. if (refresh == 'refresh') {
  105. uni.stopPullDownRefresh();
  106. }
  107. this['isOver' + type] = res.data.list.length != 10
  108. this['orderList' + type] = this['orderList' + type].concat(res.data.list)
  109. if (this['orderList' + type].length) {
  110. this['orderList' + type].forEach(v => {
  111. v.noPick = true
  112. if (v.products.some(vv => {return vv.productType == 3} )) {
  113. v.noPick = false
  114. }
  115. })
  116. }
  117. }).catch(error => {
  118. this.$refs.uTips.show({
  119. title: error.data.msg,
  120. type: 'warning',
  121. })
  122. })
  123. },
  124. }
  125. }
  126. </script>
  127. <style lang="less" scoped>
  128. page {
  129. width: 100%;
  130. height: 100%;
  131. }
  132. .container {
  133. width: 100%;
  134. height: 100%;
  135. float: left;
  136. background-color: #f7f7f7;
  137. .order-tab {
  138. width: 100%;
  139. height: 45px;
  140. float: left;
  141. }
  142. .order-list {
  143. width: calc(100% - 30px);
  144. height: calc(100% - 46px);
  145. float: left;
  146. margin: 0 15px;
  147. box-sizing: border-box;
  148. padding-top: 15px;
  149. }
  150. }
  151. </style>