index.vue 3.7 KB

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