index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import {
  2. formatSeconds
  3. } from '../../../utils/util.js'
  4. let app = getApp()
  5. let mulSelect = 3
  6. Page({
  7. data: {
  8. list: [],
  9. redo: false,
  10. preList:["A","B","C", "D","E","F"],
  11. info:{},
  12. id:0,
  13. timer: null,
  14. doTime: 0,
  15. remainTime: 0,
  16. remainTimeStr: '',
  17. modalShow: false,
  18. isFinish: false,
  19. result: {},
  20. startTime: "",
  21. timeOutShow: false
  22. },
  23. onLoad: function(options) {
  24. let groupId = +options.id||3
  25. let redo = !!options.redo;
  26. this.setData({redo})
  27. let method = redo?'Exam.examreStart':'Exam.examStartLimit';
  28. let _this = this
  29. let oindex = [2,3,1]
  30. app.formPost(method, {groupId}).then(res => {
  31. if (res.code ==200) {
  32. let {startTime, info, list} = res.data;
  33. let duration = info.duration
  34. list = list.map(item=>{
  35. delete( item["select"])
  36. return item
  37. })
  38. wx.setNavigationBarTitle({
  39. title: info.title+'-模拟考试'
  40. })
  41. _this.setData({
  42. list: list,
  43. info: info,
  44. startTime: startTime,
  45. remainTime: duration
  46. });
  47. _this.timeReduce()
  48. }
  49. })
  50. },
  51. timeReduce() {
  52. let _this = this
  53. let timer = setInterval(function() {
  54. let remainTime = _this.data.remainTime
  55. if (remainTime <= 0) {
  56. _this.timeOut()
  57. } else {
  58. _this.setData({
  59. remainTime: remainTime - 1,
  60. remainTimeStr: formatSeconds(remainTime),
  61. doTime: _this.data.doTime + 1
  62. });
  63. }
  64. }, 1000)
  65. _this.setData({
  66. timer: timer
  67. });
  68. },
  69. onUnload() {
  70. clearInterval(this.data.timer)
  71. },
  72. returnRecord() {
  73. this.setData({isFinish: true, modalShow:false})
  74. },
  75. timeOut() {
  76. clearInterval(this.data.timer)
  77. this.setData({
  78. timeOutShow: true
  79. });
  80. },
  81. radioChange( e ){
  82. let index = e.currentTarget.dataset.index;
  83. let list = this.data.list
  84. list[index].select = +e.detail.value
  85. console.log("select", index, list[index].select )
  86. this.setData( {list} );
  87. },
  88. checkboxChange( e ){
  89. let index = e.currentTarget.dataset.index;
  90. let list = this.data.list
  91. list[index].select = +e.detail.value.sort().join("")
  92. let result = ""+list[index].result
  93. if (list[index].select == result ){
  94. list[index]._select = true
  95. }
  96. for( let i in e.detail.value){
  97. if(result.indexOf( e.detail.value[i] )==-1 ){
  98. list[index]._select = true
  99. }
  100. }
  101. this.setData( {list} );
  102. },
  103. formSubmit: function(e) {
  104. let _this = this
  105. let force = this.data.remainTime < 3;
  106. let isFinish = true;
  107. wx.showLoading({
  108. title: '提交中',
  109. mask: true
  110. })
  111. let info = this.data.info;
  112. let param ={};
  113. param.groupId = info.groupId;
  114. param.paperId = info.paperId;
  115. param.answers = [];
  116. param.result = [];
  117. param.correct = 0;
  118. param.counter = this.data.list.length
  119. param.groupName = info.title;
  120. param.useTime = this.data.doTime
  121. param.duration = info.duration
  122. param.startTime = this.data.startTime;
  123. let errIds = [];
  124. for( let i=0; i< this.data.list.length; i++){
  125. let item = this.data.list[i];
  126. param.answers.push( item.answerId );
  127. param.result.push( item.select || 0);
  128. if( item.select == item.result){
  129. param.correct += (item.result>5?2:1);
  130. }else{
  131. if( item.select ) errIds.push( item.answerId)
  132. }
  133. if( !item.select ) isFinish = false
  134. }
  135. param.result = param.result.join(",")
  136. param.answers = param.answers.join(",")
  137. param.errors = errIds.join(",")
  138. param.isRedo = this.data.redo?1:0;
  139. app.formPost('Exam.ExamSubmit', param).then(res => {
  140. if (res.code === 200) {
  141. _this.setData({
  142. id: res.data.id,
  143. modalShow: true,
  144. result:param,
  145. });
  146. if (this.data.timer) {
  147. clearInterval(this.data.timer)
  148. }
  149. } else {
  150. app.message(res.msg, 'error')
  151. }
  152. wx.hideLoading()
  153. })
  154. }
  155. })