You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
300 lines
7.4 KiB
300 lines
7.4 KiB
// pages/twoTest/twoTest.js
|
|
const app = getApp()
|
|
//计时器
|
|
function timing(that) {
|
|
var seconds = that.data.seconds
|
|
if (seconds > 21599) {
|
|
that.setData({
|
|
time: '6小时,不想继续了gg'
|
|
});
|
|
return;
|
|
}
|
|
setTimeout(function () {
|
|
that.setData({
|
|
seconds: seconds + 1
|
|
});
|
|
timing(that);
|
|
}
|
|
, 1000)
|
|
formatSeconds(that)
|
|
}
|
|
function formatSeconds(that) {
|
|
var mins = 0, hours = 0, seconds = that.data.seconds, time = ''
|
|
if (seconds < 60) {
|
|
|
|
} else if (seconds < 3600) {
|
|
mins = parseInt(seconds / 60)
|
|
seconds = seconds % 60
|
|
} else {
|
|
mins = parseInt(seconds / 60)
|
|
seconds = seconds % 60
|
|
hours = parseInt(mins / 60)
|
|
mins = mins % 60
|
|
}
|
|
that.setData({
|
|
time: formatTime(hours) + ':' + formatTime(mins) + ':' + formatTime(seconds)
|
|
});
|
|
}
|
|
function formatTime(num) {
|
|
if (num < 10)
|
|
return '0' + num
|
|
else
|
|
return num + ''
|
|
}
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
age:0,
|
|
sex:0,
|
|
cate_title:'测试分类',
|
|
count:0,//测试总数
|
|
index:0,//当前测试索引
|
|
setindex:-1,
|
|
seconds: 0,
|
|
time: '00:00:00',
|
|
per:0,//进度条
|
|
testlist:[],
|
|
detail:[],
|
|
pidgrade1:0,
|
|
pidgrade2:0,
|
|
pidgrade3:0,
|
|
pidgrade4:0,
|
|
pidgrade5:0,
|
|
pidgrade6:0,
|
|
pidgrade7:0,
|
|
pidgrade8:0,
|
|
setcolor:"#209F84",
|
|
user_id:0,
|
|
uptest_id_index:0,//上一题索引
|
|
upgrade_index:-1,//选项索引分数
|
|
upshow:0,//不显示返回上一题
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.getUserId();
|
|
this.setData({
|
|
age:options.age,
|
|
sex:options.sex,
|
|
})
|
|
},
|
|
|
|
getUserId(){
|
|
var getuser = wx.getStorageSync("userInfo");
|
|
if(getuser){
|
|
this.data.user_id = getuser.id;
|
|
}else if(app.globalData.userInfo){
|
|
this.data.user_id = app.globalData.userInfo.id;
|
|
}else{
|
|
wx.navigateTo({
|
|
url: '/page/login/login',
|
|
});
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
timing(this);//倒计时
|
|
this.gettestlist();
|
|
},
|
|
//获取题目
|
|
gettestlist(){
|
|
var that = this;
|
|
this.setData({ loading: true });
|
|
app.request('/api/mini/testcenter', {sex:this.data.sex}, function (data, ret) {
|
|
//获取成功
|
|
if(ret.code == 1){
|
|
var resdata = ret.data;
|
|
that.setData({
|
|
loading: false,
|
|
count : resdata.count,
|
|
testlist:resdata.lists,
|
|
detail :resdata.detail,
|
|
cate_title:resdata.detail.cate_title,
|
|
});
|
|
}
|
|
|
|
typeof cb == 'function' && cb(data);
|
|
}, function (data, ret) {
|
|
that.setData({
|
|
loading: false
|
|
});
|
|
app.error(ret.msg);
|
|
},2);
|
|
},
|
|
|
|
startClick:function(e){
|
|
var that=this;
|
|
var tmp = e.detail.value;
|
|
var c_title = e.currentTarget.dataset.c_title;
|
|
var pid = e.currentTarget.dataset.pid;
|
|
var grade = e.currentTarget.dataset.grade;
|
|
var setindex = e.currentTarget.dataset.setindex;
|
|
this.setData({
|
|
setindex:setindex,
|
|
uptest_id_index:this.data.index,
|
|
upgrade_index:setindex,
|
|
upshow:1,
|
|
})
|
|
// this.data.detail.selectcenter.forEach((item,index)=>{
|
|
// if(setindex==index){
|
|
// this.data.detail.selectcenter[setindex].setindex = setindex
|
|
// }else{
|
|
// this.data.detail.selectcenter[setindex].setindex = true
|
|
// }
|
|
// })
|
|
|
|
console.log(this.data.detail.selectcenter,"9999")
|
|
var dealgrade = Number(this.data[c_title])+Number(grade);
|
|
console.log(this.data.uptest_id_index)
|
|
var resindex = this.data.index+1;
|
|
//进度条
|
|
var progressNum = Math.floor((this.data.per+ 1.7)*100) / 100;
|
|
this.setData({per:progressNum})
|
|
//end进度条
|
|
if(resindex>=this.data.count){
|
|
this.setData({
|
|
[c_title] :dealgrade,
|
|
})
|
|
console.log("已结束")
|
|
|
|
this.setData({ loading: true });
|
|
app.request('/api/mini/addTest', {
|
|
pidgrade1:this.data.pidgrade1,
|
|
pidgrade2:this.data.pidgrade2,
|
|
pidgrade3:this.data.pidgrade3,
|
|
pidgrade4:this.data.pidgrade4,
|
|
pidgrade5:this.data.pidgrade5,
|
|
pidgrade6:this.data.pidgrade6,
|
|
pidgrade7:this.data.pidgrade7,
|
|
pidgrade8:this.data.pidgrade8,
|
|
usetime:this.data.seconds,
|
|
sex:this.data.sex,
|
|
age:this.data.age,
|
|
user_id:this.data.user_id,
|
|
}, function (data, ret) {
|
|
//获取成功
|
|
if(ret.code == 1){
|
|
// wx.redirectTo({
|
|
// url: '../constitutionGrade/constitutionGrade?res_test_id=' +ret.data.res_test_id
|
|
// })
|
|
wx.redirectTo({
|
|
url: '../shetai/shetai?res_test_id=' +ret.data.res_test_id
|
|
})
|
|
}
|
|
typeof cb == 'function' && cb(data);
|
|
}, function (data, ret) {
|
|
that.setData({
|
|
loading: false
|
|
});
|
|
app.error(ret.msg);
|
|
},2);
|
|
|
|
|
|
|
|
}else{
|
|
var res_detail = this.data.testlist[resindex];
|
|
setTimeout(function () {
|
|
that.setData({
|
|
setindex:-1,
|
|
})
|
|
}, 350)
|
|
this.setData({
|
|
index:resindex,
|
|
detail:res_detail,
|
|
cate_title:res_detail.cate_title,
|
|
[c_title] :dealgrade,
|
|
})
|
|
this.data.testlist[resindex-1].setindex = this.data.setindex
|
|
}
|
|
},
|
|
|
|
upTest:function(){
|
|
if(this.data.uptest_id_index>=0){
|
|
var oridetail = this.data.testlist[this.data.uptest_id_index];
|
|
console.log(oridetail)
|
|
if(oridetail){
|
|
var c_title = 'pidgrade'+oridetail.pid;
|
|
var dealgrade = Number(this.data[c_title])-Number(oridetail.selectcenter[this.data.upgrade_index].grade);
|
|
this.setData({
|
|
uptest_id_index:-1,
|
|
upshow:0,
|
|
[c_title]:dealgrade,
|
|
detail:oridetail,
|
|
index:this.data.index-1
|
|
})
|
|
//进度条
|
|
var progressNum = Math.floor((this.data.per- 1.7)*100) / 100;
|
|
this.setData({per:progressNum})
|
|
}
|
|
|
|
}
|
|
},
|
|
|
|
//点击按钮播放音乐
|
|
playmusic:function(){
|
|
const innerAudioContext = wx.createInnerAudioContext()
|
|
innerAudioContext.autoplay = true
|
|
innerAudioContext.src = '/data/2310.mp3'
|
|
innerAudioContext.onPlay(() => {
|
|
console.log('开始播放')
|
|
})
|
|
innerAudioContext.onError((res) => {
|
|
console.log(res.errMsg)
|
|
console.log(res.errCode)
|
|
})
|
|
},
|
|
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
this.setData({
|
|
per:0,
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}) |