timeGroup.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view class="container">
  3. <!-- 时间组列表区域 -->
  4. <view class="time_list" v-if="timeGroups.length">
  5. <!-- 每一个时间组区域 -->
  6. <view class="time_item" v-for="item in timeGroups" :key="item.id" @click="handleClickItem(item)">
  7. <view class="item_left">
  8. <view class="top">{{ item.name }}</view>
  9. <view class="bottom">{{ item.remark }}</view>
  10. </view>
  11. <radio color="#0061FF" style="transform: scale(0.9)" :checked="item.isChecked" />
  12. </view>
  13. </view>
  14. <!-- 按钮区域 -->
  15. <view class="btns" v-if="timeGroups.length">
  16. <view class="cancel" @click="handleCancel">取消</view>
  17. <view class="confirm" @click="handleConfirm">确认</view>
  18. </view>
  19. <!-- 没有数据时展示的页面 -->
  20. <NoData v-else />
  21. </view>
  22. </template>
  23. <script setup>
  24. import { ref } from 'vue'
  25. import { onLoad } from '@dcloudio/uni-app'
  26. import { myRequest } from '@/utils/api.js'
  27. import { decryptDes } from '@/utils/des.js'
  28. import NoData from '@/components/noData.vue'
  29. // 时间组列表
  30. const timeGroups = ref([])
  31. // 学生ID集合
  32. const ids = ref([])
  33. onLoad((options) => {
  34. ids.value = JSON.parse(options.ids)
  35. getTimeGroups()
  36. })
  37. // 获取时间组列表数据
  38. const getTimeGroups = async () => {
  39. const res = await myRequest({
  40. url: '/wanzai/api/smartUser/timeGroups'
  41. })
  42. // console.log(res)
  43. const result = JSON.parse(decryptDes(res.data))
  44. // console.log(result)
  45. timeGroups.value = result
  46. timeGroups.value.forEach((ele) => {
  47. ele.isChecked = false
  48. })
  49. }
  50. // 点击每一个时间组的回调
  51. const handleClickItem = (item) => {
  52. timeGroups.value.forEach((ele) => {
  53. ele.isChecked = false
  54. })
  55. item.isChecked = !item.isChecked
  56. }
  57. // 点击取消按钮回调
  58. const handleCancel = () => {
  59. uni.navigateBack(1)
  60. }
  61. // 点击确认按钮回调
  62. const handleConfirm = async () => {
  63. // 判断是否选择了时间组
  64. const flag = timeGroups.value.find((ele) => ele.isChecked)
  65. if (!flag) {
  66. uni.showToast({
  67. title: '请选择时间组',
  68. icon: 'none',
  69. mask: true
  70. })
  71. } else {
  72. const timeGroupId = flag.id
  73. const res = await myRequest({
  74. url: '/wanzai/api/smartUser/setUserTimeGroup',
  75. method: 'post',
  76. data: {
  77. ids: ids.value,
  78. timeGroupId
  79. }
  80. })
  81. // console.log(res)
  82. uni.showToast({
  83. title: res.message,
  84. icon: 'none',
  85. mask: true
  86. })
  87. if (res.code == 200) {
  88. setTimeout(() => {
  89. uni.reLaunch({
  90. url: '/pages/studentManage/studentManage'
  91. })
  92. }, 1500)
  93. }
  94. }
  95. }
  96. </script>
  97. <style lang="scss" scoped>
  98. .container {
  99. min-height: 100vh;
  100. background-color: #f1f6fe;
  101. .time_list {
  102. padding-top: 25rpx;
  103. margin: auto;
  104. width: 710rpx;
  105. min-height: 70vh;
  106. .time_item {
  107. display: flex;
  108. justify-content: space-between;
  109. align-items: center;
  110. padding: 0 28rpx;
  111. margin-bottom: 20rpx;
  112. height: 128rpx;
  113. background-color: #fff;
  114. .item_left {
  115. display: flex;
  116. flex-direction: column;
  117. justify-content: space-between;
  118. height: 80rpx;
  119. .top {
  120. font-size: 28rpx;
  121. }
  122. .bottom {
  123. font-size: 24rpx;
  124. color: #b3b3b3;
  125. }
  126. }
  127. }
  128. }
  129. .btns {
  130. display: flex;
  131. justify-content: space-evenly;
  132. padding: 70rpx 0;
  133. height: 100rpx;
  134. font-size: 32rpx;
  135. .cancel {
  136. display: flex;
  137. justify-content: center;
  138. align-items: center;
  139. width: 297rpx;
  140. border-radius: 8rpx;
  141. color: #0061ff;
  142. border: 1rpx solid #0061ff;
  143. }
  144. .confirm {
  145. display: flex;
  146. justify-content: center;
  147. align-items: center;
  148. width: 297rpx;
  149. border-radius: 8rpx;
  150. color: #fff;
  151. background-color: #0061ff;
  152. }
  153. }
  154. }
  155. </style>