couponList.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <view class="content">
  3. <u-tabs-swiper ref="uTabs" :active-color="mainColor" :list="tabList" :current="current" @change="tabsChange"
  4. :is-scroll="false"></u-tabs-swiper>
  5. <swiper :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish" class="swiper-box">
  6. <swiper-item class="swiper-item" v-for="(item, index1) in tabList" :key="index1">
  7. <scroll-view scroll-y class="scroll-box" @scrolltolower="handleLoadMore" :refresher-enabled="true"
  8. :refresher-triggered="triggered" :refresher-threshold="100" refresher-background="white" @refresherrefresh="onRefresh"
  9. @refresherrestore="onRestore">
  10. <u-card :show-head="false" :show-foot="false" padding="0px" margin="10px" borderRadius="40" v-for="(site, index2) in item.tableList"
  11. :key="index" class="class-card" @click="goToMyClass(site)">
  12. <view class="class-content" slot="body">
  13. <view class="class-info-img">
  14. <u-image width="60px" height="60px" :src="site.url" shape="circle"></u-image>
  15. </view>
  16. <view class="class-info-content">
  17. <view class="class-info-label">{{site.name}}¥{{site.amount}}</view>
  18. <view class="class-info-text">{{site.typeValue}}&nbsp;&nbsp;{{site.content}}</view>
  19. <view class="class-info-text">{{site.endDate}}&nbsp;&nbsp;到期</view>
  20. </view>
  21. <view class="card-mask" v-if="index1 == 1"></view>
  22. <view class="out-date" v-if="index1 == 2">已用</view>
  23. </view>
  24. </u-card>
  25. <u-divider v-if="item.isOver" bg-color="transparent">没有更多了</u-divider>
  26. </scroll-view>
  27. </swiper-item>
  28. </swiper>
  29. <u-top-tips ref="uTips"></u-top-tips>
  30. </view>
  31. </template>
  32. <script>
  33. import {
  34. mapGetters
  35. } from 'vuex'
  36. const NET = require('@/utils/request')
  37. const API = require('@/config/api')
  38. export default {
  39. computed: {
  40. ...mapGetters([
  41. 'mainColor',
  42. 'handleCustomStyle',
  43. 'handleDefaultCustomStyle',
  44. ])
  45. },
  46. data() {
  47. return {
  48. triggered: false,
  49. tabList: [{
  50. name: '可用',
  51. isOver: false,
  52. pageIndex: 1,
  53. tableList: [],
  54. }, {
  55. name: '过期',
  56. isOver: false,
  57. pageIndex: 1,
  58. tableList: [],
  59. }, {
  60. name: '使用记录',
  61. isOver: false,
  62. pageIndex: 1,
  63. tableList: [],
  64. }],
  65. current: 0,
  66. swiperCurrent: 0,
  67. }
  68. },
  69. onLoad() {
  70. this.getTableList(0)
  71. this.getTableList(1)
  72. this.getTableList(2)
  73. },
  74. onReady() {},
  75. methods: {
  76. // tab页面切换
  77. tabsChange(index) {
  78. this.swiperCurrent = index;
  79. },
  80. // swiper-item左右移动,通知tabs的滑块跟随移动
  81. transition(e) {
  82. let dx = e.detail.dx;
  83. this.$refs.uTabs.setDx(dx);
  84. },
  85. // swiper滑动结束,分别设置tabs和swiper的状态
  86. animationfinish(e) {
  87. let current = e.detail.current;
  88. this.$refs.uTabs.setFinishCurrent(current);
  89. this.swiperCurrent = current;
  90. this.current = current;
  91. },
  92. // 下拉刷新
  93. onRefresh() {
  94. this.triggered = true
  95. this.tabList[this.current].isOver = false
  96. this.tabList[this.current].pageIndex = 1
  97. this.tabList[this.current].tableList = []
  98. this.getTableList(this.current, 'refresh')
  99. },
  100. // 重置下拉刷新状态
  101. onRestore() {
  102. this.triggered = 'restore'
  103. this.triggered = false
  104. },
  105. // 懒加载
  106. handleLoadMore() {
  107. if (!this.tabList[this.current].isOver) {
  108. this.tabList[this.current].pageIndex++
  109. this.getTableList(this.current)
  110. }
  111. },
  112. // 获取列表数据
  113. getTableList(index, refresh) {
  114. NET.request(API.getCouponList, {
  115. status: index,
  116. page: this.tabList[index].pageIndex,
  117. size: 10,
  118. }, 'POST').then(res => {
  119. this.triggered = false
  120. this.tabList[index].tableList = this.tabList[index].tableList.concat(res.data.list)
  121. this.tabList[index].isOver = res.data.list.length != 10
  122. }).catch(error => {
  123. this.triggered = false
  124. this.$refs.uTips.show({
  125. title: error.data.msg,
  126. type: 'warning',
  127. })
  128. })
  129. }
  130. },
  131. }
  132. </script>
  133. <style>
  134. page {
  135. width: 100%;
  136. height: 100%;
  137. background-color: #f7f7f7;
  138. }
  139. </style>
  140. <style lang="scss" scoped>
  141. @import "@/static/css/themes.scss";
  142. .content {
  143. width: 100%;
  144. float: left;
  145. .swiper-box {
  146. height: calc(100vh - 34px);
  147. .swiper-item {
  148. height: calc(100vh - 34px);
  149. .scroll-box {
  150. width: 100%;
  151. height: calc(100vh - 34px);
  152. .class-card {
  153. .class-content {
  154. padding: 10px 15px;
  155. display: flex;
  156. align-items: center;
  157. position: relative;
  158. }
  159. .class-info-img {
  160. width: 60px;
  161. height: 60px;
  162. margin-right: 10px;
  163. }
  164. .class-info-content {
  165. flex: 1;
  166. }
  167. .class-info-label {
  168. font-size: 16px;
  169. color: #000000;
  170. word-break: break-all;
  171. }
  172. .class-info-text {
  173. color: #999999;
  174. margin-bottom: 5px;
  175. }
  176. .card-mask {
  177. width: 100%;
  178. height: 100%;
  179. position: absolute;
  180. left: 0;
  181. top: 0;
  182. background-color: rgba(0, 0, 0, 0.3);
  183. }
  184. .out-date {
  185. font-size: 10px;
  186. color: #ff9900;
  187. margin-bottom: 5px;
  188. position: absolute;
  189. right: 8px;
  190. bottom: 3px;
  191. }
  192. }
  193. }
  194. }
  195. }
  196. }
  197. </style>