answer.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. let app = getApp()
  2. const util = require("../../../utils/util")
  3. Page({
  4. data: {
  5. preList:["A","B","C", "D", "E", "F"],
  6. info:{},
  7. total:0,
  8. unfinish:0,
  9. answerId:0,
  10. type:1,
  11. showResult: false,
  12. types:{
  13. 1:'判断题',
  14. 2:'单选题',
  15. 3:'多选题',
  16. 4:'案例题'
  17. },
  18. groupId:0
  19. },
  20. onLoad: function(options) {
  21. let groupId = +options.groupId||1;
  22. let type = +options.type||1;
  23. let total = +options.count ||0;
  24. this.setData({ groupId, type, total });
  25. },
  26. onChange(event){
  27. const showResult = event.detail.value;
  28. let {info} = this.data;
  29. if( showResult ) {
  30. info.select = info.result;
  31. }else{
  32. info.select = 0
  33. }
  34. this.setData({showResult, info})
  35. },
  36. onShow: function(){
  37. app.checkLogin( userInfo =>{
  38. this.setData({userInfo, from:0})
  39. this.loadAnswer()
  40. })
  41. },
  42. loadAnswer( ){
  43. let {groupId, type, showResult} = this.data
  44. app.formPost('Exam.LoadAnswerLimit', {groupId, type}).then(res => {
  45. if (res.code ==200) {
  46. let {unfinish, info, total} = res.data
  47. let answerId = info&&info.answerId||0;
  48. if( showResult) info.select = info.result;
  49. this.setData({unfinish, total, info, answerId})
  50. }
  51. })
  52. },
  53. checkAnswer( e ){
  54. let item = this.data.item;
  55. if( !item.select ){
  56. app.message("还未作答", 'error')
  57. return;
  58. }
  59. let param = {answerId: item.answerId}
  60. // 多选
  61. if( item.type == mulSelect ){
  62. item.correct = item.select.join("") == item.result;
  63. }else{
  64. item.correct = item.select == item.result;
  65. }
  66. param.correct = item.correct?1:0
  67. // 打开下一题
  68. app.formPost('Exam.EditErrorAnswer', param).then(res => {
  69. this.setData({item, next:true})
  70. })
  71. },
  72. radioChange( e ){
  73. let info = this.data.info
  74. info.select = +e.detail.value
  75. this.setData( {info} );
  76. },
  77. checkboxChange( e ){
  78. let info = this.data.info
  79. info.select = +e.detail.value.sort().join("")
  80. let result = ""+info.result
  81. if (info.select == result ){
  82. info._select = true
  83. }else{
  84. for( let i in e.detail.value){
  85. if(result.indexOf( e.detail.value[i] )==-1 ){
  86. info._select = true
  87. }
  88. }
  89. }
  90. this.setData( {info} );
  91. },
  92. restartAnswer(){
  93. let {groupId, type, total, showResult} = this.data
  94. let answerId=0
  95. let unfinish = total
  96. app.formPost('Exam.finishAnswerLimit', {groupId, answerId, type}).then(res => {
  97. if (res.code ==200) {
  98. let info = res.data
  99. let answerId = info.answerId
  100. if( showResult) info.select = info.result;
  101. this.setData({info, answerId, unfinish})
  102. }
  103. })
  104. },
  105. finishAnswer( e ){
  106. let action = e.currentTarget.dataset.action;
  107. let {groupId, unfinish, type, showResult, total} = this.data
  108. let correct = this.data.info.select == this.data.info.result?1:0;
  109. let answerId = total-unfinish;
  110. if( action == "prev"){
  111. if( total<=unfinish ) {
  112. util.showMsg("已经在第一题")
  113. return
  114. }
  115. answerId-=1
  116. }else{
  117. if( unfinish<1 ) {
  118. util.showMsg("已经最后一题")
  119. return;
  120. }
  121. answerId+=1
  122. }
  123. console.log("finishAnswer", action, answerId, unfinish, total)
  124. app.formPost('Exam.finishAnswerLimit', {groupId, answerId, type, correct, action}).then(res => {
  125. if (res.code ==200) {
  126. let info = res.data
  127. let answerId = info.answerId
  128. unfinish = (action == "prev")?(unfinish+1):(unfinish-1);
  129. if( showResult) info.select = info.result;
  130. this.setData({info, answerId, unfinish})
  131. }
  132. })
  133. }
  134. })