random-roll-call.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. let max = this.list.length - 1;
  67. let numList = this.generateUniqueRandomNumbers(this.num, 0, max);
  68. this.stuList = [];
  69. this.viewList.forEach((item, index) => {
  70. setTimeout(() => {
  71. this.stuList.push(this.list[numList[index]])
  72. this.checkList.push(this.list[numList[index]].id);
  73. }, 40 * index);
  74. })
  75. },
  76. // 生成随机数
  77. makeRandomNum(max) {
  78. let min = 1;
  79. return Math.floor(Math.random() * (max - min + 1)) + min;
  80. },
  81. // 生成不同数值的随机数
  82. generateUniqueRandomNumbers(count, min, max) {
  83. let result = [];
  84. while (result.length < count) {
  85. let randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
  86. if (result.indexOf(randomNum) === -1) {
  87. result.push(randomNum);
  88. }
  89. }
  90. return result;
  91. },
  92. }
  93. }
  94. </script>
  95. <style>
  96. /deep/ .content {
  97. background-image: url('https://zhxy.obs.cn-hz1.ctyun.cn:443/static/desk_bg/class_bj.jpg');
  98. background-size: auto;
  99. border: 1px solid #0d5396;
  100. }
  101. /deep/ .el-dialog__header {
  102. background: #022c5a80;
  103. border-bottom: 2px solid #051d37;
  104. }
  105. /deep/ .el-dialog__title {
  106. color: #fff;
  107. }
  108. /deep/ .el-dialog__body {
  109. background-color: rgba(255, 255, 255, .12);
  110. }
  111. .user-check{
  112. position: absolute;
  113. right: -10px;
  114. top: -10px;
  115. font-size: 30px;
  116. color: red;
  117. background-color: #fff;
  118. border-radius: 100px;
  119. overflow: hidden;
  120. }
  121. .el-icon-success{
  122. color: #e61010;
  123. }
  124. .el-icon-circle-check{
  125. color: #d1d1d1;
  126. }
  127. .user-item {
  128. /* float: left; */
  129. position: relative;
  130. margin: 20px;
  131. cursor: pointer;
  132. }
  133. </style>