signStudentList.vue 4.8 KB

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