datiing.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div class="datiing" v-if="currentTimu.question" @click.stop>
  3. <p class="qtitle">第{{currentIdx+1}}/{{tiku.answer.length}}题</p>
  4. <div class="dati">
  5. <p class="title">{{ currentTimu.question }}</p>
  6. <ul>
  7. <li
  8. :class="{active:timuselect == item.val && !isSubmit}"
  9. v-for="(item, i) in currentTimu.answer"
  10. @click="timuselect = item.val"
  11. :key="i"
  12. >
  13. <div>
  14. <img
  15. v-if="item.val == currentTimu.correct && isSubmit"
  16. :src="require(`@/assets/images/btnlist/dui.png`)"
  17. />
  18. <img
  19. v-if="
  20. item.val == timuselect &&
  21. item.val != currentTimu.correct &&
  22. isSubmit
  23. "
  24. :src="require(`@/assets/images/btnlist/cuo_${theme}.png`)"
  25. />
  26. <span v-if="timuselect == item.val && !isSubmit"></span>
  27. </div>
  28. <span>{{ "ABCD"[i] }}.{{ item.name }}</span>
  29. </li>
  30. </ul>
  31. </div>
  32. <div class="dati_btn">
  33. <span class="active" @click="handleNext">{{
  34. canNext ? "下一题" : "确认"
  35. }}</span>
  36. </div>
  37. </div>
  38. </template>
  39. <script>
  40. import { getQuestionGroupDetail, submitAnswers } from "@/config/api";
  41. export default {
  42. props: ["timu"],
  43. data() {
  44. return {
  45. tiku: {},
  46. currentIdx: 0,
  47. timuselect: "",
  48. isSubmit: false,
  49. canNext: false,
  50. correctNum: 0,
  51. correctRate: 0,
  52. };
  53. },
  54. computed: {
  55. currentTimu() {
  56. return this.tiku.answer ? this.tiku.answer[this.currentIdx] || {} : {};
  57. },
  58. },
  59. watch: {
  60. currentIdx(newVal) {
  61. if (newVal >= this.tiku.answer.length) {
  62. this.correctRate = Math.floor(
  63. (this.correctNum / this.tiku.answer.length) * 100
  64. );
  65. this.submitAnswers()
  66. }
  67. },
  68. },
  69. methods: {
  70. reset() {
  71. this.canNext = false;
  72. this.isSubmit = false;
  73. this.timuselect = "";
  74. },
  75. handleNext() {
  76. if (this.timuselect == this.currentTimu.correct || this.canNext) {
  77. if (this.timuselect == this.currentTimu.correct) {
  78. this.correctNum++;
  79. }
  80. this.reset();
  81. this.currentIdx++;
  82. } else {
  83. this.isSubmit = true;
  84. this.canNext = true;
  85. }
  86. },
  87. submitAnswers() {
  88. submitAnswers(
  89. {
  90. percent: this.correctRate,
  91. questionGroupId: this.tiku.entity.id,
  92. score: this.correctNum,
  93. userId: this.userInfo.id,
  94. },
  95. (res) => {
  96. this.$bus.$emit("datiing", {
  97. correctNum: this.correctNum,
  98. datiing: false,
  99. correctRate: this.correctRate,
  100. challengesuccess: this.correctRate >= 50,
  101. });
  102. console.log(res);
  103. }
  104. );
  105. },
  106. getDetail() {
  107. getQuestionGroupDetail({ id: this.timu.id}, (res) => {
  108. res.data.answer = res.data.answer.map((item) => {
  109. item.answer = JSON.parse(item.answer);
  110. return item;
  111. });
  112. this.tiku = res.data;
  113. });
  114. },
  115. },
  116. mounted() {
  117. this.getDetail();
  118. },
  119. };
  120. </script>
  121. <style lang="less" scoped>
  122. .datiing {
  123. width: 100%;
  124. height: 100%;
  125. .qtitle {
  126. color: #fff;
  127. margin-top: 6px;
  128. }
  129. .dati {
  130. width: 83%;
  131. height: 62%;
  132. overflow-y: auto;
  133. margin: 0 auto;
  134. margin-top: 100px;
  135. padding: 0 10px;
  136. }
  137. .dati_btn {
  138. > span {
  139. padding: 0 40px;
  140. border-radius: 5px;
  141. }
  142. }
  143. }
  144. </style>