studentManage.vue 5.4 KB

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