addStudent.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <view class="container">
  3. <!-- 背景图片区域 -->
  4. <img class="img_bg" src="../../static/images/center-bg.png" />
  5. <!-- 输入框和添加按钮区域 -->
  6. <view class="header">
  7. <view class="header_input">
  8. <uni-icons type="search" size="28" color="#808080" @click="changeInputValue"></uni-icons>
  9. <input v-model="keyWord" class="input" type="text" placeholder="请输入学生姓名" />
  10. </view>
  11. <view class="header_add" @click="goAddPage">
  12. <uni-icons type="plus" size="28" color="#0061FF"></uni-icons>
  13. </view>
  14. </view>
  15. <!-- 全选按钮区域 -->
  16. <view class="all" v-if="dataList.length">
  17. <view class="all_text" @click="handleAllCheck">
  18. <radio color="#0061FF" style="transform: scale(0.7)" :checked="allChecked" />
  19. 全选
  20. </view>
  21. <view class="cancel" @click="handleCancel">
  22. <uni-icons type="closeempty" size="17" color="#00BAAD"></uni-icons>
  23. &nbsp;取消全选
  24. </view>
  25. </view>
  26. <!-- 学生列表区域 -->
  27. <view class="list" v-if="dataList.length">
  28. <!-- 每一个学生区域 -->
  29. <view class="list_item" v-for="item in dataList" :key="item.id" @click="handleClickItem(item)">
  30. <radio color="#0061FF" style="transform: scale(0.7)" :checked="item.isChecked" />
  31. <view class="item_info">
  32. <image v-if="item.headImage" class="info_img" :src="item.headImage" mode="aspectFill"></image>
  33. <image v-else class="info_img" src="/static/images/header.png" mode="aspectFill"></image>
  34. <view class="info_msg">
  35. <view class="msg_name">{{ item.name }}</view>
  36. <view>{{ item.cardNo }}</view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. <!-- 确认按钮区域 -->
  42. <view class="btn" v-if="dataList.length" @click="handleConfirm">确认</view>
  43. <NoData v-if="!dataList.length" />
  44. </view>
  45. </template>
  46. <script setup>
  47. import { onLoad } from '@dcloudio/uni-app'
  48. import { ref } from 'vue'
  49. import { myRequest } from '@/utils/api.js'
  50. import { decryptDes } from '@/utils/des.js'
  51. import NoData from '@/components/noData.vue'
  52. // 输入框绑定数据
  53. const keyWord = ref('')
  54. // 是否全选数据
  55. const allChecked = ref(false)
  56. // 列表数据
  57. const dataList = ref([])
  58. onLoad(() => {
  59. // 查询未分组的学生
  60. getData()
  61. })
  62. // 查询未分组的学生
  63. const getData = async () => {
  64. const res = await myRequest({
  65. url: '/wanzai/api/smartUser/appListClass',
  66. data: {
  67. keyWord: keyWord.value
  68. }
  69. })
  70. // console.log(res)
  71. const result = JSON.parse(decryptDes(res.data))
  72. // console.log(result)
  73. dataList.value = result
  74. dataList.value.forEach((ele) => {
  75. ele.isChecked = false
  76. })
  77. }
  78. // 输入框搜索回调
  79. const changeInputValue = () => {
  80. getData()
  81. }
  82. // 点击添加图标回调
  83. const goAddPage = () => {
  84. uni.navigateTo({
  85. url: '/pages/addStudentMsg/addStudentMsg'
  86. })
  87. }
  88. // 点击全选按钮回调
  89. const handleAllCheck = () => {
  90. if (!allChecked.value) {
  91. dataList.value.forEach((ele) => {
  92. ele.isChecked = true
  93. })
  94. } else {
  95. dataList.value.forEach((ele) => {
  96. ele.isChecked = false
  97. })
  98. }
  99. allChecked.value = !allChecked.value
  100. }
  101. // 点击取消按钮回调
  102. const handleCancel = () => {
  103. if (allChecked.value) {
  104. dataList.value.forEach((ele) => {
  105. ele.isChecked = false
  106. })
  107. }
  108. allChecked.value = false
  109. }
  110. // 点击每一个学生的回调
  111. const handleClickItem = (item) => {
  112. item.isChecked = !item.isChecked
  113. // 判断全选按钮的状态
  114. allChecked.value = dataList.value.every((ele) => ele.isChecked)
  115. }
  116. // 确认按钮回调
  117. const handleConfirm = () => {
  118. // 判断是否选择了学生
  119. const flag = dataList.value.find((ele) => ele.isChecked)
  120. if (!flag) {
  121. uni.showToast({
  122. title: '请至少选择一名学生',
  123. icon: 'none',
  124. mask: true
  125. })
  126. } else {
  127. uni.showModal({
  128. title: '提示',
  129. content: '确定将未分组的学生添加到班级吗?',
  130. success: (res) => {
  131. if (res.confirm) {
  132. let arr = []
  133. dataList.value.forEach((ele) => {
  134. if (ele.isChecked) {
  135. arr.push(ele.id)
  136. }
  137. })
  138. handleAddClass(arr)
  139. }
  140. }
  141. })
  142. }
  143. }
  144. // 添加请求
  145. const handleAddClass = async (ids) => {
  146. const res = await myRequest({
  147. url: '/wanzai/api/smartUser/appSaveClass',
  148. method: 'post',
  149. data: {
  150. ids,
  151. schoolClass: uni.getStorageSync('userInfo').schoolClass
  152. // departmentId: uni.getStorageSync('userInfo').departmentId
  153. }
  154. })
  155. // console.log(res)
  156. if (res.code == 200) {
  157. uni.showToast({
  158. title: res.message,
  159. icon: 'success'
  160. })
  161. setTimeout(() => {
  162. uni.reLaunch({
  163. url: '/pages/studentManage/studentManage'
  164. })
  165. }, 1500)
  166. }
  167. }
  168. </script>
  169. <style lang="scss" scoped>
  170. .container {
  171. box-sizing: border-box;
  172. padding: 20rpx;
  173. height: 100vh;
  174. background-color: #f1f6fe;
  175. // 背景图片区域样式
  176. .img_bg {
  177. position: absolute;
  178. top: -70rpx;
  179. right: 0;
  180. width: 589rpx;
  181. height: 320rpx;
  182. pointer-events: none;
  183. }
  184. .header {
  185. display: flex;
  186. justify-content: space-between;
  187. align-items: center;
  188. padding-top: 30rpx;
  189. .header_input {
  190. display: flex;
  191. align-items: center;
  192. box-sizing: border-box;
  193. padding-left: 40rpx;
  194. width: 589rpx;
  195. height: 100rpx;
  196. font-size: 28rpx;
  197. border-radius: 13rpx;
  198. border: 2rpx solid #cccccc;
  199. background-color: #fff;
  200. .input {
  201. padding: 0 20rpx;
  202. width: 425rpx;
  203. }
  204. }
  205. .header_add {
  206. display: flex;
  207. justify-content: center;
  208. align-items: center;
  209. width: 100rpx;
  210. height: 100rpx;
  211. border-radius: 13rpx;
  212. border: 2rpx solid #cccccc;
  213. background-color: #fff;
  214. }
  215. }
  216. .all {
  217. display: flex;
  218. align-items: center;
  219. margin-top: 30rpx;
  220. font-size: 28rpx;
  221. .all_text {
  222. display: flex;
  223. align-items: center;
  224. color: #0061ff;
  225. }
  226. .cancel {
  227. display: flex;
  228. align-items: center;
  229. margin-left: 50rpx;
  230. color: #00baad;
  231. }
  232. }
  233. .list {
  234. margin-top: 30rpx;
  235. height: calc(100vh - 500rpx);
  236. overflow-y: auto;
  237. .list_item {
  238. display: flex;
  239. align-items: center;
  240. margin-bottom: 20rpx;
  241. .item_info {
  242. display: flex;
  243. align-items: center;
  244. flex: 1;
  245. height: 167rpx;
  246. border-radius: 8rpx 0 0 8rpx;
  247. background-color: #fff;
  248. .info_img {
  249. margin-left: 20rpx;
  250. width: 100rpx;
  251. height: 100rpx;
  252. border-radius: 50%;
  253. }
  254. .info_msg {
  255. display: flex;
  256. flex-direction: column;
  257. justify-content: space-between;
  258. margin-left: 28rpx;
  259. height: 100rpx;
  260. font-size: 28rpx;
  261. color: #808080;
  262. .msg_name {
  263. color: #000000;
  264. font-size: 32rpx;
  265. }
  266. }
  267. }
  268. }
  269. }
  270. .btn {
  271. display: flex;
  272. justify-content: center;
  273. align-items: center;
  274. margin-top: 80rpx;
  275. width: 710rpx;
  276. height: 100rpx;
  277. font-size: 32rpx;
  278. color: #fff;
  279. border-radius: 8rpx;
  280. background-color: #0061ff;
  281. }
  282. }
  283. </style>