QuestionTypeShow.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <!-- 不同类型问卷题目 的渲染 -->
  2. <template>
  3. <!-- 单选 -->
  4. <el-radio-group
  5. :disabled="!allowEdit"
  6. @change="HandleChange"
  7. v-model="questionVal"
  8. v-if="[0,3].includes(Number(questionType))"
  9. :class="{vertical:!isHorizontal}">
  10. <el-radio v-for="radioItem in questionSubOptions"
  11. :key="radioItem.id"
  12. :value="radioItem.id"
  13. >
  14. {{ radioItem.content }}
  15. </el-radio>
  16. </el-radio-group>
  17. <!-- 多选 -->
  18. <el-checkbox-group
  19. :disabled="!allowEdit"
  20. @change="HandleChange"
  21. v-model="questionVal"
  22. v-else-if="Number(questionType) === 1"
  23. :class="{vertical:!isHorizontal}">
  24. <el-checkbox
  25. v-for="checkItem in questionSubOptions"
  26. :key="checkItem.id"
  27. :label="checkItem.content"
  28. :value="checkItem.id"
  29. />
  30. </el-checkbox-group>
  31. <!-- 问答题 -->
  32. <el-input
  33. :disabled="!allowEdit"
  34. @change="HandleChange"
  35. v-model="questionVal"
  36. v-else-if="Number(questionType) === 2"
  37. :autosize="{ minRows:5, maxRows: 5 }"
  38. type="textarea"
  39. :rows="5"
  40. placeholder="不超过2000字"
  41. />
  42. <!-- 评价(分)题 5 -->
  43. <template v-else-if="Number(questionType) === 5 ">
  44. <!-- 评数题 -->
  45. <ul class="num_list_score" v-if="Number(evaluationType) === 0 && Number(questionScore)">
  46. <li v-for="value in Number(questionScore)"
  47. :key="value"
  48. :class="{active:questionVal == value,disabled:!allowEdit}"
  49. @click="allowEdit ? HandleNumberScoreChange(value) : ''">
  50. {{ value }}分
  51. </li>
  52. </ul>
  53. <!-- 评星题 -->
  54. <div :class="['star_list_score',{disabled:!allowEdit}]" v-else-if="Number(evaluationType) === 1 && Number(questionScore)">
  55. 非常不满意
  56. <el-rate size="large"
  57. v-model="questionVal"
  58. :disabled="!allowEdit"
  59. :colors="['#2e64fa','#2e64fa','#2e64fa']"
  60. :max="Number(questionScore)"
  61. @change="HandleChange"
  62. clearable />
  63. 非常满意
  64. </div>
  65. </template>
  66. </template>
  67. <script setup lang="ts">
  68. import {ref} from 'vue'
  69. interface Option {
  70. content: String
  71. score?: Number|String,
  72. id?: Number|string
  73. }
  74. const props = defineProps({
  75. questionType:{ //题目展示类型 单选0/多选1/问答2/评分单选3 / 评分题4
  76. type:[Number,String],
  77. required:true
  78. },
  79. isHorizontal:{ //单选/多选 选项 水平/垂直 排列
  80. type:Boolean,
  81. default:true,
  82. required:true
  83. },
  84. questionSubOptions:{ // 单选/多选 选项列表
  85. type:[Array<Option>,null],
  86. },
  87. evaluationType:{ //评分题 分值的展示形式 0 数字 1 星星
  88. type:[Number,String,null],
  89. },
  90. questionScore:{ // 评分题 题目的分值
  91. type:[Number,null]
  92. },
  93. allowEdit:{ //是否允许编辑
  94. type:Boolean,
  95. default:true
  96. }
  97. })
  98. const emit = defineEmits(['formChange'])
  99. const questionVal = ref()
  100. const HandleNumberScoreChange = (val:number)=>{
  101. questionVal.value = val;
  102. HandleChange(val)
  103. }
  104. const HandleChange = (val)=>{
  105. emit('formChange',val)
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. .el-checkbox-group,
  110. .el-radio-group{
  111. display: flex;
  112. flex-direction: row;
  113. gap: 5px 15px;
  114. flex-wrap: wrap;
  115. }
  116. .el-checkbox-group.vertical,
  117. .el-radio-group.vertical{
  118. display: flex;
  119. flex-direction: column;
  120. justify-content: flex-start;
  121. align-items: flex-start;
  122. gap:5px;
  123. }
  124. .el-checkbox-group,
  125. .el-radio-group
  126. {
  127. overflow: auto;
  128. :deep(.el-radio),
  129. :deep(.el-checkbox){
  130. display: flex;
  131. align-items: flex-start;
  132. height: auto;
  133. margin: 0;
  134. .el-radio__input,
  135. .el-checkbox__input{
  136. height: 21px;
  137. display: flex;
  138. align-items: center;
  139. }
  140. .el-radio__label,
  141. .el-checkbox__label{
  142. line-height: 21px;
  143. overflow: auto;
  144. word-break: break-all !important;
  145. white-space: normal !important;
  146. }
  147. }
  148. }
  149. // 评分题样式
  150. .num_list_score{
  151. display: flex;
  152. align-items: center;
  153. gap:16px;
  154. color: #CCCCCC;
  155. line-height: 1;
  156. font-size: 14px;
  157. flex-wrap: wrap;
  158. li{
  159. display: flex;
  160. justify-content: center;
  161. align-items: center;
  162. border-radius: 4px ;
  163. border: 1px solid #CCCCCC;
  164. width: 44px;
  165. height: 32px;
  166. background-color: white;
  167. cursor: pointer;
  168. &.active{
  169. background-color: #2E64FA;
  170. color: white;
  171. border:none;
  172. }
  173. &.disabled{
  174. &.active{
  175. background-color: #CCCCCC;
  176. }
  177. cursor: not-allowed !important;
  178. }
  179. }
  180. }
  181. // 评星题样式
  182. .star_list_score{
  183. display: flex;
  184. align-items: center;
  185. gap:16px;
  186. color: #CCCCCC;
  187. line-height: 1;
  188. font-size: 14px;
  189. word-break: keep-all;
  190. &.disabled{
  191. cursor: not-allowed;
  192. }
  193. .el-rate{
  194. display: flex;
  195. flex-wrap: wrap;
  196. gap:10px 20px;
  197. height: auto;
  198. :deep(.el-rate__item){
  199. .el-rate__icon{
  200. font-size: 24px;
  201. }
  202. }
  203. }
  204. }
  205. </style>