123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- // pages/subject/subject.js
- const app = getApp()
- const host = app.globalData.host;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- data:{},
- idx:1,
- ans:[],
- id:''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- wx.request({
- url: host+'/api/wx/paper/info',
- data: { id: options.id},
- method:'GET',
- success:res=>{
- this.setData({
- data:res.data.data,
- id:options.id
- })
- this.countDown(res.data.data.time_limit)
- }
- })
- },
- countDown:function(time){
- var m=time-1,s=59,_this=this;
- var down=setInterval(function(){
- s--
- if(s==0 && m>0){
- m--;
- s=59
- }
- if(s==0 && m == 0){
- clearInterval(down)
- _this.post();
- }
- _this.setData({
- time:m+"分"+s+"秒"
- })
- },1000)
- },
- answer:function(e){
- let id = e.target.dataset.id, value = e.detail.value
- let ans = this.data.ans
- let old=ans.filter(item=>item.id == id)
- if (old.length>0){
- for (let i = 0; i < ans.length; i++) {
- if (ans[i].id == id) {
- ans[i].answer = e.detail.value
- }
- }
- }else{
- ans.push({
- id:id,
- answer:value
- })
- }
- this.setData({
- ans:ans
- })
- },
- next:function(){
- const idx=this.data.idx+1
- const cur = this.data.idx -1
- if (!this.data.ans[cur].answer){
- wx.showToast({
- title: '请选择答案',
- icon: 'none',
- duration: 2000
- })
- }else{
- this.setData({
- idx:idx
- })
- }
- },
- prev: function () {
- const idx = this.data.idx - 1
- this.setData({
- idx: idx
- })
- },
- post:function(){
- var _this=this
- wx.showModal({
- title: '交卷确认',
- content: '您确认要交卷吗?',
- success(res) {
- if (res.confirm) {
- wx.request({
- url: host + '/api/wx/postpaper',
- data: {
- paper_id: _this.data.id,
- questions: _this.data.ans
- },
- method: 'POST',
- success: res => {
- console.log(res.data)
- if (res.data.code == 0) {
- wx.showModal({
- title: res.data.data.score+'分',
- content: '您本次考试得分',
- showCancel: false,
- success(res) {
- if (res.confirm) {
- wx.navigateTo({
- url: '../online/online?tab=1',
- })
- }
- }
- })
- }
- }
- })
- }
- }
- })
-
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|