index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <view class="pages-content">
  3. <view class="tabs">
  4. <u-tabs-swiper ref="uTabs" active-color="red" :list="tabsList" bar-width="100" :current="current" @change="tabsChange" :is-scroll="false"
  5. swiperWidth="750"></u-tabs-swiper>
  6. </view>
  7. <swiper style="height: calc(100% - 50px);" :current="swiperCurrent" @transition="transition" @change="swiperChange" @animationfinish="animationfinish">
  8. <swiper-item class="swiper-item" v-for="(item, index) in tabsList" :key="index">
  9. <scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="onreachBottom">
  10. <couponTpl :list="index==current?couponList:[]"></couponTpl>
  11. <u-empty :text="noDataText" img-width="120" v-if="couponList.length==0 && status!='loading'" mode="list"></u-empty>
  12. <view style="padding: 20upx;">
  13. <u-loadmore v-if="count>pageSize || status=='loading'" :status="status" />
  14. </view>
  15. </scroll-view>
  16. </swiper-item>
  17. </swiper>
  18. </view>
  19. </template>
  20. <script>
  21. import couponTpl from '@/pages/coupon/couponTpl.vue'
  22. import {couponListFind} from '@/api/coupon.js'
  23. export default {
  24. components: {
  25. couponTpl
  26. },
  27. data() {
  28. return {
  29. noDataText: '暂无数据',
  30. status: 'loading',
  31. tabsList: [{
  32. name: '未使用',
  33. status: 0
  34. }, {
  35. name: '已使用',
  36. status: 1
  37. }, {
  38. name: '已过期',
  39. status: -1
  40. }],
  41. couponList: [], // 优惠卷列表
  42. // 因为内部的滑动机制限制,请将tabs组件和swiper组件的current用不同变量赋值
  43. current: 0, // tabs组件的current值,表示当前活动的tab选项
  44. swiperCurrent: 0, // swiper组件的current值,表示当前那个swiper-item是活动的
  45. pageNo:1,
  46. pageSize:10,
  47. count:0
  48. };
  49. },
  50. onLoad() {
  51. this.pageInit()
  52. },
  53. methods: {
  54. pageInit () {
  55. this.current = 0 // tabs组件的current值,表示当前活动的tab选项
  56. this.swiperCurrent = 0
  57. this.couponList = []
  58. this.pageNo = 1
  59. this.status = 'loading'
  60. this.getList()
  61. },
  62. // tabs通知swiper切换
  63. tabsChange(index) {
  64. this.swiperCurrent = index;
  65. },
  66. // swiper-item左右移动,通知tabs的滑块跟随移动
  67. transition(e) {
  68. let dx = e.detail.dx;
  69. this.$refs.uTabs.setDx(dx);
  70. },
  71. swiperChange(event){
  72. console.log(event.detail)
  73. this.couponList = []
  74. this.status = 'loading'
  75. },
  76. // 由于swiper的内部机制问题,快速切换swiper不会触发dx的连续变化,需要在结束时重置状态
  77. // swiper滑动结束,分别设置tabs和swiper的状态
  78. animationfinish(e) {
  79. let current = e.detail.current;
  80. if (current != this.current) {
  81. this.$refs.uTabs.setFinishCurrent(current);
  82. this.swiperCurrent = current;
  83. this.current = current;
  84. this.getList()
  85. }
  86. },
  87. // 获取优惠卷列表
  88. getList(num){
  89. if(num) {
  90. this.pageNo = num
  91. }
  92. let item = this.tabsList[this.swiperCurrent]
  93. let params = {
  94. pageNo: this.pageNo,
  95. pageSize: this.pageSize,
  96. status: item.status
  97. }
  98. couponListFind(params).then(res=>{
  99. this.status = 'loadmore'
  100. if (res.status == 200) {
  101. let list = res.data.list
  102. this.couponList = this.couponList.concat(list)
  103. this.count = res.data.count
  104. } else {
  105. this.couponList = []
  106. this.count = 0
  107. }
  108. })
  109. },
  110. // scroll-view到底部加载更多
  111. onreachBottom() {
  112. if (this.couponList.length<this.count) {
  113. this.pageNo++
  114. this.getList()
  115. } else {
  116. this.status = "nomore"
  117. }
  118. }
  119. }
  120. };
  121. </script>
  122. <style lang="scss">
  123. page{
  124. height: 100%;
  125. }
  126. .pages-content{
  127. width: 100%;
  128. height: 100%;
  129. display: flex;
  130. flex-direction: column;
  131. uni-swiper{
  132. flex-grow: 1;
  133. }
  134. .u-empty{
  135. height: auto!important;
  136. }
  137. }
  138. </style>