studentManage.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <view class="container" :style="showEdit ? 'padding-bottom:180rpx' : ''">
  3. <!-- 背景图片区域 -->
  4. <img class="img_bg" src="../../static/images/center-bg.png" />
  5. <!-- input组件区域 -->
  6. <HeaderInput placeholder="请输入学生姓名或时间组名称" @changeInputValue="changeInputValue" />
  7. <!-- 学校年级班级区域 -->
  8. <view class="school" v-if="list.length">
  9. <view class="">{{ classInfo }}</view>
  10. <!-- 批量按钮区域 -->
  11. <view v-if="!showEdit" class="school_edit" @click="handleEdit">
  12. <img class="img" src="@/static/images/edit.png" />
  13. 批量
  14. </view>
  15. <!-- 全选按钮区域 -->
  16. <view v-else class="school_btn">
  17. <view class="cancel" @click="handleCancel">取消</view>
  18. <radio color="#0061FF" style="transform: scale(0.7)" :checked="allChecked" @click="handleAllCheck" />
  19. <view class="all">全选</view>
  20. </view>
  21. </view>
  22. <!-- 学生列表区域 -->
  23. <view class="list_box" v-if="list.length">
  24. <!-- 每一个学生区域 -->
  25. <view class="item_box" v-for="(item, index) in list" :key="index" @click="handleClickItem(item)">
  26. <view class="box_name">{{ item.name }}({{ item.cardNo }})</view>
  27. <view class="box_time">{{ item.timeGroup }}</view>
  28. <radio v-if="showEdit" color="#0061FF" style="transform: scale(0.7)" :checked="item.isChecked" />
  29. </view>
  30. </view>
  31. <!-- 关联时间组按钮区域 -->
  32. <view class="btn" v-if="showEdit">
  33. <view class="btn_box" @click="handleBind">
  34. <uni-icons color="#fff" type="link" size="28"></uni-icons>
  35. <text class="text">关联时间组</text>
  36. </view>
  37. </view>
  38. <!-- 没有数据时展示的页面 -->
  39. <NoData v-if="!list.length" style="margin-top: 140rpx" />
  40. </view>
  41. </template>
  42. <script setup>
  43. import { ref } from 'vue'
  44. import { onLoad } from '@dcloudio/uni-app'
  45. import HeaderInput from '@/components/headerInput.vue'
  46. import NoData from '@/components/noData.vue'
  47. import { myRequest } from '@/utils/api.js'
  48. import { decryptDes } from '@/utils/des.js'
  49. // 当前所处班级
  50. const classInfo = ref()
  51. // 搜索框绑定数据
  52. const keyWord = ref('')
  53. // 学生列表数据
  54. const list = ref([])
  55. // 缓存数据
  56. const copyList = ref([])
  57. // 是否显示全选radio
  58. const showEdit = ref(false)
  59. // 是否全选
  60. const allChecked = ref(false)
  61. onLoad(() => {
  62. getData()
  63. })
  64. // 获取学生列表数据
  65. const getData = async () => {
  66. const res = await myRequest({
  67. url: '/wanzai/api/smartUser/queryClassUser',
  68. data: {
  69. userId: uni.getStorageSync('userInfo').id,
  70. keyWord: keyWord.value
  71. }
  72. })
  73. // console.log(res)
  74. const result = JSON.parse(decryptDes(res.data))
  75. // console.log(result)
  76. list.value = result.userDetails
  77. list.value.forEach((ele) => {
  78. ele.isChecked = false
  79. })
  80. classInfo.value = result.name
  81. uni.setNavigationBarTitle({
  82. title: result.name
  83. })
  84. }
  85. // 点击批量按钮回调
  86. const handleEdit = () => {
  87. showEdit.value = true
  88. copyList.value = JSON.parse(JSON.stringify(list.value))
  89. }
  90. // 点击取消按钮回调
  91. const handleCancel = () => {
  92. showEdit.value = false
  93. allChecked.value = false
  94. list.value = copyList.value
  95. }
  96. // 点击全选按钮回调
  97. const handleAllCheck = () => {
  98. if (!allChecked.value) {
  99. list.value.forEach((ele) => {
  100. ele.isChecked = true
  101. })
  102. } else {
  103. list.value.forEach((ele) => {
  104. ele.isChecked = false
  105. })
  106. }
  107. allChecked.value = !allChecked.value
  108. }
  109. // 点击每一个学生时的回调
  110. const handleClickItem = (item) => {
  111. if (showEdit.value) {
  112. item.isChecked = !item.isChecked
  113. // 判断全选按钮的状态
  114. allChecked.value = list.value.every((ele) => ele.isChecked)
  115. }
  116. }
  117. // 点击关联时间组按钮回调
  118. const handleBind = () => {
  119. // 判断是否选择了学生
  120. const flag = list.value.find((ele) => ele.isChecked)
  121. if (!flag) {
  122. uni.showToast({
  123. title: '请至少选择一名学生',
  124. icon: 'none',
  125. mask: true
  126. })
  127. } else {
  128. let arr = []
  129. list.value.forEach((ele) => {
  130. if (ele.isChecked) {
  131. arr.push(ele.id)
  132. }
  133. })
  134. uni.navigateTo({
  135. url: `/pages/timeGroup/timeGroup?ids=${JSON.stringify(arr)}`
  136. })
  137. }
  138. }
  139. // 输入框组件自定义事件
  140. const changeInputValue = (value) => {
  141. keyWord.value = value
  142. getData()
  143. }
  144. </script>
  145. <style lang="scss" scoped>
  146. .container {
  147. display: flex;
  148. flex-direction: column;
  149. padding: 0 20rpx;
  150. min-height: 100vh;
  151. background-color: #f1f6fe;
  152. // 背景图片区域样式
  153. .img_bg {
  154. position: absolute;
  155. top: -70rpx;
  156. right: 0;
  157. width: 589rpx;
  158. height: 320rpx;
  159. pointer-events: none;
  160. }
  161. // 学校名称区域样式
  162. .school {
  163. display: flex;
  164. justify-content: space-between;
  165. align-items: center;
  166. margin-top: 38rpx;
  167. color: #808080;
  168. font-size: 28rpx;
  169. .school_edit {
  170. display: flex;
  171. align-items: center;
  172. margin-right: 30rpx;
  173. color: #0061ff;
  174. .img {
  175. margin-right: 10rpx;
  176. width: 30rpx;
  177. height: 30rpx;
  178. }
  179. }
  180. .school_btn {
  181. display: flex;
  182. align-items: center;
  183. .cancel {
  184. margin-right: 20rpx;
  185. color: #d43030;
  186. }
  187. .all {
  188. margin-left: -10rpx;
  189. }
  190. }
  191. }
  192. .list_box {
  193. padding: 0 30rpx 30rpx;
  194. margin-top: 22rpx;
  195. background-color: #fff;
  196. .item_box {
  197. display: flex;
  198. justify-content: space-between;
  199. align-items: center;
  200. height: 103rpx;
  201. font-size: 24rpx;
  202. border-bottom: 1rpx solid #e6e6e6;
  203. .box_name {
  204. }
  205. .box_time {
  206. }
  207. }
  208. }
  209. .btn {
  210. position: fixed;
  211. bottom: 0;
  212. padding: 0 30rpx 30rpx;
  213. background-color: #fff;
  214. .btn_box {
  215. display: flex;
  216. justify-content: center;
  217. align-items: center;
  218. margin-top: 28rpx;
  219. width: 650rpx;
  220. height: 100rpx;
  221. color: #fff;
  222. font-size: 32rpx;
  223. border-radius: 8rpx;
  224. background-color: #0061ff;
  225. .text {
  226. margin-left: 10rpx;
  227. }
  228. }
  229. }
  230. }
  231. </style>