var util = require("../../utils/util.js") const app = getApp() Page({ data: { testLists: [], answers: [], answersBoxs: [], testFinish: '', core_id: '' }, onLoad: function(options) { if (options.testFinish == '未完成') { this.setData({ testFinish: '未完成' }) } this.setData({ navH: app.globalData.navHeight, core_id: options.core_id }) this.init(options.core_id); }, init(testid) { const that = this util.postData('/college/queryTests', { openid: app.globalData.openid, core_id: testid }) .then(res => { this.setData({ testLists: res, }) }) .catch(err => { console.log(err); }) }, // 选择题选择 _selectItem: function(e) { let index = e.currentTarget.dataset.index; let subid = e.currentTarget.dataset.subid; this.editQuestion(index, subid); let selId = e.currentTarget.dataset.selid; let answersBoxs = this.data.answersBoxs; let i = answersBoxs.indexOf(selId) if (i < 0) { answersBoxs.push(selId) } this.setData({ answersBoxs: answersBoxs }) }, // 选择 editQuestion: function(index, subid) { let testLists = this.data.testLists; this.data.testLists[index].collegeTestResults.forEach((item, itemInd) => { item.id == subid ? item.is_select = 1 : item.is_select = 0; let attr = `testLists[${index}].collegeTestResults[${itemInd}]`; this.setData({ [attr]: item }) }) }, // 提交信息 _clickBtn: function() { if (this.data.answersBoxs.length < this.data.testLists.length) { wx.showToast({ title: '请完整回答', icon: 'none', duration: 2000 }) return } let answers = []; this.data.testLists.forEach(item => { item.collegeTestResults.forEach(jjj => { if (jjj.userAnswer != null) { wx.showToast({ title: '已做过测试', icon: 'none', duration: 2000 }) return } if (jjj.is_select == 1) { answers.push(jjj.seq) } }) }) const that = this util.postData('/college/addTestDetail', { openid: app.globalData.openid, core_id: that.data.core_id, answers: answers.toString() }) .then(res => { wx.navigateTo({ url: '/pages/testing/score/score?res=' + JSON.stringify(res) +'&core_id='+that.data.core_id }) // wx.showToast({ // title: '答对' + res.count + '题' + '总分' + res.score + '分', // icon: 'none', // duration: 4000 // }) }) .catch(err => { console.log(err); }) }, //返回首页 backHome: function() { util.goHome(); }, /** * 用户点击右上角分享 */ onShareAppMessage: function() {} })