messageList.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. tableList: [],
  45. }, {
  46. name: '请假',
  47. isOver: false,
  48. pageIndex: 1,
  49. tableList: [],
  50. }, {
  51. name: '续费',
  52. isOver: false,
  53. pageIndex: 1,
  54. tableList: [],
  55. }, {
  56. name: '签到',
  57. isOver: false,
  58. pageIndex: 1,
  59. tableList: [],
  60. }],
  61. current: 0,
  62. swiperCurrent: 0,
  63. }
  64. },
  65. onLoad() {
  66. this.getTableList(0)
  67. this.getTableList(1)
  68. this.getTableList(2)
  69. this.getTableList(3)
  70. },
  71. onReady() {},
  72. methods: {
  73. // tab页面切换
  74. tabsChange(index) {
  75. this.swiperCurrent = index;
  76. },
  77. // swiper-item左右移动,通知tabs的滑块跟随移动
  78. transition(e) {
  79. let dx = e.detail.dx;
  80. this.$refs.uTabs.setDx(dx);
  81. },
  82. // swiper滑动结束,分别设置tabs和swiper的状态
  83. animationfinish(e) {
  84. let current = e.detail.current;
  85. this.$refs.uTabs.setFinishCurrent(current);
  86. this.swiperCurrent = current;
  87. this.current = current;
  88. },
  89. // 下拉刷新
  90. onRefresh() {
  91. this.triggered = true
  92. this.tabList[this.current].isOver = false
  93. this.tabList[this.current].pageIndex = 1
  94. this.tabList[this.current].tableList = []
  95. this.getTableList(this.current, 'refresh')
  96. },
  97. // 重置下拉刷新状态
  98. onRestore() {
  99. this.triggered = 'restore'
  100. this.triggered = false
  101. },
  102. // 懒加载
  103. handleLoadMore() {
  104. if (!this.tabList[this.current].isOver) {
  105. this.tabList[this.current].pageIndex++
  106. this.getTableList(this.current)
  107. }
  108. },
  109. // 获取列表数据
  110. getTableList(index, refresh) {
  111. NET.request(API.getMessageList, {
  112. type: index,
  113. page: this.tabList[index].pageIndex,
  114. size: 10,
  115. }, 'POST').then(res => {
  116. this.triggered = false
  117. this.tabList[index].tableList = this.tabList[index].tableList.concat(res.data.row)
  118. this.tabList[index].isOver = res.data.row.length != 10
  119. }).catch(error => {
  120. this.triggered = false
  121. this.$refs.uTips.show({
  122. title: error.message,
  123. type: 'warning',
  124. })
  125. })
  126. }
  127. },
  128. }
  129. </script>
  130. <style>
  131. page {
  132. width: 100%;
  133. height: 100%;
  134. background-color: #f7f7f7;
  135. }
  136. </style>
  137. <style lang="scss" scoped>
  138. @import "@/static/css/themes.scss";
  139. .content {
  140. width: 100%;
  141. float: left;
  142. /deep/.u-card__head--left__title {
  143. font-weight: bold;
  144. }
  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. .card-box {
  153. .card-content {
  154. .info-text {
  155. margin-bottom: 5px;
  156. font-size: 14px;
  157. }
  158. }
  159. }
  160. }
  161. }
  162. }
  163. }
  164. </style>