couponList.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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="index2" class="class-card">
  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. if (!this.triggered) {
  95. this.triggered = true
  96. this.tabList[this.current].isOver = false
  97. this.tabList[this.current].pageIndex = 1
  98. this.tabList[this.current].tableList = []
  99. this.getTableList(this.current, 'refresh')
  100. }
  101. },
  102. // 重置下拉刷新状态
  103. onRestore() {
  104. this.triggered = 'restore'
  105. this.triggered = false
  106. },
  107. // 懒加载
  108. handleLoadMore() {
  109. if (!this.tabList[this.current].isOver) {
  110. this.tabList[this.current].pageIndex++
  111. this.getTableList(this.current)
  112. }
  113. },
  114. // 获取列表数据
  115. getTableList(index, refresh) {
  116. NET.request(API.getCouponList, {
  117. status: index,
  118. page: this.tabList[index].pageIndex,
  119. size: 10,
  120. }, 'POST').then(res => {
  121. this.triggered = false
  122. this.tabList[index].tableList = this.tabList[index].tableList.concat(res.data.row)
  123. this.tabList[index].isOver = res.data.row.length != 10
  124. }).catch(error => {
  125. this.triggered = false
  126. this.$refs.uTips.show({
  127. title: error.message,
  128. type: 'warning',
  129. })
  130. })
  131. }
  132. },
  133. }
  134. </script>
  135. <style>
  136. page {
  137. width: 100%;
  138. height: 100%;
  139. background-color: #f7f7f7;
  140. }
  141. </style>
  142. <style lang="scss" scoped>
  143. @import "@/static/css/themes.scss";
  144. .content {
  145. width: 100%;
  146. float: left;
  147. .swiper-box {
  148. height: calc(100vh - 34px);
  149. .swiper-item {
  150. height: calc(100vh - 34px);
  151. .scroll-box {
  152. width: 100%;
  153. height: calc(100vh - 34px);
  154. padding-bottom: 10px;
  155. box-sizing: border-box;
  156. .class-card {
  157. .class-content {
  158. padding: 10px 15px;
  159. display: flex;
  160. align-items: center;
  161. position: relative;
  162. }
  163. .class-info-img {
  164. width: 60px;
  165. height: 60px;
  166. margin-right: 10px;
  167. }
  168. .class-info-content {
  169. flex: 1;
  170. }
  171. .class-info-label {
  172. font-size: 16px;
  173. color: #000000;
  174. word-break: break-all;
  175. margin-bottom: 5px;
  176. }
  177. .class-info-text {
  178. color: #999999;
  179. margin-bottom: 5px;
  180. }
  181. .card-mask {
  182. width: 100%;
  183. height: 100%;
  184. position: absolute;
  185. left: 0;
  186. top: 0;
  187. background-color: rgba(0, 0, 0, 0.3);
  188. }
  189. .out-date {
  190. font-size: 10px;
  191. color: #ff9900;
  192. margin-bottom: 5px;
  193. position: absolute;
  194. right: 8px;
  195. bottom: 3px;
  196. }
  197. }
  198. }
  199. }
  200. }
  201. }
  202. </style>