classList.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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="card-box" @click="goToClassDetail(site)">
  12. <view class="card-content" slot="head" style="padding-top: 10px;">
  13. <view class="card-name">{{site.name}}</view>
  14. </view>
  15. <view class="card-content" slot="body">
  16. <view class="card-info-text">
  17. <u-icon name="clock"></u-icon>
  18. {{site.classStartDate}}&nbsp;&nbsp;{{site.classStartHours}}
  19. </view>
  20. <view class="card-info-text">
  21. <u-icon name="map"></u-icon>
  22. {{site.address}}
  23. </view>
  24. </view>
  25. </u-card>
  26. <u-divider v-if="item.isOver" bg-color="transparent">没有更多了</u-divider>
  27. </scroll-view>
  28. </swiper-item>
  29. </swiper>
  30. <u-icon name="plus-circle-fill" :color="mainColor" size="96" class="fix-add-icon" @click="goToAddClassForm()"></u-icon>
  31. <u-top-tips ref="uTips"></u-top-tips>
  32. </view>
  33. </template>
  34. <script>
  35. import {
  36. mapGetters
  37. } from 'vuex'
  38. const NET = require('@/utils/request')
  39. const API = require('@/config/api')
  40. export default {
  41. computed: {
  42. ...mapGetters([
  43. 'mainColor',
  44. ])
  45. },
  46. data() {
  47. return {
  48. triggered: false,
  49. tabList: [{
  50. name: '全部',
  51. status: 3,
  52. isOver: false,
  53. pageIndex: 1,
  54. tableList: [],
  55. }, {
  56. name: '已开班',
  57. status: 1,
  58. isOver: false,
  59. pageIndex: 1,
  60. tableList: [],
  61. }, {
  62. name: '未开班',
  63. status: 0,
  64. isOver: false,
  65. pageIndex: 1,
  66. tableList: [],
  67. }, {
  68. name: '审核中',
  69. status: 2,
  70. isOver: false,
  71. pageIndex: 1,
  72. tableList: [],
  73. }],
  74. current: 0,
  75. swiperCurrent: 0,
  76. }
  77. },
  78. onShow() {
  79. this.tabList.forEach((site, index) => {
  80. site.isOver = false
  81. site.pageIndex = 1
  82. site.tableList = []
  83. this.getTableList(index)
  84. })
  85. },
  86. methods: {
  87. // tab页面切换
  88. tabsChange(index) {
  89. this.swiperCurrent = index;
  90. },
  91. // swiper-item左右移动,通知tabs的滑块跟随移动
  92. transition(e) {
  93. let dx = e.detail.dx;
  94. this.$refs.uTabs.setDx(dx);
  95. },
  96. // swiper滑动结束,分别设置tabs和swiper的状态
  97. animationfinish(e) {
  98. let current = e.detail.current;
  99. this.$refs.uTabs.setFinishCurrent(current);
  100. this.swiperCurrent = current;
  101. this.current = current;
  102. },
  103. // 下拉刷新
  104. onRefresh() {
  105. if (!this.triggered) {
  106. this.triggered = true
  107. this.tabList[this.current].isOver = false
  108. this.tabList[this.current].pageIndex = 1
  109. this.tabList[this.current].tableList = []
  110. this.getTableList(this.current, 'refresh')
  111. }
  112. },
  113. // 重置下拉刷新状态
  114. onRestore() {
  115. this.triggered = 'restore'
  116. this.triggered = false
  117. },
  118. // 懒加载
  119. handleLoadMore() {
  120. if (!this.tabList[this.current].isOver) {
  121. this.tabList[this.current].pageIndex++
  122. this.getTableList(this.current)
  123. }
  124. },
  125. // 获取列表数据
  126. getTableList(index, refresh) {
  127. NET.request(API.getClassList, {
  128. status: this.tabList[index].status,
  129. page: this.tabList[index].pageIndex,
  130. size: 10,
  131. }, 'POST').then(res => {
  132. this.triggered = false
  133. this.tabList[index].tableList = this.tabList[index].tableList.concat(res.data.row)
  134. this.tabList[index].isOver = res.data.row.length != 10
  135. }).catch(error => {
  136. this.triggered = false
  137. this.$refs.uTips.show({
  138. title: error.message,
  139. type: 'warning',
  140. })
  141. })
  142. },
  143. // 跳转新增班级表单
  144. goToAddClassForm() {
  145. uni.navigateTo({
  146. url: '/pagesClass/addClassForm'
  147. });
  148. },
  149. // 跳转班级详情
  150. goToClassDetail(site) {
  151. uni.navigateTo({
  152. url: '/pagesClass/classDetail?id=' + site.id
  153. });
  154. }
  155. },
  156. }
  157. </script>
  158. <style>
  159. page {
  160. width: 100%;
  161. height: 100%;
  162. background-color: #f7f7f7;
  163. }
  164. </style>
  165. <style lang="scss" scoped>
  166. @import "@/static/css/themes.scss";
  167. .content {
  168. width: 100%;
  169. float: left;
  170. position: relative;
  171. .swiper-box {
  172. height: calc(100vh - 34px);
  173. .swiper-item {
  174. height: calc(100vh - 34px);
  175. .scroll-box {
  176. width: 100%;
  177. height: calc(100vh - 34px);
  178. .card-box {
  179. .card-content {
  180. padding: 5px 15px;
  181. }
  182. .card-name {
  183. height: 20px;
  184. display: inline-block;
  185. font-weight: bold;
  186. font-size: 14px;
  187. line-height: 20px;
  188. }
  189. .card-info-text {
  190. color: #999999;
  191. margin-bottom: 5px;
  192. /deep/.u-icon {
  193. margin-right: 5px;
  194. font-size: 14px;
  195. color: #000000;
  196. }
  197. }
  198. }
  199. }
  200. }
  201. }
  202. .fix-add-icon {
  203. position: fixed;
  204. bottom: 15px;
  205. right: 15px;
  206. }
  207. }
  208. </style>