index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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% - 40px);" :current="swiperCurrent" @transition="transition" @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="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="total>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:15,
  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.count = 0
  58. this.couponList = []
  59. this.getList()
  60. },
  61. // tabs通知swiper切换
  62. tabsChange(index) {
  63. this.swiperCurrent = index;
  64. this.couponList = []
  65. this.count = 0
  66. },
  67. // swiper-item左右移动,通知tabs的滑块跟随移动
  68. transition(e) {
  69. let dx = e.detail.dx;
  70. this.$refs.uTabs.setDx(dx);
  71. },
  72. // 由于swiper的内部机制问题,快速切换swiper不会触发dx的连续变化,需要在结束时重置状态
  73. // swiper滑动结束,分别设置tabs和swiper的状态
  74. animationfinish(e) {
  75. let current = e.detail.current;
  76. this.$refs.uTabs.setFinishCurrent(current);
  77. this.swiperCurrent = current;
  78. this.current = current;
  79. this.couponList = []
  80. this.count = 0
  81. this.getList()
  82. },
  83. // 获取优惠卷列表
  84. getList(){
  85. this.status = 'loading'
  86. let item = this.tabsList[this.swiperCurrent]
  87. let params = {
  88. pageNo: this.pageNo,
  89. pageSize: this.pageSize,
  90. status: item.status
  91. }
  92. couponListFind(params).then(res=>{
  93. this.status = 'loadmore'
  94. if (res.status == 200) {
  95. let list = res.data.list
  96. this.couponList = this.couponList.concat(list)
  97. this.count = res.data.count
  98. } else {
  99. this.couponList = []
  100. this.count = 0
  101. }
  102. })
  103. },
  104. // scroll-view到底部加载更多
  105. onreachBottom() {
  106. if (this.couponList.length<this.count) {
  107. this.pageNo++
  108. this.getList()
  109. } else {
  110. this.status = "nomore"
  111. }
  112. }
  113. }
  114. };
  115. </script>
  116. <style lang="scss">
  117. page{
  118. height: 100%;
  119. }
  120. .pages-content{
  121. width: 100%;
  122. height: 100%;
  123. display: flex;
  124. flex-direction: column;
  125. uni-swiper{
  126. flex-grow: 1;
  127. }
  128. .u-empty.data-v-6938e513{
  129. height: 90%;
  130. }
  131. }
  132. </style>