classList.vue 5.6 KB

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