answer.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // pages/contest/answer/answer.js
  2. import {
  3. answer
  4. } from '../../../api/api.js'
  5. let timer
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. pagination: {
  12. page: 1,
  13. rows: 10
  14. },
  15. show: false,
  16. pattern: false,
  17. isupdate: false,
  18. paperId: '',
  19. paperScore: 0,
  20. questionWrong: '',
  21. questionList: [],
  22. questionTotal: [],
  23. chooseList: [],
  24. time: 0
  25. },
  26. attendContest () {
  27. answer.attendContest({reqdata:{}},r => {
  28. let {paperId,questions} = r.object
  29. this.setData({
  30. paperId,
  31. questionTotal: questions,
  32. questionList: questions.filter((item,index)=>index<10)
  33. })
  34. })
  35. },
  36. showToggle(e) {
  37. this.setData({
  38. show: !this.data.show
  39. })
  40. },
  41. patternToggle (e) {
  42. this.setData({
  43. pattern: !this.data.pattern
  44. })
  45. this.showToggle()
  46. this.bindNavTagger({currentTarget:{dataset:{index:1}}})
  47. },
  48. updateTagger (e) {
  49. this.setData({
  50. pattern: false,
  51. isupdate: true
  52. })
  53. this.bindNavTagger({currentTarget:{dataset:{index:1}}})
  54. },
  55. bindNavTagger(e) {
  56. let i = e.currentTarget.dataset.index
  57. this.setData({
  58. ['pagination.page']: i-0
  59. },()=>{
  60. if (wx.pageScrollTo) {
  61. wx.pageScrollTo({
  62. scrollTop: 0
  63. })
  64. } else {
  65. wx.showModal({
  66. title: '提示',
  67. content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
  68. })
  69. }
  70. this.setData({
  71. questionList: this.data.questionTotal.filter((item,index)=>index>=(i-1)*10&&index<i*10)
  72. })
  73. })
  74. },
  75. clickChoose (e) {
  76. let {questionindex,index} = e.currentTarget.dataset
  77. let {chooseList} = this.data
  78. chooseList[questionindex] = index
  79. this.setData({
  80. chooseList
  81. }, () => {
  82. console.log(chooseList);
  83. })
  84. },
  85. clickConfim (e) {
  86. let {paperId,chooseList,questionTotal,time} = this.data
  87. let paperScore = 0
  88. let questionWrong = []
  89. questionTotal.forEach((item,index) => {
  90. (chooseList[index]||chooseList[index]==0)&&item.options[chooseList[index]].optionAnswer
  91. ? paperScore += 2
  92. : questionWrong.push({[item.id]: (chooseList[index]||chooseList[index]==0)?item.options[chooseList[index]].optionId:''})
  93. })
  94. answer.submitUserAnswer({reqdata:{
  95. paperId,
  96. userId: wx.getStorageSync('id'),
  97. questionWrong: JSON.stringify(questionWrong),
  98. paperScore,
  99. paperDuration:time
  100. }},r => {
  101. wx.navigateTo({
  102. url: `/pages/contest/score/score?rank=${r.object}&score=${paperScore}`,
  103. })
  104. })
  105. },
  106. /**
  107. * 生命周期函数--监听页面加载
  108. */
  109. onLoad: function (options) {
  110. this.attendContest()
  111. timer = setInterval(() => {
  112. this.setData({
  113. time: ++this.data.time
  114. })
  115. }, 1000)
  116. },
  117. /**
  118. * 生命周期函数--监听页面初次渲染完成
  119. */
  120. onReady: function () {
  121. },
  122. /**
  123. * 生命周期函数--监听页面显示
  124. */
  125. onShow: function () {
  126. },
  127. /**
  128. * 生命周期函数--监听页面隐藏
  129. */
  130. onHide: function () {
  131. },
  132. /**
  133. * 生命周期函数--监听页面卸载
  134. */
  135. onUnload: function () {
  136. clearInterval(timer)
  137. },
  138. /**
  139. * 页面相关事件处理函数--监听用户下拉动作
  140. */
  141. onPullDownRefresh: function () {
  142. },
  143. /**
  144. * 页面上拉触底事件的处理函数
  145. */
  146. onReachBottom: function () {
  147. },
  148. /**
  149. * 用户点击右上角分享
  150. */
  151. onShareAppMessage: function () {
  152. }
  153. })