index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <view class="pages-content">
  3. <view class="tabs">
  4. <u-tabs-swiper ref="uTabs" :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%;">
  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. id: 23432445,
  43. couponTitle: "满100减50",
  44. couponAmount: 100,
  45. validEndTime: "2020-05-16",
  46. remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
  47. checked: false
  48. },
  49. {
  50. id: 3544355,
  51. couponTitle: "满100减50",
  52. couponAmount: 100,
  53. validEndTime: "2020-05-16",
  54. remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
  55. checked: false
  56. },
  57. {
  58. id: 234234234,
  59. couponTitle: "满100减50",
  60. couponAmount: 100,
  61. validEndTime: "2020-05-16",
  62. remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
  63. checked: false
  64. },
  65. {
  66. id: 66264646,
  67. couponTitle: "满100减50",
  68. couponAmount: 100,
  69. validEndTime: "2020-05-16",
  70. remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
  71. checked: false
  72. },
  73. {
  74. id: 9794694698,
  75. couponTitle: "满100减50",
  76. couponAmount: 100,
  77. validEndTime: "2020-05-16",
  78. remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
  79. checked: false
  80. }
  81. ], // 优惠卷列表
  82. // 因为内部的滑动机制限制,请将tabs组件和swiper组件的current用不同变量赋值
  83. current: 0, // tabs组件的current值,表示当前活动的tab选项
  84. swiperCurrent: 0, // swiper组件的current值,表示当前那个swiper-item是活动的
  85. pageNo:1,
  86. pageSize:15,
  87. count:0
  88. };
  89. },
  90. onLoad() {
  91. this.pageInit()
  92. },
  93. methods: {
  94. pageInit () {
  95. this.current = 0 // tabs组件的current值,表示当前活动的tab选项
  96. this.swiperCurrent = 0
  97. this.getList()
  98. },
  99. // tabs通知swiper切换
  100. tabsChange(index) {
  101. this.swiperCurrent = index;
  102. this.getList()
  103. },
  104. // swiper-item左右移动,通知tabs的滑块跟随移动
  105. transition(e) {
  106. let dx = e.detail.dx;
  107. this.$refs.uTabs.setDx(dx);
  108. },
  109. // 由于swiper的内部机制问题,快速切换swiper不会触发dx的连续变化,需要在结束时重置状态
  110. // swiper滑动结束,分别设置tabs和swiper的状态
  111. animationfinish(e) {
  112. let current = e.detail.current;
  113. this.$refs.uTabs.setFinishCurrent(current);
  114. this.swiperCurrent = current;
  115. this.current = current;
  116. this.getList()
  117. },
  118. // 获取优惠卷列表
  119. getList(){
  120. this.status = 'loading'
  121. let item = this.tabsList[this.swiperCurrent]
  122. couponListFind({status:item.status}).then(res=>{
  123. this.status = 'loadmore'
  124. if (res.status == 200) {
  125. this.couponList = res.data
  126. } else {
  127. this.couponList = []
  128. }
  129. })
  130. }
  131. }
  132. };
  133. </script>
  134. <style lang="scss">
  135. page{
  136. height: 100%;
  137. }
  138. .pages-content{
  139. width: 100%;
  140. height: 100%;
  141. display: flex;
  142. flex-direction: column;
  143. uni-swiper{
  144. flex-grow: 1;
  145. }
  146. }
  147. </style>