123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- // pages/contest/answer/answer.js
- import {
- answer
- } from '../../../api/api.js'
- let timer
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- pagination: {
- page: 1,
- rows: 10
- },
- show: false,
- pattern: false,
- isupdate: false,
- paperId: '',
- paperScore: 0,
- questionWrong: '',
- questionList: [],
- questionTotal: [],
- chooseList: [],
- time: 0
- },
- attendContest () {
- answer.attendContest({reqdata:{}},r => {
- let {paperId,questions} = r.object
- this.setData({
- paperId,
- questionTotal: questions,
- questionList: questions.filter((item,index)=>index<10)
- })
- })
- },
- showToggle(e) {
- this.setData({
- show: !this.data.show
- })
- },
- patternToggle (e) {
- this.setData({
- pattern: !this.data.pattern
- })
- this.showToggle()
- this.bindNavTagger({currentTarget:{dataset:{index:1}}})
- },
- updateTagger (e) {
- this.setData({
- pattern: false,
- isupdate: true
- })
- this.bindNavTagger({currentTarget:{dataset:{index:1}}})
- },
- bindNavTagger(e) {
- let i = e.currentTarget.dataset.index
- this.setData({
- ['pagination.page']: i-0
- },()=>{
- if (wx.pageScrollTo) {
- wx.pageScrollTo({
- scrollTop: 0
- })
- } else {
- wx.showModal({
- title: '提示',
- content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
- })
- }
- this.setData({
- questionList: this.data.questionTotal.filter((item,index)=>index>=(i-1)*10&&index<i*10)
- })
- })
- },
- clickChoose (e) {
- let {questionindex,index} = e.currentTarget.dataset
- let {chooseList} = this.data
- chooseList[questionindex] = index
- this.setData({
- chooseList
- }, () => {
- console.log(chooseList);
- })
- },
- clickConfim (e) {
- let {paperId,chooseList,questionTotal,time} = this.data
- let paperScore = 0
- let questionWrong = []
- questionTotal.forEach((item,index) => {
- (chooseList[index]||chooseList[index]==0)&&item.options[chooseList[index]].optionAnswer
- ? paperScore += 2
- : questionWrong.push({[item.id]: (chooseList[index]||chooseList[index]==0)?item.options[chooseList[index]].optionId:''})
- })
- answer.submitUserAnswer({reqdata:{
- paperId,
- userId: wx.getStorageSync('id'),
- questionWrong: JSON.stringify(questionWrong),
- paperScore,
- paperDuration:time
- }},r => {
- wx.navigateTo({
- url: `/pages/contest/score/score?rank=${r.object}&score=${paperScore}`,
- })
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.attendContest()
- timer = setInterval(() => {
- this.setData({
- time: ++this.data.time
- })
- }, 1000)
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- clearInterval(timer)
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|