timeGroup.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. box-sizing: border-box;
  103. padding: 15rpx 0;
  104. margin: auto;
  105. width: 710rpx;
  106. height: calc(100vh - 245rpx);
  107. overflow-y: auto;
  108. .time_item {
  109. display: flex;
  110. justify-content: space-between;
  111. align-items: center;
  112. padding: 0 28rpx;
  113. margin-bottom: 20rpx;
  114. height: 128rpx;
  115. background-color: #fff;
  116. .item_left {
  117. display: flex;
  118. flex-direction: column;
  119. justify-content: space-between;
  120. height: 80rpx;
  121. .top {
  122. font-size: 28rpx;
  123. }
  124. .bottom {
  125. font-size: 24rpx;
  126. color: #b3b3b3;
  127. }
  128. }
  129. }
  130. }
  131. .btns {
  132. position: fixed;
  133. left: 0;
  134. right: 0;
  135. bottom: 0;
  136. display: flex;
  137. justify-content: space-evenly;
  138. padding: 70rpx 0;
  139. height: 100rpx;
  140. font-size: 32rpx;
  141. border-top: 1rpx solid #eee;
  142. background-color: #fff;
  143. .cancel {
  144. display: flex;
  145. justify-content: center;
  146. align-items: center;
  147. width: 297rpx;
  148. border-radius: 8rpx;
  149. color: #0061ff;
  150. border: 1rpx solid #0061ff;
  151. }
  152. .confirm {
  153. display: flex;
  154. justify-content: center;
  155. align-items: center;
  156. width: 297rpx;
  157. border-radius: 8rpx;
  158. color: #fff;
  159. background-color: #0061ff;
  160. }
  161. }
  162. }
  163. </style>