answer.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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, index, maxIndex} = this.data;
  39. if( index > maxIndex) {
  40. util.showMsg("这题还未做过");
  41. return;
  42. }
  43. if( showResult ) {
  44. info.select = info.result;
  45. }else{
  46. info.select = 0
  47. }
  48. this.setData({showResult, info})
  49. },
  50. onShow: function(){
  51. app.checkLogin( userInfo =>{
  52. this.setData({userInfo, index:-1})
  53. this.loadAnswer()
  54. })
  55. },
  56. loadAnswer( ){
  57. let {groupId, type, showResult} = this.data;
  58. let param = {groupId, type, index: this.data.index};
  59. app.formPost('Exam.LoadAnswerLimitNew', param).then(res => {
  60. if (res.code ==200) {
  61. let {unfinish, info, total, maxIndex, index} = res.data
  62. let answerId = info&&info.answerId||0;
  63. if( showResult) info.select = info.result;
  64. this.setData({unfinish, total, info,index, answerId, maxIndex})
  65. wx.pageScrollTo({
  66. scrollTop: 0
  67. })
  68. }
  69. })
  70. },
  71. radioChange( e ){
  72. let cid=e.currentTarget.dataset.cid;
  73. let info = this.data.info
  74. info.select = +e.detail.value
  75. if( info.child ){
  76. info.child[cid].select = +e.detail.value
  77. }
  78. this.setData( {info} );
  79. },
  80. checkboxChange( e ){
  81. let cid=e.currentTarget.dataset.cid;
  82. let info = this.data.info
  83. info.select = +e.detail.value.sort().join("")
  84. let result = ""+info.result
  85. if (info.select == result ){
  86. info._select = true
  87. }else{
  88. for( let i in e.detail.value){
  89. if(result.indexOf( e.detail.value[i] )==-1 ){
  90. info._select = true
  91. }
  92. }
  93. }
  94. if( info.child ){
  95. info.child[cid].select = info.select
  96. }
  97. this.setData( {info} );
  98. },
  99. restartAnswer(){
  100. this.setData({index:0, showResult:false})
  101. this.loadAnswer()
  102. },
  103. prevAnswer( e ){
  104. let {index}= this.data
  105. if( index <= 0 ) {
  106. util.showMsg("已经在第一题")
  107. return
  108. }
  109. index--;
  110. this.setData({index,isConfirm:false})
  111. this.loadAnswer()
  112. },
  113. nextAnswer( e ){
  114. let {index, maxIndex, total,isConfirm}= this.data
  115. if( index >= total-1 ) {
  116. util.showMsg("已经最后一题")
  117. return;
  118. }
  119. if( index >= maxIndex && !isConfirm){
  120. util.showMsg("还未作答");
  121. return;
  122. }
  123. index++;
  124. this.setData({index,isConfirm:false})
  125. this.loadAnswer()
  126. },
  127. confirmAnswer(){
  128. let {id, groupId, type,answerId, index} = this.data
  129. let param ={id, groupId, answerId, index, type};
  130. app.formPost('Exam.finishAnswerLimitNew', param).then( res=>{
  131. if( res.code == 200){
  132. this.setData({isConfirm:true})
  133. }
  134. })
  135. }
  136. })