list.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <view class="page">
  3. <view class="tabbox">
  4. <u-tabs :is-scroll="false" :list="tabOps" :current="tabIndex" @change="changeTab"></u-tabs>
  5. </view>
  6. <view class="content">
  7. <!-- 列表
  8. :style="{height:'calc(100vh - '+topHeight+'px)'}"-->
  9. <view class="list" v-if="orderList[tabIndex]&&orderList[tabIndex].length>0">
  10. <OrderCard v-for="(item, index) in orderList[tabIndex]" :key="index" :data="item" @refresh="refreshData"></OrderCard>
  11. </view>
  12. <NoData height="60vh" type="order" v-if="orderLoad[tabIndex].finish&&orderList[tabIndex].length==0"></NoData>
  13. <!-- <u-loadmore v-else :status="orderLoad[tabIndex].finish?'nomore':orderLoad[tabIndex].loading?'loading':'loadmore'" :load-text="loadText" margin-top="60" /> -->
  14. <LoadMore v-else :loadtype="orderLoad[tabIndex]"></LoadMore>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. // 组件
  20. import NavbarTabSearch from '@/pages-mall/components/navbar-tab-search.vue';
  21. import OrderCard from '@/pages-mall/components/order/order-card.vue';
  22. const app = getApp();
  23. var _self;
  24. export default {
  25. components: { NavbarTabSearch, OrderCard },
  26. data() {
  27. return {
  28. topHeight:app.globalData.statusBarHeight + app.globalData.navBarHeight*2 - app.globalData.menuHeight,
  29. // 当前tab
  30. tabIndex: 0,
  31. loadText: {
  32. loadmore: '轻轻上拉',
  33. loading: ' ',
  34. nomore: '没有更多了'
  35. },
  36. tabOps:[
  37. { name: '全部', value: '' ,type:'all'},
  38. { name: '待付款', value: '10', type:'type10' },
  39. { name: '待发货', value: '11', type:'type11' },
  40. { name: '待收货', value: '12', type:'type12' },
  41. { name: '已完成', value: '13', type:'type13' },
  42. ],
  43. orders:[],
  44. orderList: [],//常规订单
  45. refundOrder:[],//售后订单
  46. orderLoad:[{
  47. page:1,
  48. loading:true,
  49. finish:false,
  50. },{
  51. page:1,
  52. loading:true,
  53. finish:false,
  54. },{
  55. page:1,
  56. loading:true,
  57. finish:false,
  58. },{
  59. page:1,
  60. loading:true,
  61. finish:false,
  62. },{
  63. page:1,
  64. loading:true,
  65. finish:false,
  66. },{
  67. page:1,
  68. loading:true,
  69. finish:false,
  70. },]
  71. };
  72. },
  73. onLoad(ops) {
  74. _self = this;
  75. let selIndex=0;
  76. if (ops.tabIndex) {
  77. selIndex = Number(ops.tabIndex);
  78. }
  79. this.tabIndex = selIndex;
  80. this.$nextTick(() => {
  81. _self.changeTab(selIndex);
  82. });
  83. },
  84. onPullDownRefresh(){
  85. // uni.stopPullDownRefresh();
  86. this.orderLoad[this.tabIndex].page=1;
  87. this.orderLoad[this.tabIndex].finish=false;
  88. this.orderList[this.tabIndex]=[];
  89. this.getData();
  90. },
  91. onShow() {
  92. console.log('onShow.......')
  93. this.refreshData();
  94. },
  95. onReachBottom(){
  96. console.log('滚动到底部')
  97. this.getData();
  98. },
  99. methods: {
  100. // 刷新页面
  101. refreshData(){
  102. uni.startPullDownRefresh();
  103. },
  104. // 更新数据
  105. getData(){
  106. this.getOrderList();
  107. },
  108. // 切换tab的回调
  109. changeTab(index) {
  110. this.tabIndex = index;
  111. if(this.orderLoad[index].finish){
  112. // 该状态下已加载全部
  113. return false;
  114. }
  115. if(!this.orderList[index]||this.orderList[index].length==0){
  116. // 无数据说明没加载过,第一次加载
  117. // this.orderList[index]=[];
  118. this.orderLoad[index]={
  119. page:1,
  120. loading:false,
  121. finish:false,
  122. }
  123. }
  124. this.getData();
  125. },
  126. // 正常订单
  127. getOrderList(){
  128. // let thisTab = this.orderList[this.tabIndex];
  129. if(this.orderLoad[this.tabIndex].finish){
  130. return false;
  131. }
  132. this.orderLoad[this.tabIndex].loading = true;
  133. this.$u.api.getOrderListAjax({
  134. status:this.tabOps[this.tabIndex].value,
  135. page:this.orderLoad[this.tabIndex].page,
  136. }).then(({code,data})=>{
  137. console.log(code,data);
  138. console.log(this.tabIndex);
  139. this.orderLoad[this.tabIndex].loading = false;
  140. uni.stopPullDownRefresh();
  141. if(code==1){
  142. if(data.last_page<=data.current_page){
  143. this.orderLoad[this.tabIndex].finish = true;
  144. }
  145. if(data.current_page==1){
  146. this.orderList[this.tabIndex] = data.data;
  147. }else{
  148. this.orderList[this.tabIndex]=this.orderList[this.tabIndex].concat(data.data);
  149. }
  150. }else{
  151. this.orderLoad[this.tabIndex].finish = true;
  152. }
  153. this.orderLoad[this.tabIndex].page = data.current_page+1;
  154. this.$forceUpdate();
  155. }).catch(()=>{
  156. uni.stopPullDownRefresh();
  157. this.orderLoad[this.tabIndex].loading = false;
  158. this.orderLoad[this.tabIndex].finish = true;
  159. })
  160. },
  161. }
  162. };
  163. </script>
  164. <style lang="scss" scoped>
  165. .page{
  166. min-height: 100vh;
  167. }
  168. .list {
  169. padding: 0 30rpx 30rpx;
  170. box-sizing: border-box;
  171. width: 100%;
  172. }
  173. .tabbox{
  174. position: fixed;
  175. top: 0;
  176. left: 0;
  177. width: 750rpx;
  178. z-index: $app-zIndex-fixed;
  179. }
  180. .content{
  181. padding-top: 80rpx;
  182. }
  183. </style>