addStudent.vue 6.7 KB

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