messageList.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 :title="site.name" :sub-title="site.time" :show-foot="false" border-radius="30" v-for="(site, index2) in item.tableList"
  11. :key="index2" class="card-box">
  12. <view class="card-content" slot="body">
  13. <view class="info-text">{{site.content}}</view>
  14. </view>
  15. </u-card>
  16. <u-divider v-if="item.isOver" bg-color="transparent" :style="{paddingTop : item.tableList.length == 0 ? '10px' : ''}">没有更多了</u-divider>
  17. </scroll-view>
  18. </swiper-item>
  19. </swiper>
  20. <u-top-tips ref="uTips"></u-top-tips>
  21. </view>
  22. </template>
  23. <script>
  24. import {
  25. mapGetters
  26. } from 'vuex'
  27. const NET = require('@/utils/request')
  28. const API = require('@/config/api')
  29. export default {
  30. computed: {
  31. ...mapGetters([
  32. 'mainColor',
  33. 'handleCustomStyle',
  34. 'handleDefaultCustomStyle',
  35. ])
  36. },
  37. data() {
  38. return {
  39. triggered: false,
  40. tabList: [{
  41. name: '全部',
  42. isOver: false,
  43. pageIndex: 1,
  44. type: 2,
  45. tableList: [],
  46. }, {
  47. name: '办卡',
  48. isOver: false,
  49. pageIndex: 1,
  50. type: 0,
  51. tableList: [],
  52. }, {
  53. name: '续费',
  54. isOver: false,
  55. pageIndex: 1,
  56. type: 1,
  57. tableList: [],
  58. }],
  59. current: 0,
  60. swiperCurrent: 0,
  61. }
  62. },
  63. onLoad() {
  64. this.getTableList(0)
  65. this.getTableList(1)
  66. this.getTableList(2)
  67. },
  68. onReady() {},
  69. methods: {
  70. // tab页面切换
  71. tabsChange(index) {
  72. this.swiperCurrent = index;
  73. },
  74. // swiper-item左右移动,通知tabs的滑块跟随移动
  75. transition(e) {
  76. let dx = e.detail.dx;
  77. this.$refs.uTabs.setDx(dx);
  78. },
  79. // swiper滑动结束,分别设置tabs和swiper的状态
  80. animationfinish(e) {
  81. let current = e.detail.current;
  82. this.$refs.uTabs.setFinishCurrent(current);
  83. this.swiperCurrent = current;
  84. this.current = current;
  85. },
  86. // 下拉刷新
  87. onRefresh() {
  88. if (!this.triggered) {
  89. this.triggered = true
  90. this.tabList[this.current].isOver = false
  91. this.tabList[this.current].pageIndex = 1
  92. this.tabList[this.current].tableList = []
  93. this.getTableList(this.current, 'refresh')
  94. }
  95. },
  96. // 重置下拉刷新状态
  97. onRestore() {
  98. this.triggered = 'restore'
  99. this.triggered = false
  100. },
  101. // 懒加载
  102. handleLoadMore() {
  103. if (!this.tabList[this.current].isOver) {
  104. this.tabList[this.current].pageIndex++
  105. this.getTableList(this.current)
  106. }
  107. },
  108. // 获取列表数据
  109. getTableList(index, refresh) {
  110. NET.request(API.getMessageList, {
  111. type: this.tabList[index].type,
  112. page: this.tabList[index].pageIndex,
  113. size: 10,
  114. }, 'POST').then(res => {
  115. this.triggered = false
  116. this.tabList[index].tableList = this.tabList[index].tableList.concat(res.data.row)
  117. this.tabList[index].isOver = res.data.row.length != 10
  118. }).catch(error => {
  119. this.triggered = false
  120. this.$refs.uTips.show({
  121. title: error.message,
  122. type: 'warning',
  123. })
  124. })
  125. }
  126. },
  127. }
  128. </script>
  129. <style>
  130. page {
  131. width: 100%;
  132. height: 100%;
  133. background-color: #f7f7f7;
  134. }
  135. </style>
  136. <style lang="scss" scoped>
  137. @import "@/static/css/themes.scss";
  138. .content {
  139. width: 100%;
  140. float: left;
  141. /deep/.u-card__head--left__title {
  142. font-weight: bold;
  143. }
  144. .swiper-box {
  145. height: calc(100vh - 34px);
  146. .swiper-item {
  147. height: calc(100vh - 34px);
  148. .scroll-box {
  149. width: 100%;
  150. height: calc(100vh - 34px);
  151. .card-box {
  152. .card-content {
  153. .info-text {
  154. margin-bottom: 5px;
  155. font-size: 14px;
  156. }
  157. }
  158. }
  159. }
  160. }
  161. }
  162. }
  163. </style>