SingleSelectQuestionBatchFill.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <!-- 单选题 批量填答 -->
  2. <template>
  3. <div class="batch_question">
  4. <!-- 题目行 -->
  5. <QuestionTitleComponent :titleMsg="titleMsg" :titleIndex="titleIndex"/>
  6. <Table :hidePagination="true"
  7. :tableColumns="tableColumns"
  8. :tableData="tableData">
  9. <template v-for="column in tableColumns.slice(1)"
  10. v-slot:[column.name]="{row}" :key="column.name">
  11. <div class="select_cell" :class="{disabled:!allowEdit}" @click="allowEdit ? HandleCheck(row,column.name,!row[column.name]) : ''">
  12. <img :src="row[column.name] ? selectIcon : (allowEdit ? singleUnselectIcon :unselectDisabledIcon) " alt="">
  13. </div>
  14. </template>
  15. </Table>
  16. </div>
  17. </template>
  18. <script setup lang="ts">
  19. import { onMounted, ref, watch } from 'vue';
  20. import QuestionTitleComponent from '../QuestionTitleComponent.vue';
  21. import Table from '@/baseComponents/Table.vue';
  22. import { tableColumns } from './table.js';
  23. import selectIcon from '@/assets/studentQuestionnaire/select_icon.png'
  24. import unselectDisabledIcon from '@/assets/studentQuestionnaire/unselect_disabled_icon.png'
  25. import singleUnselectIcon from '@/assets/studentQuestionnaire/single_unselect.svg'
  26. interface TitleMsg {
  27. questionTitleName:string,
  28. questionType:number
  29. }
  30. interface TableColumn {
  31. name:string,
  32. label:string,
  33. width:string,
  34. fixed:string,
  35. align:string,
  36. minWdth:string,
  37. custom:boolean,
  38. }
  39. const props = defineProps({
  40. titleMsg:{
  41. type:Object as () => TitleMsg,
  42. required:true
  43. },
  44. titleIndex:{
  45. type:Number,
  46. required:true,
  47. },
  48. allowEdit:{
  49. type:Boolean,
  50. required:true
  51. },
  52. customTableColumns:{
  53. type:Array<TableColumn>,
  54. default:()=>[]
  55. },
  56. defaultTableData:{
  57. type:Array,
  58. default:()=>[]
  59. }
  60. })
  61. const emit = defineEmits(['questionAnswerChange'])
  62. const isFinishEdit = defineModel('isFinishEdit') //是否已经填写完成
  63. const tableData = ref<any[]>([])
  64. // 处选项的选中
  65. const HandleCheck = (row,key,val)=>{
  66. // 控制一行只选一个
  67. tableColumns.value.slice(1).map(item=>{
  68. row[item.name] = false
  69. })
  70. row[key] = val
  71. emit('questionAnswerChange',tableData.value)
  72. }
  73. watch(()=>props.defaultTableData,(newVal)=>{
  74. console.log('传递的表数据变化了---',newVal)
  75. tableData.value = newVal
  76. emit('questionAnswerChange',tableData.value)
  77. },{immediate:true})
  78. watch(()=>tableData.value,(newVal)=>{
  79. console.log('当前表格数据变化了',)
  80. let isFinish = true
  81. newVal.map(row=>{
  82. // 选项没有被勾选
  83. if(Object.values(row).filter(val=>val === true).length < 1){
  84. isFinish = false
  85. }
  86. })
  87. // 当前问卷全部填写完成
  88. if(isFinish){
  89. isFinishEdit.value = true
  90. }else{
  91. // 当前问卷没有全部填写完成
  92. isFinishEdit.value = false
  93. }
  94. },{deep:true,immediate:true})
  95. watch(()=>props.customTableColumns,(newVal)=>{
  96. tableColumns.value = [
  97. {
  98. name:'teacher',
  99. label:'',
  100. width:'100',
  101. fixed:'',
  102. align:'center',
  103. minWdth:'',
  104. },
  105. ...newVal
  106. ]
  107. },{immediate:true,deep:true})
  108. </script>
  109. <style lang="scss" scoped>
  110. .batch_question{
  111. padding: 10px 20px;
  112. :deep(.el-table){
  113. tr th.el-table__cell {
  114. font-weight: 400;
  115. color: #666666;
  116. }
  117. }
  118. .select_cell{
  119. display: flex;
  120. align-items: center;
  121. justify-content: center;
  122. &.disabled{
  123. cursor: not-allowed;
  124. }
  125. img{
  126. width: 24px;
  127. height: 24px;
  128. }
  129. }
  130. }
  131. </style>