studentManage.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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 id = uni.getStorageSync('userInfo').id
  171. getManageClass(id)
  172. })
  173. // 获取管理的班级数组
  174. const getManageClass = async (id) => {
  175. const res = await myRequest({
  176. url: '/wanzai/api/smartUser/getManageClass',
  177. data: {
  178. id
  179. }
  180. })
  181. // console.log(res)
  182. const result = JSON.parse(decryptDes(res.data))
  183. // console.log(result)
  184. dataTree_student.value = result
  185. classes_student.value = result[0].classId
  186. grade_student.value = result[0].gradeId
  187. classInfo.value = result[0].name
  188. uni.setStorageSync('grade_student', grade_student.value)
  189. uni.setStorageSync('classes_student', classes_student.value)
  190. uni.setStorageSync('currentClass', classInfo.value)
  191. uni.setNavigationBarTitle({
  192. title: classInfo.value
  193. })
  194. getData()
  195. }
  196. // 获取学生列表数据
  197. const getData = async () => {
  198. const res = await myRequest({
  199. url: '/wanzai/api/smartUser/queryClassUser',
  200. data: {
  201. userId: uni.getStorageSync('userInfo').id,
  202. keyWord: keyWord.value,
  203. classId: classes_student.value
  204. }
  205. })
  206. // console.log(res)
  207. const result = JSON.parse(decryptDes(res.data))
  208. // console.log(result)
  209. list.value = result.userDetails
  210. list.value.forEach((ele) => {
  211. ele.isChecked = false
  212. })
  213. }
  214. // 点击邀请家长按钮回调
  215. const handleInvitation = () => {
  216. let departmentId = uni.getStorageSync('departmentId')
  217. let departmentId_list = uni.getStorageSync('departmentId_list')
  218. if (departmentId && departmentId_list) {
  219. uni.navigateTo({
  220. url: '/pages/invitation/invitation'
  221. })
  222. } else {
  223. uni.showToast({
  224. title: '请先选择部门',
  225. icon: 'none'
  226. })
  227. setTimeout(() => {
  228. uni.navigateTo({
  229. url: '/pages/set/set'
  230. })
  231. }, 1500)
  232. }
  233. }
  234. // 点击批量按钮回调
  235. const handleEdit = (type) => {
  236. currentType.value = type
  237. showEdit.value = true
  238. copyList.value = JSON.parse(JSON.stringify(list.value))
  239. }
  240. // 点击添加按钮回调
  241. const handleAdd = () => {
  242. let departmentId = uni.getStorageSync('departmentId')
  243. let departmentId_list = uni.getStorageSync('departmentId_list')
  244. if (departmentId && departmentId_list) {
  245. uni.navigateTo({
  246. url: '/pages/addStudent/addStudent'
  247. })
  248. } else {
  249. uni.showToast({
  250. title: '请先选择部门',
  251. icon: 'none'
  252. })
  253. setTimeout(() => {
  254. uni.navigateTo({
  255. url: '/pages/set/set'
  256. })
  257. }, 1500)
  258. }
  259. }
  260. // 批量删除按钮回调
  261. const handleDelete = (type) => {
  262. currentType.value = type
  263. showEdit.value = true
  264. copyList.value = JSON.parse(JSON.stringify(list.value))
  265. }
  266. // 点击取消按钮回调
  267. const handleCancel = () => {
  268. currentType.value = ''
  269. showEdit.value = false
  270. allChecked.value = false
  271. list.value = copyList.value
  272. }
  273. // 点击全选按钮回调
  274. const handleAllCheck = () => {
  275. if (!allChecked.value) {
  276. list.value.forEach((ele) => {
  277. ele.isChecked = true
  278. })
  279. } else {
  280. list.value.forEach((ele) => {
  281. ele.isChecked = false
  282. })
  283. }
  284. allChecked.value = !allChecked.value
  285. }
  286. // 点击每一项删除回调
  287. const onClickItem = (item) => {
  288. uni.showModal({
  289. title: '提示',
  290. content: `确定把${item.name}移除吗?`,
  291. success: (res) => {
  292. if (res.confirm) {
  293. handleDeleteReq([item.id])
  294. }
  295. }
  296. })
  297. }
  298. // 删除请求
  299. const handleDeleteReq = async (ids) => {
  300. const res = await myRequest({
  301. url: '/wanzai/api/smartUser/appRemoveClass',
  302. method: 'post',
  303. data: {
  304. ids: ids
  305. }
  306. })
  307. // console.log(res)
  308. if (res.code == 200) {
  309. uni.showToast({
  310. title: res.message,
  311. icon: 'success'
  312. })
  313. setTimeout(() => {
  314. currentType.value = ''
  315. showEdit.value = false
  316. allChecked.value = false
  317. getData()
  318. }, 1500)
  319. }
  320. }
  321. // 点击每一个学生时的回调
  322. const handleClickItem = (item) => {
  323. if (showEdit.value) {
  324. item.isChecked = !item.isChecked
  325. // 判断全选按钮的状态
  326. allChecked.value = list.value.every((ele) => ele.isChecked)
  327. } else {
  328. // 编辑单个学生
  329. showPage.value = true
  330. headerName.value = item.name
  331. studentId.value = item.id
  332. getTimeGroups()
  333. popupDom.value.open('center')
  334. }
  335. }
  336. // 获取时间组列表数据
  337. const getTimeGroups = async () => {
  338. const res = await myRequest({
  339. url: '/wanzai/api/smartUser/timeGroups'
  340. })
  341. // console.log(res)
  342. const result = JSON.parse(decryptDes(res.data))
  343. // console.log(result)
  344. timeGroups.value = result
  345. timeGroups.value.forEach((ele) => {
  346. ele.isChecked = false
  347. })
  348. }
  349. // 点击弹窗每一个时间组的回调
  350. const handleClickItemPop = (item) => {
  351. timeGroups.value.forEach((ele) => {
  352. ele.isChecked = false
  353. })
  354. item.isChecked = !item.isChecked
  355. uni.showModal({
  356. title: '提示',
  357. content: '确定修改时间组吗?',
  358. success: async (res) => {
  359. if (res.confirm) {
  360. handleConfirm(item.id)
  361. }
  362. }
  363. })
  364. }
  365. const handleConfirm = async (timeGroupId) => {
  366. const res = await myRequest({
  367. url: '/wanzai/api/smartUser/setUserTimeGroup',
  368. method: 'post',
  369. data: {
  370. ids: [studentId.value],
  371. timeGroupId
  372. }
  373. })
  374. // console.log(res)
  375. uni.showToast({
  376. title: res.message,
  377. icon: 'none',
  378. mask: true
  379. })
  380. if (res.code == 200) {
  381. setTimeout(() => {
  382. uni.reLaunch({
  383. url: '/pages/studentManage/studentManage'
  384. })
  385. }, 1500)
  386. }
  387. }
  388. // 点击关联时间组按钮回调
  389. const handleBind = () => {
  390. // 判断是否选择了学生
  391. const flag = list.value.find((ele) => ele.isChecked)
  392. if (!flag) {
  393. uni.showToast({
  394. title: '请至少选择一名学生',
  395. icon: 'none',
  396. mask: true
  397. })
  398. } else {
  399. let arr = []
  400. list.value.forEach((ele) => {
  401. if (ele.isChecked) {
  402. arr.push(ele.id)
  403. }
  404. })
  405. uni.navigateTo({
  406. url: `/pages/timeGroup/timeGroup?ids=${JSON.stringify(arr)}`
  407. })
  408. }
  409. }
  410. // 批量删除按钮回调
  411. const handleDeleteBatch = () => {
  412. // 判断是否选择了学生
  413. const flag = list.value.find((ele) => ele.isChecked)
  414. if (!flag) {
  415. uni.showToast({
  416. title: '请至少选择一名学生',
  417. icon: 'none',
  418. mask: true
  419. })
  420. } else {
  421. uni.showModal({
  422. title: '提示',
  423. content: '确定批量移除吗?',
  424. success: (res) => {
  425. if (res.confirm) {
  426. let arr = []
  427. list.value.forEach((ele) => {
  428. if (ele.isChecked) {
  429. arr.push(ele.id)
  430. }
  431. })
  432. handleDeleteReq(arr)
  433. }
  434. }
  435. })
  436. }
  437. }
  438. // 输入框组件自定义事件
  439. const changeInputValue = () => {
  440. getData()
  441. }
  442. // 设置图标点击回调
  443. const handleClickSet = () => {
  444. uni.navigateTo({
  445. url: '/pages/set/set'
  446. })
  447. }
  448. // 学生部门筛选框选择时的回调
  449. const onchange_student = (e) => {
  450. // console.log(e)
  451. classes_student.value = e.classId
  452. grade_student.value = e.gradeId
  453. classInfo.value = e.name
  454. uni.setStorageSync('currentClass', classInfo.value)
  455. uni.setNavigationBarTitle({
  456. title: classInfo.value
  457. })
  458. uni.setStorageSync('grade_student', grade_student.value)
  459. uni.setStorageSync('classes_student', classes_student.value)
  460. getData()
  461. }
  462. </script>
  463. <style lang="scss" scoped>
  464. .container {
  465. display: flex;
  466. flex-direction: column;
  467. padding: 0 20rpx;
  468. min-height: 100vh;
  469. background-color: #f1f6fe;
  470. // 背景图片区域样式
  471. .img_bg {
  472. position: absolute;
  473. top: -70rpx;
  474. right: 0;
  475. width: 589rpx;
  476. height: 320rpx;
  477. pointer-events: none;
  478. }
  479. .header {
  480. display: flex;
  481. justify-content: space-between;
  482. align-items: center;
  483. padding-top: 30rpx;
  484. .header_input {
  485. display: flex;
  486. align-items: center;
  487. box-sizing: border-box;
  488. padding-left: 40rpx;
  489. width: 589rpx;
  490. height: 100rpx;
  491. font-size: 28rpx;
  492. border-radius: 13rpx;
  493. border: 2rpx solid #cccccc;
  494. background-color: #fff;
  495. .input {
  496. padding: 0 20rpx;
  497. width: 425rpx;
  498. }
  499. }
  500. .header_set {
  501. display: flex;
  502. justify-content: center;
  503. align-items: center;
  504. width: 100rpx;
  505. height: 100rpx;
  506. border-radius: 13rpx;
  507. border: 2rpx solid #cccccc;
  508. background-color: #fff;
  509. }
  510. }
  511. .grade {
  512. margin-top: 10rpx;
  513. height: 70rpx;
  514. }
  515. // 学校名称区域样式
  516. .school {
  517. display: flex;
  518. // justify-content: space-between;
  519. align-items: center;
  520. margin-top: 38rpx;
  521. color: #808080;
  522. font-size: 28rpx;
  523. .invite {
  524. display: flex;
  525. align-items: center;
  526. margin-right: 30rpx;
  527. color: #0061ff;
  528. }
  529. .school_edit {
  530. display: flex;
  531. align-items: center;
  532. margin-right: 80rpx;
  533. color: #00baad;
  534. .img {
  535. width: 45rpx;
  536. height: 45rpx;
  537. }
  538. }
  539. .add {
  540. display: flex;
  541. align-items: center;
  542. color: #0061ff;
  543. }
  544. .delete {
  545. display: flex;
  546. align-items: center;
  547. margin-left: auto;
  548. color: #d43030;
  549. }
  550. .school_btn {
  551. display: flex;
  552. align-items: center;
  553. .cancel {
  554. margin-right: 20rpx;
  555. color: #d43030;
  556. }
  557. .all {
  558. margin-left: -10rpx;
  559. }
  560. }
  561. }
  562. .list_box {
  563. padding-bottom: 30rpx;
  564. margin-top: 22rpx;
  565. background-color: #f1f6fe;
  566. .item_box {
  567. display: flex;
  568. justify-content: space-between;
  569. align-items: center;
  570. padding: 0 20rpx;
  571. height: 167rpx;
  572. font-size: 28rpx;
  573. border-radius: 8rpx;
  574. background-color: #fff;
  575. .box_info {
  576. display: flex;
  577. .info_img {
  578. width: 100rpx;
  579. height: 100rpx;
  580. border-radius: 50%;
  581. }
  582. .info_msg {
  583. display: flex;
  584. flex-direction: column;
  585. justify-content: space-between;
  586. margin-left: 28rpx;
  587. .msg_name {
  588. font-size: 32rpx;
  589. }
  590. .msg_no {
  591. color: #808080;
  592. }
  593. }
  594. }
  595. .box_time {
  596. }
  597. }
  598. }
  599. .btn {
  600. position: fixed;
  601. bottom: 0;
  602. padding: 0 30rpx 30rpx;
  603. background-color: #fff;
  604. .btn_box {
  605. display: flex;
  606. justify-content: center;
  607. align-items: center;
  608. margin-top: 28rpx;
  609. width: 650rpx;
  610. height: 100rpx;
  611. color: #fff;
  612. font-size: 32rpx;
  613. border-radius: 8rpx;
  614. background-color: #0061ff;
  615. .text {
  616. margin-left: 10rpx;
  617. }
  618. }
  619. .delete {
  620. background-color: #d43030;
  621. }
  622. }
  623. .pop_up {
  624. width: 710rpx;
  625. height: 855rpx;
  626. border-radius: 22rpx;
  627. background-color: #fff;
  628. .popup_top {
  629. height: 94rpx;
  630. line-height: 94rpx;
  631. text-align: center;
  632. font-size: 28rpx;
  633. border-bottom: 1rpx solid #e6e6e6;
  634. }
  635. .popup_body {
  636. height: 760rpx;
  637. overflow-y: auto;
  638. .time_item {
  639. display: flex;
  640. justify-content: space-between;
  641. align-items: center;
  642. padding: 0 40rpx;
  643. height: 130rpx;
  644. border-bottom: 1rpx solid #e6e6e6;
  645. .item_left {
  646. display: flex;
  647. flex-direction: column;
  648. justify-content: space-between;
  649. height: 80rpx;
  650. .top {
  651. font-size: 28rpx;
  652. }
  653. .bottom {
  654. font-size: 24rpx;
  655. color: #b3b3b3;
  656. }
  657. }
  658. }
  659. }
  660. }
  661. }
  662. </style>