// pages/bookServices/examination/questionOptions/index.js Component({ /** * 组件的属性列表 */ properties: { currentIndex: { type: Number, value: 0, }, questionDataList: { type: Array, value: [], }, scoreData: { type: Array, value: [], }, correctNum: { type: Number, value: 0, }, submitStatus: { type: Boolean, value: false, }, isNight: { type: Boolean, value: false, }, showId: { type: String }, isShowDialog: { type: Boolean } }, /** * 组件的初始数据 */ data: { btnStyle: "width:320rpx;border-radius:60rpx", noReady: 0, questionCardState: false, setUpPopup: false, testReportState: false, sliderValue: 36, useTime: "", radioItem: "daytime", }, observers: { isShowDialog: function (newValue, oldValue) { if (newValue) this.setData({ testReportState: newValue, }); } }, 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(/ /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) { const value = e.detail.value; console.log(value); this.triggerEvent("onChangeSlider", { value }); }, // 设置遮罩层点击 onSetUpChange(e) { this.setData({ setUpPopup: e.detail.visible, }); }, // 设置模式切换 onRadioChange(e) { this.setData({ radioItem: e.detail.value, }); const value = e.detail.value == "night" ? true : false; this.triggerEvent("changeBGColor", { value }); }, // 重做按钮 resterBtn() { wx.showModal({ title: "提示", content: "是否重新开始答题?", //editable如果为true,这就是输入框的内容 confirmColor: "#ff6c00", cancelColor: "#949494", 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.showToast({ title: `您还有 ${this.data.noReady}道题未答,请完成所有题目后提交。`, icon: 'none', duration: 2000 }); }, // 底部提交按钮 submitBtn() { this.setData({ noReady: 0, }); if (this.properties.submitStatus) return wx.navigateBack(); 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, }); }, // 答题时间到 timeout() { wx.showModal({ title: "提示", content: "答题时间已到", //editable如果为true,这就是输入框的内容 confirmColor: "#ff6c00", cancelColor: "#949494", editable: false, //是否显示输入框 showCancel: false, success: (res) => {}, }); this.submitPaper(); }, }, });