answer.js 3.5 KB

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