index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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.examStart';
  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. // .sort( (i,j) =>{
  39. // return oindex.indexOf(i.type) > oindex.indexOf(j.type)?1:-1;
  40. // })
  41. console.log( list.map( item=>{ return item.type}) )
  42. wx.setNavigationBarTitle({
  43. title: info.title+'-模拟考试'
  44. })
  45. _this.setData({
  46. list: list,
  47. info: info,
  48. startTime: startTime,
  49. remainTime: duration
  50. });
  51. _this.timeReduce()
  52. }
  53. })
  54. },
  55. timeReduce() {
  56. let _this = this
  57. let timer = setInterval(function() {
  58. let remainTime = _this.data.remainTime
  59. if (remainTime <= 0) {
  60. _this.timeOut()
  61. } else {
  62. _this.setData({
  63. remainTime: remainTime - 1,
  64. remainTimeStr: formatSeconds(remainTime),
  65. doTime: _this.data.doTime + 1
  66. });
  67. }
  68. }, 1000)
  69. _this.setData({
  70. timer: timer
  71. });
  72. },
  73. onUnload() {
  74. clearInterval(this.data.timer)
  75. },
  76. returnRecord() {
  77. // let id = this.data.id;
  78. this.setData({isFinish: true, modalShow:false})
  79. // wx.navigateTo({
  80. // url: `/pages/exam/read/index?id=${id}`
  81. // })
  82. },
  83. timeOut() {
  84. clearInterval(this.data.timer)
  85. this.setData({
  86. timeOutShow: true
  87. });
  88. },
  89. radioChange( e ){
  90. let index = e.currentTarget.dataset.index;
  91. let list = this.data.list
  92. list[index].select = +e.detail.value
  93. console.log("select", index, list[index].select )
  94. this.setData( {list} );
  95. },
  96. checkboxChange( e ){
  97. let index = e.currentTarget.dataset.index;
  98. let list = this.data.list
  99. list[index].select = +e.detail.value.sort().join("")
  100. let result = ""+list[index].result
  101. if (list[index].select == result ){
  102. list[index]._select = true
  103. }
  104. for( let i in e.detail.value){
  105. if(result.indexOf( e.detail.value[i] )==-1 ){
  106. list[index]._select = true
  107. }
  108. }
  109. this.setData( {list} );
  110. },
  111. formSubmit: function(e) {
  112. let _this = this
  113. let force = this.data.remainTime < 3;
  114. let isFinish = true;
  115. wx.showLoading({
  116. title: '提交中',
  117. mask: true
  118. })
  119. let info = this.data.info;
  120. let param ={};
  121. param.groupId = info.groupId;
  122. param.paperId = info.paperId;
  123. param.answers = [];
  124. param.result = [];
  125. param.correct = 0;
  126. param.counter = this.data.list.length
  127. param.groupName = info.title;
  128. param.useTime = this.data.doTime
  129. param.duration = info.duration
  130. param.startTime = this.data.startTime;
  131. let errIds = [];
  132. for( let i=0; i< this.data.list.length; i++){
  133. let item = this.data.list[i];
  134. param.answers.push( item.answerId );
  135. param.result.push( item.select || 0);
  136. if( item.select == item.result){
  137. param.correct += 1
  138. }else{
  139. if( item.select ) errIds.push( item.answerId)
  140. }
  141. if( !item.select ) isFinish = false
  142. }
  143. // if( !isFinish && !force){
  144. // app.message("还未完成", 'error')
  145. // wx.hideLoading()
  146. // return
  147. // }
  148. param.result = param.result.join(",")
  149. param.answers = param.answers.join(",")
  150. param.errors = errIds.join(",")
  151. param.isRedo = this.data.redo?1:0;
  152. app.formPost('Exam.ExamSubmit', param).then(res => {
  153. if (res.code === 200) {
  154. _this.setData({
  155. id: res.data.id,
  156. modalShow: true,
  157. result:param,
  158. });
  159. if (this.data.timer) {
  160. clearInterval(this.data.timer)
  161. }
  162. } else {
  163. app.message(res.msg, 'error')
  164. }
  165. wx.hideLoading()
  166. })
  167. }
  168. })