index.vue 4.7 KB

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