answer.js 3.1 KB

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