studentManage.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. <template>
  2. <view class="container" :style="[showEdit ? 'padding-bottom:180rpx' : '', showPage ? 'overflow:hidden' : 'overflow:visible']">
  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_set" @click="handleClickSet">
  12. <uni-icons type="gear" size="28" color="#383838"></uni-icons>
  13. </view>
  14. </view>
  15. <!-- 选择年级区域 -->
  16. <view class="grade">
  17. <uni-data-picker
  18. placeholder="请选择班级"
  19. popup-title="请选择班级"
  20. :map="{ text: 'name', value: 'classId' }"
  21. :clear-icon="false"
  22. :localdata="dataTree_student"
  23. v-model="classes_student"
  24. @nodeclick="onchange_student"
  25. ></uni-data-picker>
  26. </view>
  27. <!-- 功能按钮区域 -->
  28. <view class="school" v-if="list.length">
  29. <!-- 邀请家长按钮区域 -->
  30. <view v-if="!showEdit" class="invite" @click="handleInvitation">
  31. <uni-icons type="personadd" size="22" color="#0061FF"></uni-icons>
  32. &nbsp;邀请家长
  33. </view>
  34. <!-- 批量修改按钮区域 -->
  35. <view v-if="!showEdit" class="school_edit" @click="handleEdit('修改')">
  36. <img class="img" src="@/static/images/edit2.png" />
  37. 批量修改
  38. </view>
  39. <!-- 添加按钮区域 -->
  40. <view v-if="!showEdit" class="add" @click="handleAdd">
  41. <uni-icons type="plus" size="22" color="#0061FF"></uni-icons>
  42. &nbsp;添加
  43. </view>
  44. <!-- 删除按钮区域 -->
  45. <view v-if="!showEdit" class="delete" @click="handleDelete('删除')">
  46. <uni-icons type="trash" size="22" color="#D43030"></uni-icons>
  47. 批量删除
  48. </view>
  49. <!-- 全选按钮区域 -->
  50. <view v-if="showEdit" class="school_btn">
  51. <view class="cancel" @click="handleCancel">取消</view>
  52. <radio color="#0061FF" style="transform: scale(0.7)" :checked="allChecked" @click="handleAllCheck" />
  53. <view class="all">全选</view>
  54. </view>
  55. </view>
  56. <!-- 学生列表区域 -->
  57. <view class="list_box" v-if="list.length">
  58. <uni-swipe-action>
  59. <view v-for="(item, index) in list" :key="index">
  60. <uni-swipe-action-item :right-options="options" @click="onClickItem(item)">
  61. <!-- 每一个学生区域 -->
  62. <view class="item_box" @click="handleClickItem(item)">
  63. <view class="box_info">
  64. <image v-if="item.headImage" class="info_img" :src="item.headImage" mode="aspectFill"></image>
  65. <image
  66. v-else
  67. class="info_img"
  68. src="https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/excelModel/nupp7VVnHWpVa413437dba82ce85374b2a4ee1a6b973.png"
  69. mode="aspectFill"
  70. ></image>
  71. <view class="info_msg">
  72. <view class="msg_name">
  73. {{ item.name }}
  74. </view>
  75. <view class="msg_no">
  76. {{ item.cardNo }}
  77. </view>
  78. </view>
  79. </view>
  80. <view class="box_time">{{ item.timeGroup }}</view>
  81. <radio v-if="showEdit" color="#0061FF" style="transform: scale(0.7)" :checked="item.isChecked" />
  82. </view>
  83. </uni-swipe-action-item>
  84. <view style="height: 20rpx"></view>
  85. </view>
  86. </uni-swipe-action>
  87. </view>
  88. <!-- 关联时间组按钮区域 -->
  89. <view class="btn" v-if="showEdit && currentType == '修改'">
  90. <view class="btn_box" @click="handleBind">
  91. <uni-icons color="#fff" type="link" size="28"></uni-icons>
  92. <text class="text">关联时间组</text>
  93. </view>
  94. </view>
  95. <!-- 批量删除区域 -->
  96. <view class="btn" v-if="showEdit && currentType == '删除'">
  97. <view class="btn_box delete" @click="handleDeleteBatch">
  98. <uni-icons color="#fff" type="trash" size="28"></uni-icons>
  99. <text class="text">批量删除</text>
  100. </view>
  101. </view>
  102. <!-- 没有数据时展示的页面 -->
  103. <NoData v-if="!list.length" style="margin-top: 140rpx" />
  104. <!-- 弹窗区域 -->
  105. <uni-popup ref="popupDom">
  106. <view class="pop_up">
  107. <!-- 头部标题区域 -->
  108. <view class="popup_top">{{ headerName }} - 关联时间组</view>
  109. <!-- 时间组区域 -->
  110. <view class="popup_body">
  111. <!-- 每一个时间组区域 -->
  112. <view class="time_item" v-for="item in timeGroups" :key="item.id" @click="handleClickItemPop(item)">
  113. <view class="item_left">
  114. <view class="top">{{ item.name }}</view>
  115. <view class="bottom">{{ item.remark }}</view>
  116. </view>
  117. <radio color="#0061FF" style="transform: scale(0.9)" :checked="item.isChecked" />
  118. </view>
  119. </view>
  120. </view>
  121. </uni-popup>
  122. </view>
  123. </template>
  124. <script setup>
  125. import { ref } from 'vue'
  126. import { onLoad } from '@dcloudio/uni-app'
  127. import HeaderInput from '@/components/headerInput.vue'
  128. import NoData from '@/components/noData.vue'
  129. import { myRequest } from '@/utils/api.js'
  130. import { decryptDes } from '@/utils/des.js'
  131. // 当前所处班级
  132. const classInfo = ref()
  133. // 搜索框绑定数据
  134. const keyWord = ref('')
  135. // 学生列表数据
  136. const list = ref([])
  137. // 缓存数据
  138. const copyList = ref([])
  139. // 是否显示全选radio
  140. const showEdit = ref(false)
  141. // 是否全选
  142. const allChecked = ref(false)
  143. // 弹窗DOM
  144. const popupDom = ref()
  145. // 时间组列表
  146. const timeGroups = ref([])
  147. // 弹窗标题
  148. const headerName = ref('')
  149. // 当前学生id
  150. const studentId = ref()
  151. // 滚动穿透控制
  152. const showPage = ref(false)
  153. const options = [
  154. {
  155. text: '删除',
  156. style: {
  157. backgroundColor: '#D43030'
  158. }
  159. }
  160. ]
  161. // 判断是修改还是删除
  162. const currentType = ref('')
  163. // 班级数组
  164. const dataTree_student = ref([])
  165. // 选择的班级
  166. const classes_student = ref()
  167. // 选择的年级
  168. const grade_student = ref()
  169. onLoad(() => {
  170. const manageGrade = uni.getStorageSync('userInfo').manageGrade
  171. const manageSchoolClass = uni.getStorageSync('userInfo').manageSchoolClass
  172. getManageClass(manageSchoolClass, manageGrade)
  173. })
  174. // 获取管理的班级数组
  175. const getManageClass = async (manageSchoolClass, manageGrade) => {
  176. const res = await myRequest({
  177. url: '/wanzai/api/smartUser/getManageClass',
  178. data: {
  179. manageSchoolClass,
  180. manageGrade
  181. }
  182. })
  183. // console.log(res)
  184. const result = JSON.parse(decryptDes(res.data))
  185. // console.log(result)
  186. dataTree_student.value = result
  187. classes_student.value = result[0].classId
  188. grade_student.value = result[0].gradeId
  189. classInfo.value = result[0].name
  190. uni.setStorageSync('grade_student', grade_student.value)
  191. uni.setStorageSync('classes_student', classes_student.value)
  192. uni.setStorageSync('currentClass', classInfo.value)
  193. uni.setNavigationBarTitle({
  194. title: classInfo.value
  195. })
  196. getData()
  197. }
  198. // 获取学生列表数据
  199. const getData = async () => {
  200. const res = await myRequest({
  201. url: '/wanzai/api/smartUser/queryClassUser',
  202. data: {
  203. userId: uni.getStorageSync('userInfo').id,
  204. keyWord: keyWord.value,
  205. classId: classes_student.value
  206. }
  207. })
  208. // console.log(res)
  209. const result = JSON.parse(decryptDes(res.data))
  210. // console.log(result)
  211. list.value = result.userDetails
  212. list.value.forEach((ele) => {
  213. ele.isChecked = false
  214. })
  215. }
  216. // 点击邀请家长按钮回调
  217. const handleInvitation = () => {
  218. let departmentId = uni.getStorageSync('departmentId')
  219. let departmentId_list = uni.getStorageSync('departmentId_list')
  220. if (departmentId && departmentId_list) {
  221. uni.navigateTo({
  222. url: '/pages/invitation/invitation'
  223. })
  224. } else {
  225. uni.showToast({
  226. title: '请先选择部门',
  227. icon: 'none'
  228. })
  229. setTimeout(() => {
  230. uni.navigateTo({
  231. url: '/pages/set/set'
  232. })
  233. }, 1500)
  234. }
  235. }
  236. // 点击批量按钮回调
  237. const handleEdit = (type) => {
  238. currentType.value = type
  239. showEdit.value = true
  240. copyList.value = JSON.parse(JSON.stringify(list.value))
  241. }
  242. // 点击添加按钮回调
  243. const handleAdd = () => {
  244. let departmentId = uni.getStorageSync('departmentId')
  245. let departmentId_list = uni.getStorageSync('departmentId_list')
  246. if (departmentId && departmentId_list) {
  247. uni.navigateTo({
  248. url: '/pages/addStudent/addStudent'
  249. })
  250. } else {
  251. uni.showToast({
  252. title: '请先选择部门',
  253. icon: 'none'
  254. })
  255. setTimeout(() => {
  256. uni.navigateTo({
  257. url: '/pages/set/set'
  258. })
  259. }, 1500)
  260. }
  261. }
  262. // 批量删除按钮回调
  263. const handleDelete = (type) => {
  264. currentType.value = type
  265. showEdit.value = true
  266. copyList.value = JSON.parse(JSON.stringify(list.value))
  267. }
  268. // 点击取消按钮回调
  269. const handleCancel = () => {
  270. currentType.value = ''
  271. showEdit.value = false
  272. allChecked.value = false
  273. list.value = copyList.value
  274. }
  275. // 点击全选按钮回调
  276. const handleAllCheck = () => {
  277. if (!allChecked.value) {
  278. list.value.forEach((ele) => {
  279. ele.isChecked = true
  280. })
  281. } else {
  282. list.value.forEach((ele) => {
  283. ele.isChecked = false
  284. })
  285. }
  286. allChecked.value = !allChecked.value
  287. }
  288. // 点击每一项删除回调
  289. const onClickItem = (item) => {
  290. uni.showModal({
  291. title: '提示',
  292. content: `确定把${item.name}移除吗?`,
  293. success: (res) => {
  294. if (res.confirm) {
  295. handleDeleteReq([item.id])
  296. }
  297. }
  298. })
  299. }
  300. // 删除请求
  301. const handleDeleteReq = async (ids) => {
  302. const res = await myRequest({
  303. url: '/wanzai/api/smartUser/appRemoveClass',
  304. method: 'post',
  305. data: {
  306. ids: ids
  307. }
  308. })
  309. // console.log(res)
  310. if (res.code == 200) {
  311. uni.showToast({
  312. title: res.message,
  313. icon: 'success'
  314. })
  315. setTimeout(() => {
  316. currentType.value = ''
  317. showEdit.value = false
  318. allChecked.value = false
  319. getData()
  320. }, 1500)
  321. }
  322. }
  323. // 点击每一个学生时的回调
  324. const handleClickItem = (item) => {
  325. if (showEdit.value) {
  326. item.isChecked = !item.isChecked
  327. // 判断全选按钮的状态
  328. allChecked.value = list.value.every((ele) => ele.isChecked)
  329. } else {
  330. // 编辑单个学生
  331. showPage.value = true
  332. headerName.value = item.name
  333. studentId.value = item.id
  334. getTimeGroups()
  335. popupDom.value.open('center')
  336. }
  337. }
  338. // 获取时间组列表数据
  339. const getTimeGroups = async () => {
  340. const res = await myRequest({
  341. url: '/wanzai/api/smartUser/timeGroups'
  342. })
  343. // console.log(res)
  344. const result = JSON.parse(decryptDes(res.data))
  345. // console.log(result)
  346. timeGroups.value = result
  347. timeGroups.value.forEach((ele) => {
  348. ele.isChecked = false
  349. })
  350. }
  351. // 点击弹窗每一个时间组的回调
  352. const handleClickItemPop = (item) => {
  353. timeGroups.value.forEach((ele) => {
  354. ele.isChecked = false
  355. })
  356. item.isChecked = !item.isChecked
  357. uni.showModal({
  358. title: '提示',
  359. content: '确定修改时间组吗?',
  360. success: async (res) => {
  361. if (res.confirm) {
  362. handleConfirm(item.id)
  363. }
  364. }
  365. })
  366. }
  367. const handleConfirm = async (timeGroupId) => {
  368. const res = await myRequest({
  369. url: '/wanzai/api/smartUser/setUserTimeGroup',
  370. method: 'post',
  371. data: {
  372. ids: [studentId.value],
  373. timeGroupId
  374. }
  375. })
  376. // console.log(res)
  377. uni.showToast({
  378. title: res.message,
  379. icon: 'none',
  380. mask: true
  381. })
  382. if (res.code == 200) {
  383. setTimeout(() => {
  384. uni.reLaunch({
  385. url: '/pages/studentManage/studentManage'
  386. })
  387. }, 1500)
  388. }
  389. }
  390. // 点击关联时间组按钮回调
  391. const handleBind = () => {
  392. // 判断是否选择了学生
  393. const flag = list.value.find((ele) => ele.isChecked)
  394. if (!flag) {
  395. uni.showToast({
  396. title: '请至少选择一名学生',
  397. icon: 'none',
  398. mask: true
  399. })
  400. } else {
  401. let arr = []
  402. list.value.forEach((ele) => {
  403. if (ele.isChecked) {
  404. arr.push(ele.id)
  405. }
  406. })
  407. uni.navigateTo({
  408. url: `/pages/timeGroup/timeGroup?ids=${JSON.stringify(arr)}`
  409. })
  410. }
  411. }
  412. // 批量删除按钮回调
  413. const handleDeleteBatch = () => {
  414. // 判断是否选择了学生
  415. const flag = list.value.find((ele) => ele.isChecked)
  416. if (!flag) {
  417. uni.showToast({
  418. title: '请至少选择一名学生',
  419. icon: 'none',
  420. mask: true
  421. })
  422. } else {
  423. uni.showModal({
  424. title: '提示',
  425. content: '确定批量移除吗?',
  426. success: (res) => {
  427. if (res.confirm) {
  428. let arr = []
  429. list.value.forEach((ele) => {
  430. if (ele.isChecked) {
  431. arr.push(ele.id)
  432. }
  433. })
  434. handleDeleteReq(arr)
  435. }
  436. }
  437. })
  438. }
  439. }
  440. // 输入框组件自定义事件
  441. const changeInputValue = () => {
  442. getData()
  443. }
  444. // 设置图标点击回调
  445. const handleClickSet = () => {
  446. uni.navigateTo({
  447. url: '/pages/set/set'
  448. })
  449. }
  450. // 学生部门筛选框选择时的回调
  451. const onchange_student = (e) => {
  452. // console.log(e)
  453. classes_student.value = e.classId
  454. grade_student.value = e.gradeId
  455. classInfo.value = e.name
  456. uni.setStorageSync('currentClass', classInfo.value)
  457. uni.setNavigationBarTitle({
  458. title: classInfo.value
  459. })
  460. uni.setStorageSync('grade_student', grade_student.value)
  461. uni.setStorageSync('classes_student', classes_student.value)
  462. getData()
  463. }
  464. </script>
  465. <style lang="scss" scoped>
  466. .container {
  467. display: flex;
  468. flex-direction: column;
  469. padding: 0 20rpx;
  470. min-height: 100vh;
  471. background-color: #f1f6fe;
  472. // 背景图片区域样式
  473. .img_bg {
  474. position: absolute;
  475. top: -70rpx;
  476. right: 0;
  477. width: 589rpx;
  478. height: 320rpx;
  479. pointer-events: none;
  480. }
  481. .header {
  482. display: flex;
  483. justify-content: space-between;
  484. align-items: center;
  485. padding-top: 30rpx;
  486. .header_input {
  487. display: flex;
  488. align-items: center;
  489. box-sizing: border-box;
  490. padding-left: 40rpx;
  491. width: 589rpx;
  492. height: 100rpx;
  493. font-size: 28rpx;
  494. border-radius: 13rpx;
  495. border: 2rpx solid #cccccc;
  496. background-color: #fff;
  497. .input {
  498. padding: 0 20rpx;
  499. width: 425rpx;
  500. }
  501. }
  502. .header_set {
  503. display: flex;
  504. justify-content: center;
  505. align-items: center;
  506. width: 100rpx;
  507. height: 100rpx;
  508. border-radius: 13rpx;
  509. border: 2rpx solid #cccccc;
  510. background-color: #fff;
  511. }
  512. }
  513. .grade {
  514. margin-top: 10rpx;
  515. height: 70rpx;
  516. }
  517. // 学校名称区域样式
  518. .school {
  519. display: flex;
  520. // justify-content: space-between;
  521. align-items: center;
  522. margin-top: 38rpx;
  523. color: #808080;
  524. font-size: 28rpx;
  525. .invite {
  526. display: flex;
  527. align-items: center;
  528. margin-right: 30rpx;
  529. color: #0061ff;
  530. }
  531. .school_edit {
  532. display: flex;
  533. align-items: center;
  534. margin-right: 80rpx;
  535. color: #00baad;
  536. .img {
  537. width: 45rpx;
  538. height: 45rpx;
  539. }
  540. }
  541. .add {
  542. display: flex;
  543. align-items: center;
  544. color: #0061ff;
  545. }
  546. .delete {
  547. display: flex;
  548. align-items: center;
  549. margin-left: auto;
  550. color: #d43030;
  551. }
  552. .school_btn {
  553. display: flex;
  554. align-items: center;
  555. .cancel {
  556. margin-right: 20rpx;
  557. color: #d43030;
  558. }
  559. .all {
  560. margin-left: -10rpx;
  561. }
  562. }
  563. }
  564. .list_box {
  565. padding-bottom: 30rpx;
  566. margin-top: 22rpx;
  567. background-color: #f1f6fe;
  568. .item_box {
  569. display: flex;
  570. justify-content: space-between;
  571. align-items: center;
  572. padding: 0 20rpx;
  573. height: 167rpx;
  574. font-size: 28rpx;
  575. border-radius: 8rpx;
  576. background-color: #fff;
  577. .box_info {
  578. display: flex;
  579. .info_img {
  580. width: 100rpx;
  581. height: 100rpx;
  582. border-radius: 50%;
  583. }
  584. .info_msg {
  585. display: flex;
  586. flex-direction: column;
  587. justify-content: space-between;
  588. margin-left: 28rpx;
  589. .msg_name {
  590. font-size: 32rpx;
  591. }
  592. .msg_no {
  593. color: #808080;
  594. }
  595. }
  596. }
  597. .box_time {
  598. }
  599. }
  600. }
  601. .btn {
  602. position: fixed;
  603. bottom: 0;
  604. padding: 0 30rpx 30rpx;
  605. background-color: #fff;
  606. .btn_box {
  607. display: flex;
  608. justify-content: center;
  609. align-items: center;
  610. margin-top: 28rpx;
  611. width: 650rpx;
  612. height: 100rpx;
  613. color: #fff;
  614. font-size: 32rpx;
  615. border-radius: 8rpx;
  616. background-color: #0061ff;
  617. .text {
  618. margin-left: 10rpx;
  619. }
  620. }
  621. .delete {
  622. background-color: #d43030;
  623. }
  624. }
  625. .pop_up {
  626. width: 710rpx;
  627. height: 855rpx;
  628. border-radius: 22rpx;
  629. background-color: #fff;
  630. .popup_top {
  631. height: 94rpx;
  632. line-height: 94rpx;
  633. text-align: center;
  634. font-size: 28rpx;
  635. border-bottom: 1rpx solid #e6e6e6;
  636. }
  637. .popup_body {
  638. height: 760rpx;
  639. overflow-y: auto;
  640. .time_item {
  641. display: flex;
  642. justify-content: space-between;
  643. align-items: center;
  644. padding: 0 40rpx;
  645. height: 130rpx;
  646. border-bottom: 1rpx solid #e6e6e6;
  647. .item_left {
  648. display: flex;
  649. flex-direction: column;
  650. justify-content: space-between;
  651. height: 80rpx;
  652. .top {
  653. font-size: 28rpx;
  654. }
  655. .bottom {
  656. font-size: 24rpx;
  657. color: #b3b3b3;
  658. }
  659. }
  660. }
  661. }
  662. }
  663. }
  664. </style>