美文网首页
安规考试

安规考试

作者: 糖醋里脊120625 | 来源:发表于2020-11-19 09:27 被阅读0次
    // pages/answer/index.js
    const { $Toast } = require('../../dist/base/index');
    var http = require('../../utils/httputils.js');   //相对路径
    var app = getApp();// 调用全局变量
    import { $wuxCountDown } from '../../wux/index'
    const { $Message } = require('../../dist/base/index');
    
    Page({
    
      data: {
        hasshow: 0,
        unanswered: 0,
        currentD: [],
        currentDId: [],
        examid: null,
        paperid: null,
        examidPaperid: null,
        examidResult: null,
        answerResult: [],
        userid: null,
        questionlist: [],
        questionCurrent: 0,
        pageCurrent: 1,
        currentItem: 0,
        badshow: false,
        goodshow: false,
        loading: false, //加载中
        showanswer: false,
        result: [], //题目
        total: 0, //题目总总数
        menu: '', //套题id
        questionMenu: '', //套题名称
        questionInfo: {},
        percent: 0, //进度条百分比
        time: 45, //时间
        s: ['A. ', 'B. ', 'C. ', 'D. ', 'E. '],
        index: 1, //第几题
        current: "", //单选选中的答案
        currentPage: 1,
        type: '', //题目类型 1:单选 2:多选
        disabled: false, //单选选中不可选
        disabled1: false, //多选选中不可选
        actionVisible: false, //弹出层
        questionErr: 0, //错题个数
        questionOk: 0, // 正确个数
        percentage: 0,
        visible1: false,
        visible2: false,
        visible3: false,
        visible4: false,
        action1: [{
          name: '取消'
        },
        {
          name: '确定',
          color: '#2db7f5',
          loading: false
        }
        ],
        action2: [{
          name: '确定',
          color: '#2db7f5',
          loading: false
        }],
        actanswer: [{
          name: '取消'
        },
        {
          name: '确认',
          color: '#19be6b'
        },
    
        ],
        action4: [{
          name: '取消'
        },
        {
          name: '确定',
          color: '#2db7f5',
          loading: false
        }
        ],
        showVideo: false,
        answerEach: '',
        answerMore: '',
        ansChose: '',
        questionIndex: '',
        indexnum: 1,
        clearTimer: false
      },
    
      onLoad(e) {
        var that = this;
        console.log(e.duration)
        var time = Number(e.duration) * 1000
        console.log(time)
        console.log(6430000)
        //var questionMenu = e.questionMenu;
        this.setData({
          targetTime2: new Date().getTime() + time,
          examid: e.examid,
          paperid: e.paperid,
          userid: app.globalData.userInfo.userid,
        })
        wx.getSystemInfo({
          success(res) {
            that.setData({
              windowWidth: res.windowWidth
            })
          }
        })
    
        that.getExamUserPaperProfile();
    
      },
      onUnload() {
        this.setData({
          clearTimer: true
        });
      },
    
    
    
      //定时器自动交卷
      myLinsterner(e) {
        this.handleMask()
      },
      handleMask() {
        var that = this;
        $Toast({
          content: '时间到,自动交卷',
          icon: 'prompt',
          duration: 0,
          mask: false
        });
        setTimeout(() => {
          $Toast.hide();
          this.goontime()
        }, 500);
      },
      goontime() {
        var that = this;
        var params = {
          examid: this.data.examid,
          paperid: this.data.examidPaperid,
          userid: this.data.userid,
          questionlist: this.data.answerResult
        }
        //人员考试-提交答卷-判定成绩
        //debugger
        http.postRequest(http.LING + "/wxapp/exam/user/paper/submit", params, function (res) {
          console.log(res)
          if (parseInt(res.error) === 0) {
            console.log("提交成功")
            $Toast({
              content: '提交成功!',
              type: 'success',
              duration: 0,
            });
            setTimeout(() => {
              $Toast.hide();
              that.setData({
                hasshow: res.data.markup.has,
                examid: res.data.markup.examid,
                examidResult: res.data,
                showanswer: false,
                badshow: true
              });
            }, 200);
          } else {
            $Toast({
              content: '提交失败!',
              type: 'warning',
              duration: 0,
            });
            setTimeout(() => {
              $Toast.hide();
            }, 200);
          }
        }, function (err) {
          $Toast({
            content: '提交失败!',
            type: 'warning',
            duration: 0,
          });
          setTimeout(() => {
            $Toast.hide();
          }, 200);
          console.log(err)
        })
      },
      nextques() {
        $Toast({
          content: '没有更多题目了',
          type: 'warning'
        });
      },
      itemClick(options) {
        console.log(options)
        var that = this;
        var id = options.currentTarget.dataset.id;
        console.log(id)
        //设置当前样式
        that.setData({
          'currentItem': id
        })
      },
      onReady(res) {
        this.videoContext = wx.createVideoContext('myVideo')
      },
      /**
       * 获取人员答卷详情
       */
      getExamUserPaperProfile() {
        var that = this;
    
        var params = {
          "examid": that.data.examid,
          "userid": that.data.userid,
          "paperid": that.data.paperid
        }
    
        http.getRequest(http.LING + "/wxapp/exam/user/paper/profile", params, function (res) {
          console.log(res)
          if (parseInt(res.error) === 0) {
            var qlist = res.data.questionlist;
            for (var i = 0; i < qlist.length; i++) {
              qlist[i]['judge'] = null
            }
            console.log('qlist', qlist);
            that.setData({
              questionlist: res.data.questionlist,
              total: res.data.qustionnum,
              result: qlist,
              examidPaperid: res.data.paperid,
    
            });
          } else {
            that.setData({
              questionlist: [],
              total: 0
            });
          }
        }, function (err) {
          console.log(err)
          that.setData({
            questionlist: [],
            total: 0
          });
        })
      },
      //上一题bbb
      laststep() {
        var that = this;
        if (that.data.currentPage === 1) {
          $Toast({
            content: '这已经是第一题了',
            type: 'warning'
          });
          return false
        }
        if (that.data.currentPage > 1) {
          that.setData({
            indexnum: that.data.indexnum - 1,
            pageCurrent: that.data.pageCurrent - 1,
            currentPage: that.data.pageCurrent - 1,
            questionCurrent: that.data.questionCurrent - 1,
            current: '',
            answerEach: ''
          });
        }
        console.log("currentPage" + that.data.currentPage)
        console.log("indexnum" + that.data.indexnum)
        var answerResult = JSON.parse(JSON.stringify(this.data.answerResult));
        var index = answerResult.map(item => item.questionid).indexOf(this.data.result[this.data.currentPage - 1]['questionid']);
        if (index > -1) {
          var current = ""
          var currentD = []
          if (answerResult[index]['answer'].constructor === String) {
            var resultOptions = this.data.result[this.data.currentPage - 1]['options']
            var idx = resultOptions.map(item => item.code).indexOf(answerResult[index]['answer']);
            current = resultOptions[idx]['code'] + '. ' + resultOptions[idx]['content']
          }
          console.log(resultOptions)
          //debugger
          console.log(resultOptions)
          if (answerResult[index]['answer'].constructor === Array) {
            var resultOptions = this.data.result[this.data.currentPage - 1]['options']
            for (var i = 0; i < answerResult[index]['answer'].length; i++) {
              var idx = resultOptions.map(item => item.code).indexOf(answerResult[index]['answer'][i]);
              currentD.push(resultOptions[idx]['code'] + '. ' + resultOptions[idx]['content'])
            }
          }
          this.setData({
            answerEach: answerResult[index]['answer'],
            current: current,
            currentD: currentD,
            currentDId: answerResult[index]['answer']
          });
        }else{
          this.setData({
            answerEach: '',
            current: '',
            currentD: [],
            currentDId: []
          });
        }
    
      },
      //下一题nnn
      nextstep() {
        var that = this;
        console.log("indexnum___" + that.data.indexnum)
        if (that.data.indexnum === that.data.questionlist.length) {
          $Toast({
            content: '这已经是最后一题了',
            type: 'warning'
          });
          return false
        }
        //未答题可跳过继续往下答题
        if (!that.data.answerEach) {
    
          
          that.setData({
            indexnum: that.data.indexnum + 1,
            pageCurrent: that.data.pageCurrent + 1,
            currentPage: that.data.pageCurrent + 1,
            questionCurrent: that.data.questionCurrent + 1,
            //current: '',
            //answerEach: ''
          });
          console.log("下一题第几题__" + that.data.questionCurrent)
    
          console.log("currentPage" + that.data.currentPage)
          console.log("indexnum" + that.data.indexnum)
          var answerResult = JSON.parse(JSON.stringify(that.data.answerResult));
          var index = answerResult.map(item => item.questionid).indexOf(that.data.result[that.data.currentPage - 1]['questionid']);
          if (index > -1) {
            var current = ""
            var currentD = []
            if (answerResult[index]['answer'].constructor === String) {
              var resultOptions = that.data.result[that.data.currentPage - 1]['options']
              var idx = resultOptions.map(item => item.code).indexOf(answerResult[index]['answer']);
              current = resultOptions[idx]['code'] + '. ' + resultOptions[idx]['content']
            }
            if (answerResult[index]['answer'].constructor === Array) {
              var resultOptions = that.data.result[that.data.currentPage - 1]['options']
              for (var i = 0; i < answerResult[index]['answer'].length; i++) {
                var idx = resultOptions.map(item => item.code).indexOf(answerResult[index]['answer'][i]);
                currentD.push(resultOptions[idx]['code'] + '. ' + resultOptions[idx]['content'])
              }
            }
            that.setData({
              answerEach: answerResult[index]['answer'],
              current: current,
              currentD: currentD,
              currentDId: answerResult[index]['answer']
            });
          } else {
            that.setData({
              answerEach: '',
              current: '',
              currentD: [],
              currentDId: []
            });
          }
          return false
        }
    
        var indexData = that.data.questionlist[that.data.questionCurrent]
        var params = {
          "examid": that.data.examid,
          "paperid": that.data.examidPaperid,
          "questionid": indexData.questionid,
          "answer": that.data.answerEach,
          "userid": that.data.userid
        };
    
        //debugger
        http.postRequest(http.LING + "/wxapp/exam/user/paper/question/submit", params, function (res) {
          console.log(res)
          //debugger
          if (parseInt(res.error) === 0) {
            that.setData({
              indexnum: that.data.indexnum + 1,
              pageCurrent: that.data.pageCurrent + 1,
              currentPage: that.data.pageCurrent + 1,
              questionCurrent: that.data.questionCurrent + 1,
              answerEach: '',
              current: '',
              currentD: [],
              currentDId: []
            });
            console.log("currentPage" + that.data.currentPage)
            console.log("indexnum" + that.data.indexnum)
            var answerResult = JSON.parse(JSON.stringify(that.data.answerResult));
            var index = answerResult.map(item => item.questionid).indexOf(that.data.result[that.data.currentPage - 1]['questionid']);
            if (index > -1) {
              var current = ""
              var currentD = []
              if (answerResult[index]['answer'].constructor === String) {
                var resultOptions = that.data.result[that.data.currentPage - 1]['options']
                var idx = resultOptions.map(item => item.code).indexOf(answerResult[index]['answer']);
                current = resultOptions[idx]['code'] + '. ' + resultOptions[idx]['content']
              }
              if (answerResult[index]['answer'].constructor === Array) {
                var resultOptions = that.data.result[that.data.currentPage - 1]['options']
                for (var i = 0; i < answerResult[index]['answer'].length; i++) {
                  var idx = resultOptions.map(item => item.code).indexOf(answerResult[index]['answer'][i]);
                  currentD.push(resultOptions[idx]['code'] + '. ' + resultOptions[idx]['content'])
                }
              }
              that.setData({
                answerEach: answerResult[index]['answer'],
                current: current,
                currentD: currentD,
                currentDId: answerResult[index]['answer']
              });
            } else {
              that.setData({
                answerEach: '',
                current: '',
                currentD: [],
                currentDId: []
              });
            }
          } 
          console.log("下一题第几题__" + that.data.questionCurrent)
        }, function (err) {
          console.log(err)
          // that.setData({
          //   questionlist: [],
          //   total: 0
          // });
        })
    
    
      },
      //单选
      handleChange({ detail = {}, target = {} }) {
        let questionInfo = this.data.questionInfo;
        var val = detail.value.substr(0, 1);
    
        var answerResult = JSON.parse(JSON.stringify(this.data.answerResult));
        console.log(answerResult)
        var index = answerResult.map(item => item.questionid).indexOf(this.data.result[this.data.currentPage - 1]['questionid']);
        if (index > -1) {
          answerResult[index]['answer'] = val;
        } else {
          answerResult.push({
            questionid: this.data.result[this.data.currentPage - 1]['questionid'],
            answer: val
          })
        }
        this.setData({
          answerEach: val,
          answerResult: answerResult,
          // questionInfo: questionInfo,
          current: detail.value
        });
        //获取答案
        console.log(questionInfo)
        console.log(detail.value)
    
        var rsdata = JSON.parse(JSON.stringify(this.data.result));
        console.log(rsdata)
        if (rsdata[this.data.currentPage - 1]['judge'] != 1) {
          rsdata[this.data.currentPage - 1]['judge'] = 1;
          this.setData({
            result: rsdata
          });
        }
      },
      //判断对错 
      panduan({ detail = {}, target = {} }) {
        let questionInfo = this.data.questionInfo;
        console.log(target.dataset.id)
        //判断答案
        // if (target.dataset.id) {
        //   console.log('ok')
        //   questionInfo.isOk = 1
        // } else {
        //   questionInfo.isOk = 0
        // }
    
        var val = detail.value.substr(0, 1);
    
        var answerResult = JSON.parse(JSON.stringify(this.data.answerResult));
        var index = answerResult.map(item => item.questionid).indexOf(this.data.result[this.data.currentPage - 1]['questionid']);
        if (index > -1) {
          answerResult[index]['answer'] = val;
        } else {
          answerResult.push({
            questionid: this.data.result[this.data.currentPage - 1]['questionid'],
            answer: val
          })
        }
    
        this.setData({
          //questionInfo: questionInfo,
          answerEach: val,
          answerResult: answerResult,
          current: detail.value
        });
    
        var rsdata = JSON.parse(JSON.stringify(this.data.result));
        if (rsdata[this.data.currentPage - 1]['judge'] != 1) {
          rsdata[this.data.currentPage - 1]['judge'] = 1;
          this.setData({
            result: rsdata
          });
        }
      },
      //多选
      morechose(event) {
        //let questionInfo = this.data.questionInfo;
        //sconsole.log(this.data.currentD);
        console.log(event.currentTarget.dataset)
        var currentD = JSON.parse(JSON.stringify(this.data.currentD));
        var val = event.currentTarget.dataset.id + '. ' + event.currentTarget.dataset.name
        var index = currentD.indexOf(val);
        index === -1 ? currentD.push(val) : currentD.splice(index, 1);
    
        var currentDId = JSON.parse(JSON.stringify(this.data.currentDId));
        var index = currentDId.indexOf(event.currentTarget.dataset.id);
        index === -1 ? currentDId.push(event.currentTarget.dataset.id) : currentDId.splice(index, 1);
    
        var answerResult = JSON.parse(JSON.stringify(this.data.answerResult));
        var index = answerResult.map(item => item.questionid).indexOf(this.data.result[this.data.currentPage - 1]['questionid']);
        if (index > -1) {
          answerResult[index]['answer'] = currentDId;
        } else {
          answerResult.push({
            questionid: this.data.result[this.data.currentPage - 1]['questionid'],
            answer: currentDId
          })
        }
    
        this.setData({
          currentD: currentD,
          answerEach: currentDId,
          currentDId: currentDId,
          answerResult: answerResult
        });
        console.log(this.data.currentD)
        console.log(this.data.currentDId)
        if (this.data.result[this.data.currentPage - 1]['judge'] != 1) {
          var rsdata = JSON.parse(JSON.stringify(this.data.result));
          rsdata[this.data.currentPage - 1]['judge'] = 1;
          this.setData({
            result: rsdata
          });
        }
    
      },
      //下标点击
      goindex(target) {
        var that = this;
        this.setData({
          indexnum: target.currentTarget.dataset.index + 1,
          questionCurrent: target.currentTarget.dataset.index,
          currentPage: target.currentTarget.dataset.index + 1,
          pageCurrent: target.currentTarget.dataset.index + 1,
          answerEach: '',
          current: '',
          currentD: [],
          currentDId: []
        })
        /*
        console.log("currentPage" + that.data.currentPage)
        console.log("点击第几题__" + this.data.questionCurrent)
        console.log(target.currentTarget.dataset.index);
        console.log(this.data.answerResult);
        */
        var answerResult = JSON.parse(JSON.stringify(this.data.answerResult));
        console.log(answerResult)
        var index = answerResult.map(item => item.questionid).indexOf(this.data.result[this.data.currentPage - 1]['questionid']);
        if (index > -1) {
          var current = ""
          var currentD = []
          if (answerResult[index]['answer'].constructor === String) {
            var resultOptions = this.data.result[this.data.currentPage - 1]['options']
            var idx = resultOptions.map(item => item.code).indexOf(answerResult[index]['answer']);
            current = resultOptions[idx]['code'] + '. ' + resultOptions[idx]['content']
          }
          if (answerResult[index]['answer'].constructor === Array) {
            var resultOptions = this.data.result[this.data.currentPage - 1]['options']
            for (var i = 0; i < answerResult[index]['answer'].length; i++) {
              var idx = resultOptions.map(item => item.code).indexOf(answerResult[index]['answer'][i]);
              currentD.push(resultOptions[idx]['code'] + '. ' + resultOptions[idx]['content'])
            }
          }
          this.setData({
            answerEach: answerResult[index]['answer'],
            current: current,
            currentD: currentD,
            currentDId: answerResult[index]['answer']
          });
        }
      },
    
    
      //交卷对话框
      handleSubmitOpen() {
    
        var rsdata = JSON.parse(JSON.stringify(this.data.result))
        var len = 0;
    
        for (var i = 0; i < rsdata.length; i++) {
          if (rsdata[i]['judge'] != 1) {
            len++;
          }
        }
        this.setData({
          showanswer: true,
          unanswered: len
        })
    
        /*
        this.stop();
        this.setData({
          visible1:true,
          stopMin:this.data.min,
          stopSec:this.data.sec
        })
        */
      },
      //查看答卷
      examidView() {
        var that = this;
        wx.navigateTo({
          url: '/pages/viewscore/index?examid=' + that.data.examid + '&paperid=' + that.data.examidPaperid + '&userid' + that.data.userid,
        })
      },
      //结束考试
      examidEnd() {
        wx.reLaunch({
          url: '/pages/wrong/index',
        })
      },
      //开始补考
      examidNew() {
        this.setData(
          {
            unanswered: 0,
            currentD: [],
            currentDId: [],
            examidPaperid: null,
            examidResult: null,
            answerResult: [],
            questionlist: [],
            questionCurrent: 0,
            pageCurrent: 1,
            currentItem: 0,
            badshow: false,
            goodshow: false,
            loading: false, //加载中
            showanswer: false,
            result: [], //题目
            total: 0, //题目总总数
            menu: '', //套题id
            questionMenu: '', //套题名称
    
            percent: 0, //进度条百分比
            time: 45, //时间
            index: 1, //第几题
            current: "", //单选选中的答案
            currentPage: 1,
            type: '', //题目类型 1:单选 2:多选
            disabled: false, //单选选中不可选
            disabled1: false, //多选选中不可选
            actionVisible: false, //弹出层
            questionErr: 0, //错题个数
            questionOk: 0, // 正确个数
            percentage: 0,
            visible1: false,
            visible2: false,
            visible3: false,
            visible4: false,
            answerEach: '',
            answerMore: '',
            ansChose: '',
            questionIndex: '',
            indexnum: 1
          }
        )
        this.getExamUserPaperProfile();
      },
      //保存按钮
    
      handanswer(e) {
        var that = this;
        if (e.detail.index == 0) {
          this.setData({
            showanswer: false
          });
        } else {
          //debugger
          var params = {
            examid: this.data.examid,
            paperid: this.data.examidPaperid,
            userid: this.data.userid,
            questionlist: this.data.answerResult
          }
          //人员考试-提交答卷-判定成绩
          http.postRequest(http.LING + "/wxapp/exam/user/paper/submit", params, function (res) {
            console.log(res)
            if (parseInt(res.error) === 0) {
              console.log("提交成功")
              $Toast({
                content: '提交成功!',
                type: 'success',
                duration: 0,
              });
              setTimeout(() => { 
                $Toast.hide();
                that.setData({
                  examidResult: res.data,
                  showanswer: false,
                  badshow: true
                });
              }, 200);
            } else {
              $Toast({
                content: '提交失败!',
                type: 'warning',
                duration: 0,
              });
              setTimeout(() => {
                $Toast.hide();
              }, 200);
            }
          }, function (err) {
            $Toast({
              content: '提交失败!',
              type: 'warning',
              duration: 0,
            });
            setTimeout(() => {
              $Toast.hide();
            }, 200);
            console.log(err)
          })
        }
    
      },
      overclose() {
        wx.reLaunch({
          url: '/pages/wrong/index'
        })
      },
      seeans() {
        wx.navigateTo({
          url: '/pages/viewscore/index'
        })
      },
    
      handleSubmit() {
        this.submit();
      },
      //时间到对话框
      handleClick1() {
        this.setData({
          visible2: true
        });
      },
      //弹出统计下拉层
      handleOpen() {
        //this.hideVideo()
        this.setData({
          actionVisible: true
        })
      },
      //关闭统计下拉层
      actionCancel() {
        this.setData({
          actionVisible: false
        })
      },
    
      stop() {
        this.Countdown.stop()
      },
      start() {
        this.Countdown.start()
      },
      update(time) {
        this.Countdown.update(+(new Date) + parseInt(time))
      }
    })
    

    相关文章

      网友评论

          本文标题:安规考试

          本文链接:https://www.haomeiwen.com/subject/zydkiktx.html