random-roll-call.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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="cartoonHeadImg ? item.student_cartoon_photo : item.student_photo+'?x-image-process=style/square400'"></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. cartoonHeadImg : {
  23. default : true,
  24. },
  25. },
  26. data() {
  27. return {
  28. show: false,
  29. num: 3,
  30. stuList: [],
  31. checkList : [],
  32. }
  33. },
  34. computed: {
  35. viewList() {
  36. let list = [];
  37. for (var i = 0; i < this.num; i++) {
  38. if (this.stuList[i]) {
  39. list.push(this.stuList[i])
  40. } else {
  41. list.push({
  42. isEmpty : true,
  43. id: i,
  44. student_cartoon_photo: 'https://zhxy.obs.cn-hz1.ctyun.cn/static/student_icon/B6.png',
  45. student_photo: 'https://zhxy.obs.cn-hz1.ctyun.cn/static/student_icon/B6.png',
  46. title: '匿名'
  47. })
  48. }
  49. }
  50. return list;
  51. }
  52. },
  53. methods: {
  54. open() {
  55. this.show = true;
  56. },
  57. numChange(e){
  58. this.stuList = [];
  59. this.checkList = [];
  60. },
  61. toCheck(item){
  62. let index = this.checkList.indexOf(item.id)
  63. if (index >= 0) {
  64. this.checkList.splice(index, 1);
  65. } else {
  66. this.checkList.push(item.id);
  67. }
  68. },
  69. makeRandom() {
  70. this.checkList = [];
  71. let max = this.list.length - 1;
  72. let numList = this.generateUniqueRandomNumbers(this.num, 0, max);
  73. this.stuList = [];
  74. this.viewList.forEach((item, index) => {
  75. setTimeout(() => {
  76. this.stuList.push(this.list[numList[index]])
  77. this.checkList.push(this.list[numList[index]].id);
  78. }, 40 * index);
  79. })
  80. },
  81. // 生成随机数
  82. makeRandomNum(max) {
  83. let min = 1;
  84. return Math.floor(Math.random() * (max - min + 1)) + min;
  85. },
  86. // 生成不同数值的随机数
  87. generateUniqueRandomNumbers(count, min, max) {
  88. let result = [];
  89. while (result.length < count) {
  90. let randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
  91. if (result.indexOf(randomNum) === -1) {
  92. result.push(randomNum);
  93. }
  94. }
  95. return result;
  96. },
  97. }
  98. }
  99. </script>
  100. <style>
  101. /deep/ .content {
  102. background-image: url('https://zhxy.obs.cn-hz1.ctyun.cn:443/static/desk_bg/class_bj.jpg');
  103. background-size: auto;
  104. border: 1px solid #0d5396;
  105. }
  106. /deep/ .el-dialog__header {
  107. background: #022c5a80;
  108. border-bottom: 2px solid #051d37;
  109. }
  110. /deep/ .el-dialog__title {
  111. color: #fff;
  112. }
  113. /deep/ .el-dialog__body {
  114. background-color: rgba(255, 255, 255, .12);
  115. }
  116. .user-check{
  117. position: absolute;
  118. right: -10px;
  119. top: -10px;
  120. font-size: 30px;
  121. color: red;
  122. background-color: #fff;
  123. border-radius: 100px;
  124. overflow: hidden;
  125. }
  126. .el-icon-success{
  127. color: #e61010;
  128. }
  129. .el-icon-circle-check{
  130. color: #d1d1d1;
  131. }
  132. .user-item {
  133. /* float: left; */
  134. position: relative;
  135. margin: 20px;
  136. cursor: pointer;
  137. }
  138. </style>