random-roll-call.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <el-dialog :visible.sync="show" title="随机点名" custom-class="content" center :close-on-click-modal="false"
  3. style="background-color: #00142f63;backdrop-filter: blur(4px);" width="640px">
  4. <view style="min-height: 250px;" class="ui-flex-center ui-flex-row">
  5. <view class="text-center user-item" v-for="(item, index) in viewList" :key="item.id" @click="toCheck(item)">
  6. <text v-if="!item.isEmpty" class="user-check" :class="[checkList.includes(item.id) ? 'el-icon-success' : 'el-icon-circle-check']"></text>
  7. <el-avatar :size="70" :src="item.student_cartoon_photo"></el-avatar>
  8. <view class="f34 text-center txt-white">{{item.title}}</view>
  9. </view>
  10. </view>
  11. <view class="text-center ui-mt40">
  12. <el-input-number v-model="num" :min="1" @change="numChange" label="确认人数"></el-input-number>
  13. <el-button class="ui-ml20" type="" @click="makeRandom">确认人数</el-button>
  14. <el-button class="ui-ml20" type="primary" @click="$emit('comment', stuList)">批量点评</el-button>
  15. </view>
  16. </el-dialog>
  17. </template>
  18. <script>
  19. export default {
  20. props: {
  21. list: {},
  22. },
  23. data() {
  24. return {
  25. show: false,
  26. num: 3,
  27. stuList: [],
  28. checkList : [],
  29. }
  30. },
  31. computed: {
  32. viewList() {
  33. let list = [];
  34. for (var i = 0; i < this.num; i++) {
  35. if (this.stuList[i]) {
  36. list.push(this.stuList[i])
  37. } else {
  38. list.push({
  39. isEmpty : true,
  40. id: i,
  41. student_cartoon_photo: 'https://zhxy.obs.cn-hz1.ctyun.cn/static/student_icon/B6.png',
  42. title: '匿名'
  43. })
  44. }
  45. }
  46. return list;
  47. }
  48. },
  49. methods: {
  50. open() {
  51. this.show = true;
  52. },
  53. numChange(e){
  54. this.stuList = [];
  55. this.checkList = [];
  56. },
  57. toCheck(item){
  58. let index = this.checkList.indexOf(item.id)
  59. if (index >= 0) {
  60. this.checkList.splice(index, 1);
  61. } else {
  62. this.checkList.push(item.id);
  63. }
  64. },
  65. makeRandom() {
  66. this.checkList = [];
  67. let max = this.list.length - 1;
  68. let numList = this.generateUniqueRandomNumbers(this.num, 0, max);
  69. this.stuList = [];
  70. this.viewList.forEach((item, index) => {
  71. setTimeout(() => {
  72. this.stuList.push(this.list[numList[index]])
  73. this.checkList.push(this.list[numList[index]].id);
  74. }, 40 * index);
  75. })
  76. },
  77. // 生成随机数
  78. makeRandomNum(max) {
  79. let min = 1;
  80. return Math.floor(Math.random() * (max - min + 1)) + min;
  81. },
  82. // 生成不同数值的随机数
  83. generateUniqueRandomNumbers(count, min, max) {
  84. let result = [];
  85. while (result.length < count) {
  86. let randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
  87. if (result.indexOf(randomNum) === -1) {
  88. result.push(randomNum);
  89. }
  90. }
  91. return result;
  92. },
  93. }
  94. }
  95. </script>
  96. <style>
  97. /deep/ .content {
  98. background-image: url('https://zhxy.obs.cn-hz1.ctyun.cn:443/static/desk_bg/class_bj.jpg');
  99. background-size: auto;
  100. border: 1px solid #0d5396;
  101. }
  102. /deep/ .el-dialog__header {
  103. background: #022c5a80;
  104. border-bottom: 2px solid #051d37;
  105. }
  106. /deep/ .el-dialog__title {
  107. color: #fff;
  108. }
  109. /deep/ .el-dialog__body {
  110. background-color: rgba(255, 255, 255, .12);
  111. }
  112. .user-check{
  113. position: absolute;
  114. right: -10px;
  115. top: -10px;
  116. font-size: 30px;
  117. color: red;
  118. background-color: #fff;
  119. border-radius: 100px;
  120. overflow: hidden;
  121. }
  122. .el-icon-success{
  123. color: #e61010;
  124. }
  125. .el-icon-circle-check{
  126. color: #d1d1d1;
  127. }
  128. .user-item {
  129. /* float: left; */
  130. position: relative;
  131. margin: 20px;
  132. cursor: pointer;
  133. }
  134. </style>