litian
2024-03-15 3f1ea0a8e4bb02bf7544df8660b15cfa69d6b84a
pages/bookServices/examination/questionOptions/index.js
@@ -1,10 +1,50 @@
// pages/bookServices/examination/questionOptions/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    currentIndex: {
      type: Number,
      value: 0,
    },
    questionDataList: {
      type: Array,
      value: []
    },
    cardList: {
      type: Array,
      value: []
    },
    subjectiveTotal: {
      type: Number,
      value: 0
    },
    countdownTime: {
      type: Number,
      value: 0,
    },
    answerType: {
      type: String,
      value: ''
    },
    subjectiveNum: {
      type: Number,
      value: 0
    },
    subjectiveGrade: {
      type: Number,
      value: 0
    },
    correctNum: {
      type: Number,
      value: 0
    },
    submitStatus: {
      type: Boolean,
      value: false
    }
  },
  /**
@@ -12,12 +52,212 @@
   */
  data: {
    btnStyle: "width:320rpx;border-radius:60rpx",
    noReady: 0,
    questionCardState: false,
    setUpPopup: false,
    testReportState: false,
    sliderValue: 0,
    useTime: ''
  },
  observers: {
    "countdownTime": function (newValue, oldValue) {
      if (this.properties.answerType == 'option') {
        this.setData({
          useTime: this.formatTime(2 * 60 * 60 * 1000 - this.properties.countdownTime)
        })
      }
      if (newValue == 0 && (this.properties.answerType == 'option' || this.properties.answerType == 'mock')) {
        this.timeout()
      }
    },
  },
  created() {
  },
  /**
   * 组件的方法列表
   */
  methods: {
    // // 格式化时间
    formatTime(ms) {
      const hours = Math.floor((ms / (1000 * 60 * 60)) % 24)
        .toString()
        .padStart(2, '0')
      const minutes = Math.floor((ms / (1000 * 60)) % 60)
        .toString()
        .padStart(2, '0')
      const seconds = Math.floor((ms / 1000) % 60)
        .toString()
        .padStart(2, '0')
      return `${hours}:${minutes}:${seconds}`
    },
    // 判断是否输入答案
    isHaveAnswer(data) {
      if (typeof data == 'string') {
        data = data
          .replace(/<[^>]*>/g, '')
          .replace(/&nbsp;/g, '')
          .trim()
        if (data.length) {
          return true
        } else {
          return false
        }
      } else {
        const answer = data.find((item) => item.length > 0)
        if (answer) {
          return true
        } else {
          return false
        }
      }
    },
    setCollect() {
      var myEventDetail = {
      }
      var myEventOption = {
        bubbles: true,
        composed: true,
      }
      this.triggerEvent('setCollect', myEventDetail, myEventOption)
    },
    // 答题卡按钮
    handlePopup() {
      this.setData({
        questionCardState: true
      })
    },
    // 答题卡跳转题目
    goQuestion(e) {
      var myEventDetail = {
        id: e.currentTarget.dataset.id
      }
      var myEventOption = {
        bubbles: true,
        composed: true,
      }
      this.triggerEvent('goQuestion', myEventDetail, myEventOption)
    },
    // 答题卡遮罩层点击
    onVisibleChange(e) {
      this.setData({
        questionCardState: e.detail.visible,
      });
    },
    // 设置按钮
    setUpBtn() {
      this.setData({
        setUpPopup: true
      })
    },
    // 滑块变化
    onChangeSlider(e) {
      console.log(e);
      this.setData({
        sliderValue: e.detail.value
      })
    },
    // 设置遮罩层点击
    onSetUpChange(e) {
      this.setData({
        setUpPopup: e.detail.visible
      })
    },
    // 重做按钮
    resterBtn() {
      wx.showModal({
        title: '提示',
        content: '是否重新开始答题?',//editable如果为true,这就是输入框的内容
        editable: false,//是否显示输入框
        success: (res) => {
          if (res.confirm) {
            this.restart()
          }
        }
      })
    },
    // 重做事件
    restart() {
      var myEventDetail = {
      }
      var myEventOption = {
        bubbles: true,
        composed: true,
      }
      this.triggerEvent('restart', myEventDetail, myEventOption)
    },
    // 还有N道题未做弹窗
    confrimPromptDialog() {
      wx.showModal({
        title: '提示',
        content: `您还有 ${this.data.noReady}道题未答,是否提交?`,//editable如果为true,这就是输入框的内容
        editable: false,//是否显示输入框
        success: (res) => {
          if (res.confirm) {
            this.submitPaper()
          }
        }
      })
    },
    // 底部提交按钮
    submitBtn() {
      // 我的错题和收藏  直接走提交逻辑
      if (this.properties.answerType !== 'option' || this.properties.answerType !== 'option') {
        return this.submitPaper()
      }
      this.properties.questionDataList.forEach(item => {
        if (!this.isHaveAnswer(item.userAnswer)) {
          this.setData({
            noReady: this.data.noReady + 1
          })
        }
      })
      // 未做完,打开提示弹窗
      if (this.data.noReady > 0) {
        this.confrimPromptDialog()
      } else {
        // 做完了直接执行提交事件
        this.submitPaper()
      }
    },
    // 提交事件
    submitPaper() {
      var myEventDetail = {
      }
      var myEventOption = {
        bubbles: true,
        composed: true,
      }
      this.triggerEvent('submitPaper', myEventDetail, myEventOption)
    },
    // 打开测试报告弹窗
    openTestReportDialog() {
      this.setData({
        testReportState: true
      })
    },
    // 关闭测试报告弹窗
    closeTestReportDialog(e) {
      this.setData({
        testReportState: false
      })
    },
    // 测试报告弹窗查看答案解析按钮
    viewAnswer() {
      this.closeTestReportDialog()
    },
    // 答题时间到
    timeout() {
      wx.showModal({
        title: '提示',
        content: '答题时间已到',//editable如果为true,这就是输入框的内容
        editable: false,//是否显示输入框
        showCancel: false,
        success: (res) => {
        }
      })
      this.submitPaper()
    }
  }
})