extraLessonsStudentList.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <view class="content">
  3. <view class="filter-box">
  4. <u-search placeholder="请输入关键字" v-model="filterText" @search="setFilterText" @custom="setFilterText"></u-search>
  5. </view>
  6. <scroll-view scroll-y class="scroll-box" @scrolltolower="handleLoadMore"
  7. :refresher-triggered="triggered" :refresher-threshold="100" refresher-background="white"
  8. @refresherrestore="onRestore">
  9. <u-checkbox-group :active-color="mainColor" shape="circle" size="56" icon-size="36">
  10. <u-card :head-border-bottom="false" :foot-border-top="false" padding="0px" margin="0" borderRadius="0" v-for="(item, index) in tableList"
  11. :key="index" class="card-box" @click="changeStatus(item)">
  12. <view class="card-content" slot="body">
  13. <view class="card-info-img">
  14. <u-avatar :src="item.url" size="100"></u-avatar>
  15. </view>
  16. <view class="card-info-text">{{item.name}}</view>
  17. <u-checkbox v-model="item.checked" @click.native="changeStatus(item)"></u-checkbox>
  18. </view>
  19. </u-card>
  20. </u-checkbox-group>
  21. <u-divider v-if="isOver" bg-color="transparent">没有更多了</u-divider>
  22. </scroll-view>
  23. <view class="handle-fix-box">
  24. <u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" @click="selectStudent()">确定</u-button>
  25. </view>
  26. <u-top-tips ref="uTips"></u-top-tips>
  27. </view>
  28. </template>
  29. <script>
  30. import {
  31. mapGetters
  32. } from 'vuex'
  33. const NET = require('@/utils/request')
  34. const API = require('@/config/api')
  35. export default {
  36. computed: {
  37. ...mapGetters([
  38. 'mainColor',
  39. 'customStyle',
  40. ])
  41. },
  42. data() {
  43. return {
  44. filterText: '',
  45. triggered: false,
  46. isOver: false,
  47. pageIndex: 1,
  48. tableList: [],
  49. checkedList: uni.getStorageSync('extraLessonsUserList').length ? uni.getStorageSync('extraLessonsUserList') : []
  50. }
  51. },
  52. onLoad() {
  53. this.getTableList()
  54. },
  55. onReady() {},
  56. methods: {
  57. // 设置过滤字段
  58. setFilterText(value) {
  59. this.onRefresh()
  60. },
  61. // 下拉刷新
  62. onRefresh() {
  63. this.triggered = true
  64. this.isOver = false
  65. this.pageIndex = 1
  66. this.tableList = []
  67. this.getTableList()
  68. },
  69. // 重置下拉刷新状态
  70. onRestore() {
  71. this.triggered = 'restore'
  72. this.triggered = false
  73. },
  74. // 懒加载
  75. handleLoadMore() {
  76. if (!this.isOver) {
  77. this.pageIndex++
  78. this.getTableList()
  79. }
  80. },
  81. // 获取列表数据
  82. getTableList() {
  83. NET.request(API.getExtraLessonsStudentList, {
  84. name: this.filterText,
  85. page: this.pageIndex,
  86. size: 10,
  87. }, 'POST').then(res => {
  88. this.triggered = false
  89. res.data.row.forEach(site => site.checked = false)
  90. this.tableList = this.tableList.concat(res.data.row)
  91. this.isOver = res.data.row.length != 10
  92. this.tableList.forEach(
  93. item=>{
  94. if(this.checkedList.filter(checkedItem=>checkedItem.id==item.id).length!=0){
  95. item.checked = true
  96. }
  97. }
  98. )
  99. }).catch(error => {
  100. this.triggered = false
  101. this.$refs.uTips.show({
  102. title: error.message,
  103. type: 'warning',
  104. })
  105. })
  106. },
  107. // 变更状态
  108. changeStatus(item) {
  109. item.checked = !item.checked
  110. if(item.checked){
  111. if(this.checkedList.filter(checkedItem=>checkedItem.id==item.id).length==0){
  112. this.checkedList.push(
  113. {
  114. id: item.id,
  115. name: item.name,
  116. url: item.url,
  117. hasHead: item.hasUrl,
  118. checked: false,
  119. }
  120. )
  121. }
  122. }else{
  123. this.checkedList = this.checkedList.filter(checkedItem=>checkedItem.id!=item.id)
  124. }
  125. },
  126. // 选择学员
  127. selectStudent() {
  128. const data = this.tableList.filter(site => site.checked).map(site => {
  129. return {
  130. id: site.id,
  131. name: site.name,
  132. url: site.url,
  133. hasHead: site.hasUrl,
  134. checked: false,
  135. }
  136. })
  137. data.forEach(
  138. item=>{
  139. if(this.checkedList.filter(checkedItem=>checkedItem.id==item.id).length==0){
  140. this.checkedList.push(item)
  141. }
  142. }
  143. )
  144. uni.setStorage({
  145. key: 'extraLessonsUserList',
  146. data: this.checkedList
  147. })
  148. uni.navigateBack()
  149. }
  150. },
  151. }
  152. </script>
  153. <style>
  154. page {
  155. width: 100%;
  156. height: 100%;
  157. background-color: #f7f7f7;
  158. }
  159. </style>
  160. <style lang="scss" scoped>
  161. @import "@/static/css/themes.scss";
  162. .content {
  163. width: 100%;
  164. float: left;
  165. .filter-box {
  166. height: 48px;
  167. padding: 10px 15px;
  168. background-color: #FFFFFF;
  169. }
  170. .scroll-box {
  171. width: 100%;
  172. height: calc(100vh - 108px);
  173. .card-box {
  174. border-bottom: 1px solid #cccccc;
  175. .card-content {
  176. padding: 5px 15px;
  177. display: flex;
  178. align-items: center;
  179. .card-info-img {
  180. width: 50px;
  181. height: 50px;
  182. margin-right: 5px;
  183. display: flex;
  184. align-items: center;
  185. justify-content: center;
  186. }
  187. .card-info-text {
  188. line-height: 20px;
  189. font-size: 14px;
  190. flex: 1;
  191. }
  192. }
  193. }
  194. }
  195. }
  196. </style>