signStudentList.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. venueId:'',
  45. filterText: '',
  46. triggered: false,
  47. isOver: false,
  48. pageIndex: 1,
  49. tableList: [],
  50. checkedList: uni.getStorageSync('signUserList').length ? uni.getStorageSync('signUserList') : []
  51. }
  52. },
  53. onLoad(options) {
  54. this.venueId = options.venueId
  55. this.getTableList()
  56. },
  57. onReady() {
  58. },
  59. methods: {
  60. // 设置过滤字段
  61. setFilterText(value) {
  62. this.onRestore()
  63. this.onRefresh()
  64. },
  65. // 下拉刷新
  66. onRefresh() {
  67. this.triggered = true
  68. this.isOver = false
  69. this.pageIndex = 1
  70. this.tableList = []
  71. this.getTableList()
  72. },
  73. // 重置下拉刷新状态
  74. onRestore() {
  75. this.triggered = 'restore'
  76. this.triggered = false
  77. },
  78. // 懒加载
  79. handleLoadMore() {
  80. if (!this.isOver) {
  81. this.pageIndex++
  82. this.getTableList()
  83. }
  84. },
  85. // 获取列表数据
  86. getTableList() {
  87. NET.request(API.getOtherSignStudentList, {
  88. name: this.filterText,
  89. page: this.pageIndex,
  90. size: 10,
  91. venueId: this.venueId,
  92. }, 'POST').then(res => {
  93. this.triggered = false
  94. res.data.row.forEach(site => site.checked = false)
  95. this.tableList = this.tableList.concat(res.data.row)
  96. this.isOver = res.data.row.length != 10
  97. this.tableList.forEach(
  98. item=>{
  99. if(this.checkedList.filter(checkedItem=>checkedItem.id==item.id).length!=0){
  100. item.checked = true
  101. }
  102. }
  103. )
  104. }).catch(error => {
  105. this.triggered = false
  106. this.$refs.uTips.show({
  107. title: error.message,
  108. type: 'warning',
  109. })
  110. })
  111. },
  112. // 变更状态
  113. changeStatus(item) {
  114. item.checked = !item.checked
  115. if(item.checked){
  116. if(this.checkedList.filter(checkedItem=>checkedItem.id==item.id).length==0){
  117. this.checkedList.push(
  118. {
  119. id: item.id,
  120. name: item.name,
  121. url: item.url,
  122. hasHead: item.hasUrl,
  123. checked: false,
  124. }
  125. )
  126. }
  127. }else{
  128. this.checkedList = this.checkedList.filter(checkedItem=>checkedItem.id!=item.id)
  129. }
  130. },
  131. // 选择学员
  132. selectStudent() {
  133. const data = this.tableList.filter(site => site.checked).map(site => {
  134. return {
  135. id: site.id,
  136. name: site.name,
  137. url: site.url,
  138. hasHead: site.hasUrl,
  139. checked: false,
  140. }
  141. })
  142. data.forEach(
  143. item=>{
  144. if(this.checkedList.filter(checkedItem=>checkedItem.id==item.id).length==0){
  145. this.checkedList.push(item)
  146. }
  147. }
  148. )
  149. uni.setStorage({
  150. key: 'signUserList',
  151. data: this.checkedList
  152. })
  153. uni.navigateBack()
  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. .filter-box {
  171. height: 48px;
  172. padding: 10px 15px;
  173. background-color: #FFFFFF;
  174. }
  175. .scroll-box {
  176. width: 100%;
  177. height: calc(100vh - 108px);
  178. .card-box {
  179. border-bottom: 1px solid #cccccc;
  180. .card-content {
  181. padding: 5px 15px;
  182. display: flex;
  183. align-items: center;
  184. .card-info-img {
  185. width: 50px;
  186. height: 50px;
  187. margin-right: 5px;
  188. display: flex;
  189. align-items: center;
  190. justify-content: center;
  191. }
  192. .card-info-text {
  193. line-height: 20px;
  194. font-size: 14px;
  195. flex: 1;
  196. }
  197. }
  198. }
  199. }
  200. }
  201. </style>