answer.js 2.6 KB

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