select.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <template>
  2. <view class="container-box">
  3. <image alt="" class="back-class" src="/static/image/bmi/manual_icon_arrow.png" @click="goBcak()"></image>
  4. <text class="countdown">倒计时{{ countdown }}s</text>
  5. <view class="select-box">
  6. <view class="select-tab">
  7. <view v-for="(item, index) in tabs" :key="index" :class="item.type == activeTab ? `tab-active-item${index}` : `tab-item${index}`"
  8. class="tab-item" @click="changeTab(item)">
  9. <image :src="item.type == activeTab ? item.actImg : item.img" alt="" class="tab-img"></image>
  10. <text>{{ item.title }}</text>
  11. </view>
  12. </view>
  13. <view v-if="activeTab == 'grade'" class="select-info">
  14. <view v-for="(item, index) in totalList" :class="item.active == true ? `info-active-item0` : `info-item0`" class="info-item"
  15. @click="changeGrade(item)">{{ item.name }}
  16. </view>
  17. </view>
  18. <view v-else-if="activeTab == 'class'" class="select-info">
  19. <view v-for="(item, index) in classList" :class="item.active == true ? `info-active-item1` : `info-item1`" class="info-item"
  20. @click="changeClass(item)">{{ item.class_name }}
  21. </view>
  22. </view>
  23. <view v-else-if="activeTab == 'student'" class="select-info">
  24. <view v-for="(item, index) in studentList" :class="item.active == true ? `info-active-item2` : `info-item2`" class="info-item"
  25. @click="changeStudent(item)">{{ item.jname }}
  26. </view>
  27. </view>
  28. </view>
  29. <view class="selected-box">
  30. <view>已选择:</view>
  31. <view class="selected-info">
  32. <view v-for="(item, index) in curSelected" :key="index">
  33. <text v-if="index != 0" class="selected-line">|</text>
  34. <text>{{ item.name }}</text>
  35. </view>
  36. </view>
  37. </view>
  38. <view :class="curSelected.length == 3 ? 'next-btn' : 'ban-btn'" @click="navToTest">进入检测页</view>
  39. </view>
  40. </template>
  41. <script setup>
  42. import {onActivated, onUnmounted, watch, ref, computed} from "vue";
  43. import {onLoad, onUnload, onHide} from '@dcloudio/uni-app';
  44. import {navTo, showToast} from "@/utils/app";
  45. import {getTaskClassList, getTaskStudentList} from "@/api/student";
  46. const title = ref('学生未激活')
  47. const select = ref(0)
  48. const selectMax = ref(1)
  49. const totalList = ref([])
  50. const activeTab = ref('grade')
  51. const countdown = ref(60)
  52. const interval = ref()
  53. const queryForm = ref({
  54. student_id: 0,
  55. })
  56. const tabs = ref([
  57. {
  58. title: '选择年级',
  59. type: 'grade',
  60. img: '/static/image/bmi/manual_icon_grade.png',
  61. actImg: '/static/image/bmi/manual_icon_grade_selected.png'
  62. },
  63. {
  64. title: '选择班级',
  65. type: 'class',
  66. img: '/static/image/bmi/manual_icon_class.png',
  67. actImg: '/static/image/bmi/manual_icon_class_selected.png'
  68. },
  69. {
  70. title: '选择学生',
  71. type: 'student',
  72. img: '/static/image/bmi/manual_icon_student.png',
  73. actImg: '/static/image/bmi/manual_icon_student_selected.png'
  74. }
  75. ])
  76. const selectedArr = ref([
  77. {name: '三年级', id: 1},
  78. {name: '1班', id: 2},
  79. {name: '11', id: 3},
  80. ])
  81. const setCountdown = () => {
  82. interval.value = setInterval(() => {
  83. countdown.value -= 1
  84. }, 1000);
  85. if (countdown.value == 0) {
  86. clearInterval(interval)
  87. goBcak()
  88. }
  89. }
  90. watch(countdown, (newVal, oldVal) => {
  91. if (newVal <= 0) {
  92. clearInterval(interval.value)
  93. goBcak()
  94. }
  95. })
  96. const classList = computed(() => {
  97. let activeGrade = totalList.value.find(item => item.active == true)
  98. return activeGrade ? activeGrade.class : null
  99. })
  100. const studentList = computed(() => {
  101. let activeGrade = totalList.value.find(item => item.active == true)
  102. if (activeGrade && activeGrade.class) {
  103. let activeClass = activeGrade.class.find(item => item.active == true)
  104. return activeClass ? activeClass.student : null
  105. }
  106. return null
  107. })
  108. const curSelected = computed(() => {
  109. let arr = []
  110. let activeGrade = totalList.value.find(item => item.active == true)
  111. if (activeGrade) {
  112. arr.push(activeGrade)
  113. let activeClass = classList.value.find(item => item.active == true)
  114. if (activeClass) {
  115. arr.push(activeClass)
  116. if (studentList.value && studentList.value.length > 0) {
  117. let activeStudent = studentList.value.find(item => item.active == true)
  118. if (activeStudent) arr.push(activeStudent)
  119. }
  120. }
  121. }
  122. return arr
  123. })
  124. const getGradeList = async () => {
  125. const res = await getTaskClassList()
  126. const list = []
  127. if (res.code == 1) {
  128. res.data.grades.forEach(el => {
  129. if (!list.some(e => e.id == el.id)) {
  130. list.push(el);
  131. }
  132. });
  133. }
  134. totalList.value = list
  135. const classList = []
  136. for (let item of res.data.list) {
  137. for (let task of item.task) {
  138. classList.push({
  139. ...item,
  140. ...task,
  141. name: item.class_name
  142. })
  143. }
  144. }
  145. for (let gradeItem of totalList.value) {
  146. let arr = []
  147. for (let classItem of classList) {
  148. if (gradeItem.id == classItem.grade) {
  149. arr.push(classItem)
  150. }
  151. }
  152. if (arr.length > 0) gradeItem.class = arr
  153. }
  154. }
  155. const getStudent = async (item) => {
  156. const res = await getTaskStudentList({
  157. task_id: item.task_id
  158. })
  159. if (res.code == 1) {
  160. let list = res.data.list.map(i => {
  161. return {...i, name: i.jname}
  162. })
  163. totalList.value.find(item => item.active == true).class
  164. .find(item => item.active == true).student = list
  165. }
  166. }
  167. const changeTab = (item) => {
  168. activeTab.value = item.type
  169. }
  170. const changeGrade = (item) => {
  171. activeTab.value = 'class'
  172. for (let i of totalList.value) {
  173. i.active = false
  174. }
  175. item.active = true
  176. let classList = totalList.value.find(i => i.active == true).class
  177. for (let i of classList) {
  178. i.active = false
  179. }
  180. // getClassList()
  181. }
  182. const changeClass = (item) => {
  183. activeTab.value = 'student'
  184. let classList = totalList.value.find(i => i.active == true).class
  185. for (let i of classList) {
  186. i.active = false
  187. }
  188. item.active = true
  189. getStudent(item)
  190. }
  191. const changeStudent = (item) => {
  192. let classList = totalList.value.find(i => i.active == true).class
  193. let studentList = classList.find(i => i.active == true).student
  194. for (let i of studentList) {
  195. i.active = false
  196. }
  197. item.active = true
  198. }
  199. const goBcak = () => {
  200. navTo('pages/index/index', {})
  201. }
  202. const navToTest = () => {
  203. if (curSelected.value.length == 3) {
  204. navTo('pages/test/bmi', {
  205. student_id: curSelected.value[2].id,
  206. task_id: curSelected.value[1].task_id,
  207. })
  208. }
  209. }
  210. onLoad(() => {
  211. getGradeList()
  212. setCountdown()
  213. })
  214. onHide(() => {
  215. clearInterval(interval.value)
  216. })
  217. onUnload(() => {
  218. clearInterval(interval.value)
  219. })
  220. </script>
  221. <style scoped>
  222. .container-box {
  223. height: 100vh;
  224. width: 100%;
  225. background: linear-gradient(to bottom left, rgb(218, 233, 253), #fff, rgb(218, 233, 253));
  226. position: relative;
  227. overflow: auto;
  228. }
  229. .back-class {
  230. position: absolute;
  231. top: 40upx;
  232. left: 46upx;
  233. width: 70upx;
  234. height: 70upx;
  235. }
  236. .countdown {
  237. position: absolute;
  238. top: 40upx;
  239. right: 46upx;
  240. font-weight: bold;
  241. font-size: 35upx;
  242. color: #2F3C42;
  243. line-height: 41upx;
  244. }
  245. .select-box {
  246. margin: 125upx auto 0;
  247. width: 680upx;
  248. height: 55vh;
  249. border-radius: 14upx;
  250. background: #fff;
  251. box-shadow: 0 0px 5px 1px #ccc;
  252. }
  253. .selected-box {
  254. margin: 25upx auto 0;
  255. width: 680upx;
  256. height: 15vh;
  257. line-height: 6vh;
  258. border-radius: 14upx;
  259. background: #fff;
  260. box-shadow: 0 0px 5px 1px #ccc;
  261. font-weight: bold;
  262. font-size: 28rpx;
  263. padding: 1.5vh 27upx;
  264. box-sizing: border-box;
  265. color: #0369E8;
  266. }
  267. .selected-info {
  268. display: flex;
  269. font-weight: 400;
  270. font-size: 28rpx;
  271. color: #2F3C42;
  272. }
  273. .selected-line {
  274. color: #ccc;
  275. padding: 0 10upx;
  276. }
  277. .next-btn {
  278. margin: 25upx auto 0;
  279. width: 389upx;
  280. height: 9vh;
  281. line-height: 9vh;
  282. border-radius: 14upx;
  283. background: #0369E8;
  284. color: #fff;
  285. font-weight: bold;
  286. font-size: 35rpx;
  287. text-align: center;
  288. }
  289. .ban-btn {
  290. margin: 25upx auto 0;
  291. width: 389upx;
  292. height: 9vh;
  293. line-height: 9vh;
  294. border-radius: 14upx;
  295. background: #ccc;
  296. color: #666;
  297. font-weight: bold;
  298. font-size: 35rpx;
  299. text-align: center;
  300. }
  301. .select-tab {
  302. display: flex;
  303. border-bottom: 1px solid #ccc;
  304. }
  305. .tab-img {
  306. width: 42upx;
  307. height: 42upx;
  308. margin-top: 34upx;
  309. }
  310. .tab-item {
  311. flex: 1;
  312. display: flex;
  313. justify-content: center;
  314. text-align: center;
  315. height: 10vh;
  316. line-height: 110upx;
  317. font-weight: bold;
  318. font-size: 28rpx;
  319. border-top-left-radius: 14upx;
  320. border-top-right-radius: 14upx;
  321. }
  322. .tab-item0 {
  323. color: rgb(3, 105, 232);
  324. background: #fff;
  325. }
  326. .tab-item1 {
  327. color: rgb(2, 193, 124);
  328. background: #fff;
  329. }
  330. .tab-item2 {
  331. color: rgb(211, 121, 13);
  332. background: #fff;
  333. }
  334. .tab-active-item0 {
  335. background: rgb(3, 105, 232);
  336. color: #fff;
  337. }
  338. .tab-active-item1 {
  339. background: rgb(2, 193, 124);
  340. color: #fff;
  341. }
  342. .tab-active-item2 {
  343. background: rgb(211, 121, 13);
  344. color: #fff;
  345. }
  346. .select-info {
  347. padding: 20upx 10upx 20upx 20upx;
  348. display: flex;
  349. flex-wrap: wrap;
  350. height: 40vh;
  351. overflow: auto;
  352. }
  353. .info-item {
  354. height: 69upx;
  355. width: 139upx;
  356. border-radius: 10upx;
  357. font-weight: bold;
  358. font-size: 21upx;
  359. text-align: center;
  360. line-height: 69upx;
  361. margin-right: 18upx;
  362. margin-bottom: 18upx;
  363. }
  364. .info-item0 {
  365. background: #F1F7FF;
  366. color: #0369E8;
  367. }
  368. .info-active-item0 {
  369. color: #fff;
  370. background: #0369E8;
  371. }
  372. .info-item1 {
  373. background: #EFFFF8;
  374. color: rgb(2, 193, 124);
  375. }
  376. .info-active-item1 {
  377. color: #EFFFF8;
  378. background: rgb(2, 193, 124);
  379. }
  380. .info-item2 {
  381. background: #FFFCF5;
  382. color: #D3790D;
  383. }
  384. .info-active-item2 {
  385. color: #FFFCF5;
  386. background: #D3790D;
  387. }
  388. </style>