grade.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <view class="container">
  3. <!-- 背景图片区域 -->
  4. <img class="img_bg" src="../../static/images/center-bg.png" />
  5. <!-- input组件区域 -->
  6. <headerInput @changeInputValue="changeInputValue" />
  7. <!-- 学校年级班级区域 -->
  8. <!-- <view class="school">万载三中/{{ gradeName ? gradeName + '/' : '' }}{{ className ? className : '' }}</view> -->
  9. <view class="school">
  10. <uni-data-picker
  11. placeholder="请选择班级"
  12. popup-title="请选择班级"
  13. :clear-icon="false"
  14. :map="{ text: 'name', value: 'classId' }"
  15. :localdata="dataTree_student"
  16. v-model="classes_student"
  17. @nodeclick="clickNode"
  18. ></uni-data-picker>
  19. </view>
  20. <!-- 学生列表区域 -->
  21. <listView :list="list" :appType="appType" />
  22. </view>
  23. </template>
  24. <script setup>
  25. import { ref, nextTick } from 'vue'
  26. import { onLoad } from '@dcloudio/uni-app'
  27. import headerInput from '@/components/headerInput.vue'
  28. import listView from '@/components/listView.vue'
  29. import { myRequest } from '@/utils/api.js'
  30. import { decryptDes } from '@/utils/des.js'
  31. // 学生列表数组
  32. const list = ref([])
  33. // 年级信息
  34. const gradeName = ref('')
  35. // 班级信息
  36. const className = ref('')
  37. const appType = ref('')
  38. const dataTree_student = ref([])
  39. const classes_student = ref('')
  40. const gradeId = ref('')
  41. onLoad((options) => {
  42. appType.value = options.type || ''
  43. const id = uni.getStorageSync('userInfo').id
  44. getManageClass(id)
  45. })
  46. // 获取管理的班级数组
  47. const getManageClass = async (id) => {
  48. const res = await myRequest({
  49. url: '/wanzai/api/smartUser/getManageClass',
  50. data: {
  51. id
  52. }
  53. })
  54. // console.log(res)
  55. const result = JSON.parse(decryptDes(res.data))
  56. // console.log(result)
  57. dataTree_student.value = result
  58. classes_student.value = result[0].classId
  59. gradeId.value = result[0].gradeId
  60. getData()
  61. }
  62. // 输入框组件自定义事件
  63. const changeInputValue = (value) => {
  64. // console.log(value)
  65. // console.log(value.trim())
  66. if (value.trim()) {
  67. let temList = []
  68. list.value.forEach((ele) => {
  69. if (ele.name.indexOf(value.trim()) != -1) {
  70. temList.push(ele)
  71. }
  72. })
  73. list.value = temList
  74. } else {
  75. getData()
  76. }
  77. }
  78. const getData = async () => {
  79. const res = await myRequest({
  80. url: '/wanzai/api/wechat/queryPhoneBook',
  81. data: {
  82. id: uni.getStorageSync('userInfo').id,
  83. gradeId: gradeId.value,
  84. classId: classes_student.value
  85. }
  86. })
  87. // console.log(res)
  88. res.data.forEach((ele) => {
  89. let temlist
  90. ele.classBookList.forEach((item, index, arr) => {
  91. if (item.bookUserList.length) {
  92. // 所在年级学生的数据
  93. list.value = item.bookUserList
  94. // 班级信息
  95. className.value = arr[index].className
  96. temlist = arr
  97. }
  98. })
  99. if (ele.classBookList == temlist) {
  100. gradeName.value = ele.gradeName
  101. }
  102. })
  103. // console.log(list.vlaue)
  104. if (className.value) {
  105. uni.setNavigationBarTitle({
  106. title: gradeName.value + className.value
  107. })
  108. }
  109. }
  110. // 学生部门筛选框选择时的回调
  111. const clickNode = (e) => {
  112. // console.log(e)
  113. classes_student.value = e.classId
  114. gradeId.value = e.gradeId
  115. getData()
  116. }
  117. </script>
  118. <style lang="scss" scoped>
  119. .container {
  120. display: flex;
  121. flex-direction: column;
  122. padding: 0 20rpx;
  123. min-height: 100vh;
  124. background-color: #f1f6fe;
  125. // 背景图片区域样式
  126. .img_bg {
  127. position: absolute;
  128. top: -70rpx;
  129. right: 0;
  130. width: 589rpx;
  131. height: 320rpx;
  132. pointer-events: none;
  133. }
  134. // 学校名称区域样式
  135. .school {
  136. margin-top: 30rpx;
  137. color: #808080;
  138. font-size: 28rpx;
  139. }
  140. }
  141. </style>