BuildPaperQuestionNested.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <div class="detail-question-part">
  3. <div class="detail-question-header">
  4. <div>
  5. <el-tag size="mini" effect="dark" type="success">{{
  6. question.questionType | questionType
  7. }}</el-tag>
  8. <span class="inline-middle margin-left-10"
  9. >试题总分:{{ totalScore }}分,</span
  10. >
  11. <span class="inline-middle margin-left-10">每题分数:</span>
  12. <el-input-number
  13. v-model="score"
  14. size="mini"
  15. :step="0.1"
  16. :min="0.1"
  17. :max="999"
  18. :controls="false"
  19. :precision="1"
  20. step-strictly
  21. @change="scoreChange"
  22. >
  23. </el-input-number>
  24. </div>
  25. <div>
  26. <el-button
  27. size="mini"
  28. type="text"
  29. icon="el-icon-edit"
  30. title="编辑"
  31. @click.stop="editQuestion"
  32. ></el-button>
  33. <el-button
  34. class="btn-danger"
  35. size="mini"
  36. type="text"
  37. icon="el-icon-delete"
  38. title="删除"
  39. @click.stop="removeQuestion"
  40. ></el-button>
  41. </div>
  42. </div>
  43. <div v-if="quesBody" class="detail-question-body">
  44. <rich-text :text-json="quesBody"></rich-text>
  45. </div>
  46. <div class="detail-question-subqs">
  47. <template v-for="(subq, sindex) in question.subQuestions">
  48. <build-paper-question-base
  49. :key="subq.id"
  50. v-model="subq.score"
  51. :question="subq"
  52. :question-serialno="sindex + 1"
  53. :show-action="false"
  54. @change="updateTotalScore"
  55. ></build-paper-question-base>
  56. </template>
  57. </div>
  58. </div>
  59. </template>
  60. <script>
  61. import BuildPaperQuestionBase from "./BuildPaperQuestionBase.vue";
  62. import { calcSum, deepCopy } from "@/plugins/utils";
  63. export default {
  64. name: "BuildPaperQuestionNested",
  65. components: { BuildPaperQuestionBase },
  66. props: {
  67. question: {
  68. type: Object,
  69. default() {
  70. return {};
  71. },
  72. },
  73. questionSerialno: {
  74. type: [String, Number],
  75. default: "",
  76. },
  77. },
  78. data() {
  79. return {
  80. score: undefined,
  81. quesBody: null,
  82. totalScore: 0,
  83. };
  84. },
  85. created() {
  86. if (this.questionSerialno) {
  87. if (this.question.quesBody) {
  88. this.quesBody = deepCopy(this.question.quesBody);
  89. this.quesBody.sections[0].blocks.unshift({
  90. type: "text",
  91. value: this.questionSerialno + "、",
  92. });
  93. } else {
  94. this.quesBody = {
  95. sections: [
  96. {
  97. blocks: [
  98. {
  99. type: "text",
  100. value: this.questionSerialno + "、",
  101. },
  102. ],
  103. },
  104. ],
  105. };
  106. }
  107. this.updateTotalScore();
  108. }
  109. },
  110. methods: {
  111. scoreChange() {
  112. // 这里通过引用关系直接修改了小题分值
  113. this.question.subQuestions.forEach((subq) => {
  114. subq.score = this.score;
  115. });
  116. this.updateTotalScore();
  117. },
  118. updateTotalScore() {
  119. this.totalScore = calcSum(
  120. this.question.subQuestions.map((item) => item.score || 0)
  121. );
  122. },
  123. editQuestion() {
  124. this.$emit("on-edit", this.question);
  125. },
  126. removeQuestion() {
  127. this.$emit("on-remove", this.question);
  128. },
  129. },
  130. };
  131. </script>