125 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			125 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
| // pages/test/detail.js
 | |
| const api = require("../../utils/request.js");
 | |
| Page({
 | |
| 
 | |
|   /**
 | |
|    * 页面的初始数据
 | |
|    */
 | |
|   data: {
 | |
|     tm_index:0,
 | |
|     results:[]
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * 生命周期函数--监听页面加载
 | |
|    */
 | |
|   onLoad: function (options) {
 | |
|     var that = this
 | |
|     var query = {'examtest':options.id}
 | |
|     api.request('examtest/answerdetail/', 'GET', query).then(res => {
 | |
|       that.data.results= res.data
 | |
|       that.showTm(0)
 | |
|       that.setData({
 | |
|         tmtotal:res.data.length
 | |
|       })
 | |
|     })
 | |
|     try {
 | |
|       const res = wx.getSystemInfoSync()
 | |
|       that.setData({
 | |
|         scrollHeight: res.windowHeight - 70
 | |
|       })
 | |
|     } catch (e) {
 | |
|     }
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * 生命周期函数--监听页面初次渲染完成
 | |
|    */
 | |
|   onReady: function () {
 | |
| 
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * 生命周期函数--监听页面显示
 | |
|    */
 | |
|   onShow: function () {
 | |
| 
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * 生命周期函数--监听页面隐藏
 | |
|    */
 | |
|   onHide: function () {
 | |
| 
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * 生命周期函数--监听页面卸载
 | |
|    */
 | |
|   onUnload: function () {
 | |
| 
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * 页面相关事件处理函数--监听用户下拉动作
 | |
|    */
 | |
|   onPullDownRefresh: function () {
 | |
| 
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * 页面上拉触底事件的处理函数
 | |
|    */
 | |
|   onReachBottom: function () {
 | |
| 
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * 用户点击右上角分享
 | |
|    */
 | |
|   onShareAppMessage: function () {
 | |
| 
 | |
|   },
 | |
|   showTm: function (index) {
 | |
|     var that = this
 | |
|     var tm_current = that.data.results[index]
 | |
|     that.setData({
 | |
|       'tm_index': index,
 | |
|       'tm_current': tm_current
 | |
|     })
 | |
|     that.showOptions()
 | |
|   },
 | |
|   next: function () {
 | |
|     var that = this
 | |
|     var tm_index = that.data.tm_index + 1
 | |
|     that.showTm(tm_index)
 | |
| 
 | |
|   },
 | |
|   previous: function () {
 | |
|     var that = this
 | |
|     var tm_index = that.data.tm_index - 1
 | |
|     that.showTm(tm_index)
 | |
|   },
 | |
|   showOptions: function () {
 | |
|     var that = this
 | |
|     let question_options = that.data.tm_current.question.options
 | |
|     let options = []
 | |
|     let user_answer = that.data.tm_current.user_answer
 | |
|     for (let key in question_options) {
 | |
|       let option = {}
 | |
|       option.key = key
 | |
|       option.value = key + ':' + question_options[key]
 | |
|       if (user_answer) {
 | |
|         if (key == user_answer || user_answer.indexOf(key) != -1) {
 | |
|           option.checked = true
 | |
|         }
 | |
|       } else {
 | |
|         option.checked = false
 | |
|       }
 | |
|       options.push(option)
 | |
|     }
 | |
|     that.setData({
 | |
|       options: options
 | |
|     })
 | |
|   },
 | |
| }) |