question-option.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <view class="questionBankAnswer-content-menu" @tap="post_answer(item, index)" :class="{'active-bg': answerRightFlag, //// 用户答题完毕,正确答案显示,用户
  3. // 错误答案显示 !((copy_post_status[current_timu.id] || show_beiti) && item.right_flg)
  4. 'kaoshi': question_type == 'exam',
  5. 'error-bg':answerWrongFlag}">
  6. <!-- 用户选择错误答案显示特殊样式 -->
  7. <view class="questionBankAnswer-content-num" :class="{'active': answerRightFlag, //// 用户答题完毕,正确答案显示,用户
  8. // 错误答案显示
  9. 'error':answerWrongFlag}">
  10. {{ item.answer_code === '1' ? 'A' : item.answer_code === '0' ? 'B' :
  11. item.answer_code }}
  12. <!-- 考试不显示 -->
  13. <!-- 1、用户提交答案以后显示 -->
  14. <!-- 2、背题模式显示 -->
  15. <view class="questionBankAnswer-dui">
  16. <image v-if="answerRightFlag && question_type != 'exam'" :src="static_media.img01" class="questionBankAnswer-dui-img"></image>
  17. <!-- (copy_post_status[current_timu.id] || show_beiti) && item.right_flg -->
  18. </view>
  19. </view>
  20. <view class="questionBankAnswer-content-txt">
  21. <uc-parse :node="getAsw(item.answer)"></uc-parse>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. props: {
  28. question_type: {
  29. type: String,
  30. default: 'test'
  31. },
  32. type: {
  33. type: String,
  34. default: '-1'
  35. },
  36. item: {
  37. type: Object,
  38. default: function() {
  39. return {}
  40. },
  41. },
  42. index: {
  43. type: Number,
  44. default: -1
  45. },
  46. show_beiti: {
  47. type: Boolean,
  48. default: true,
  49. },
  50. current_timu: {
  51. type: Object,
  52. default: function() {
  53. return {}
  54. },
  55. },
  56. copy_user_answer: {
  57. type: Object,
  58. default: function() {
  59. return {}
  60. },
  61. },
  62. copy_post_status: {
  63. type: Object,
  64. default: function() {
  65. return {}
  66. },
  67. },
  68. timu_index: {
  69. type: Number,
  70. default: -1
  71. }
  72. },
  73. data() {
  74. return {
  75. answerRightFlag: false,
  76. answerWrongFlag: false,
  77. }
  78. },
  79. computed: {
  80. static_media() {
  81. return {
  82. img01: this.$myConfig.localMedia + '/static/img/dui.png',
  83. }
  84. },
  85. },
  86. created() {},
  87. methods: {
  88. getAsw(item) {
  89. item = item.replace(/^[A-Z]\./,'')
  90. return item
  91. },
  92. setAnswerStyle(copy_user_answer) {
  93. this.answerRightFlag = false
  94. this.answerWrongFlag = false
  95. this.computedError(this.index, copy_user_answer)
  96. this.computedActive(this.item, this.index, copy_user_answer)
  97. },
  98. //选项的错误状态
  99. computedError(index, copy_user_answer) {
  100. if (this.question_type == 'exam') {
  101. this.answerWrongFlag = false
  102. return
  103. } else if (copy_user_answer && copy_user_answer[this.current_timu.id] && copy_user_answer[this
  104. .current_timu.id][index]) {
  105. if (copy_user_answer[this.current_timu.id][index].error_flg && ((this.current_timu.type == 2 &&
  106. this.copy_post_status[this.current_timu.id]) || (this.current_timu.type == 1 || this
  107. .current_timu.type == 3))) {
  108. this.answerWrongFlag = true
  109. return
  110. }
  111. this.answerWrongFlag = false
  112. return
  113. }
  114. this.answerWrongFlag = false
  115. },
  116. //选项的正确状态
  117. computedActive(item, index, copy_user_answer) {
  118. if (this.question_type == 'exam') {
  119. if (copy_user_answer && copy_user_answer[this.current_timu.id] && copy_user_answer[this.current_timu
  120. .id][index].active) {
  121. this.answerRightFlag = true
  122. return
  123. } else {
  124. this.answerRightFlag = false
  125. return
  126. }
  127. } else if (this.show_beiti || this.copy_post_status[this.current_timu.id]) {
  128. //背题模式 或者答完之后的
  129. if (item.right_flg) {
  130. this.answerRightFlag = true
  131. return
  132. }
  133. this.answerRightFlag = false
  134. return
  135. } else if (copy_user_answer && copy_user_answer[this.current_timu.id] && copy_user_answer[
  136. this.current_timu.id][index].active) {
  137. //答题模式 答完之后的
  138. this.answerRightFlag = true
  139. return
  140. }
  141. this.answerRightFlag = false
  142. },
  143. // 提交答案
  144. post_answer(item, index) {
  145. let copy_user_answer_this = JSON.parse(JSON.stringify(this.copy_user_answer))
  146. // 如果背题模式,不做处理
  147. if (this.show_beiti) {
  148. return;
  149. }
  150. // 如果是判断和单选。执行以下处理
  151. if (this.current_timu.type == 1 || this.current_timu.type == 3) {
  152. this.$nextTick(() => {
  153. if (copy_user_answer_this[this.current_timu.id]) {
  154. for (let i = 0, leng = copy_user_answer_this[this.current_timu.id].length; i <
  155. leng; i++) {
  156. copy_user_answer_this[this.current_timu.id].splice(i, 1, {
  157. ...copy_user_answer_this[this.current_timu.id][i],
  158. active: false,
  159. error_flg: false
  160. })
  161. }
  162. if (this.current_timu.right_answer.toString().toLowerCase().replace(/\s/g, '').indexOf(
  163. item.answer_code.toString().toLowerCase().replace(/\s/g, '')) === -1) {
  164. copy_user_answer_this[this.current_timu.id].splice(index, 1, {
  165. ...copy_user_answer_this[this.current_timu.id][index],
  166. active: true,
  167. error_flg: true
  168. })
  169. } else {
  170. copy_user_answer_this[this.current_timu.id].splice(index, 1, {
  171. ...copy_user_answer_this[this.current_timu.id][index],
  172. active: true,
  173. error_flg: false
  174. })
  175. }
  176. }
  177. this.$emit('set_copy_user_answer', copy_user_answer_this)
  178. this.$emit('post_answer_req', true)
  179. });
  180. } else if (this.current_timu.type == 2) {
  181. // 如果是多选。执行以下处理
  182. if (copy_user_answer_this[this.current_timu.id]) {
  183. this.$emit('set_sub_button_style', 'is_duoxuan_sub', false)
  184. if (copy_user_answer_this[this.current_timu.id][index]) {
  185. if (copy_user_answer_this[this.current_timu.id][index].active) {
  186. copy_user_answer_this[this.current_timu.id].splice(index, 1, {
  187. ...copy_user_answer_this[this.current_timu.id][index],
  188. active: false,
  189. error_flg: false
  190. })
  191. } else {
  192. if (this.current_timu.right_answer.toString().toLowerCase().replace(/\s/g, '').indexOf(item
  193. .answer_code.toString().toLowerCase().replace(/\s/g, '')) === -1) {
  194. copy_user_answer_this[this.current_timu.id].splice(index, 1, {
  195. ...copy_user_answer_this[this.current_timu.id][index],
  196. active: true,
  197. error_flg: true
  198. })
  199. } else {
  200. copy_user_answer_this[this.current_timu.id].splice(index, 1, {
  201. ...copy_user_answer_this[this.current_timu.id][index],
  202. active: true,
  203. error_flg: false
  204. })
  205. }
  206. }
  207. }
  208. }
  209. this.$emit('set_copy_user_answer', copy_user_answer_this)
  210. }
  211. },
  212. }
  213. }
  214. </script>