index.vue 3.6 KB

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