var question_type = ""; var answer_frequency = 300; var answer_click = true; var answer_history = []; var start_lock = false; var topic_id = 11; var quan_val_1 = '5.0'; var quan_val_2 = '5.0'; var quan_val_3 = '5.0'; axios.defaults.baseURL = '/'; $(document).ready(function() { topic_id = $('.topic_id').text(); function linersInit(){ window.r_1 = $('#R_1').slider() .on('slide', function(){ var _dom = $('#score_txt_'+1); _dom.text((window.r_1.getValue()/10).toFixed(1) + '分'); }).on('slideStop',function(){ var _dom = $('#score_txt_'+1); _dom.text((window.r_1.getValue()/10).toFixed(1) + '分'); }) .data('slider'); window.r_2 = $('#R_2').slider() .on('slide', function(){ var _dom = $('#score_txt_'+2); _dom.text((window.r_2.getValue()/10).toFixed(1) + '分'); }).on('slideStop',function(){ var _dom = $('#score_txt_'+2); _dom.text((window.r_2.getValue()/10).toFixed(1) + '分'); }) .data('slider'); window.r_3 = $('#R_3').slider() .on('slide', function () { var _dom = $('#score_txt_'+3); _dom.text((window.r_3.getValue()/10).toFixed(1) + '分'); }).on('slideStop',function(){ var _dom = $('#score_txt_'+3); _dom.text((window.r_3.getValue()/10).toFixed(1) + '分'); }) .data('slider'); $('.min-slider-handle').html('
') r_1.setValue(Number(quan_val_1) * 10,true); r_2.setValue(Number(quan_val_2) * 10,true); r_3.setValue(Number(quan_val_3) * 10,true); } function arcInit(){ var quan_val_4 = $('.quan_val_4').text(); var quan_val_5 = $('.quan_val_5').text(); var quan_val_6 = $('.quan_val_6').text(); var c = document.getElementById('score_con'); if(c.getContext){ c.width = 798; c.height = 220; var ctx = c.getContext('2d'); var data = [ { x:150,y:80,r:75,s:quan_val_4,t:'题目易懂性' },{ x:410,y:80,r:75,s:quan_val_5,t:'结果准确度' },{ x:670,y:80,r:75,s:quan_val_6,t:'建议实操性' } ]; for(var i = 0;i<3;i++){ // 画背景圆 ctx.beginPath(); ctx.lineWidth = 10; ctx.strokeStyle = '#efefef'; ctx.arc(data[i].x,data[i].y,data[i].r,0,Math.PI*2,true); ctx.closePath(); ctx.stroke(); ctx.save(); ctx.beginPath(); ctx.translate(data[i].x,data[i].y); ctx.rotate(-Math.PI*0.5); // 定义阴影 ctx.shadowOffsetY = 8; ctx.shadowBlur = 14; ctx.shadowColor = "rgba(248, 72, 94, 0.2)"; ctx.strokeStyle = '#f8485e'; ctx.lineWidth = 10; ctx.lineCap = 'round'; // 画分数线 if(data[i].s == 5){ ctx.arc(0,0,data[i].r,0,(5)*2/5*Math.PI,true); }else if(data[i].s == 0){ ctx.arc(0,0,data[i].r,0,(0)*2/5*Math.PI,true); }else if(data[i].s > 0){ ctx.arc(0,0,data[i].r,0,(2-0.4*data[i].s)*Math.PI,true); } ctx.stroke(); ctx.restore(); // 写文字 ctx.lineWidth = 1; ctx.fillStyle = "#666666"; ctx.font = "22px serif"; ctx.textAlign = 'center' ctx.fillText("平均", data[i].x, data[i].y-10); ctx.font = "30px serif"; ctx.fillText(data[i].t, data[i].x, data[i].y+130); ctx.font = "30px serif"; ctx.strokeStyle = "#f8485e"; ctx.fillStyle = "#f8485e"; ctx.lineWidth = 2; ctx.strokeText(data[i].s+'分', data[i].x, data[i].y+23); ctx.fillText(data[i].s+'分', data[i].x, data[i].y+23); } }; for(var t = 0;t<3;t++){ var tempS = data[t].s.toString(); if(tempS.length == 1){ tempS = tempS + '.0'; } $(".sc"+t).text(tempS); $(".ping_line"+t).find(".ping_true_leng").css('width',data[t].s*10*14+'px'); $(".ping_line"+t).find(".ping_line_btn").css('left',data[t].s*10*14-12+'px'); (function(ts){ $(".ping_line"+ts).find(".ping_line_btn").bind('mousedown',function(e){ var startX = e.pageX; var lengL = parseInt($(".ping_line"+ts).find(".ping_true_leng").css('width')); var btnL = parseInt($(".ping_line"+ts).find(".ping_line_btn").css('left')); $(".ping_line"+ts).bind('mousemove',function(es){ if(lengL+es.pageX-startX>0&&lengL+es.pageX-startX<705){ $(".ping_line"+ts).find(".ping_true_leng").css('width',lengL+es.pageX-startX+'px'); var sc = parseFloat(parseInt((lengL+es.pageX-startX)/14)/10); if(sc.toString().length <= 1){ sc = sc+'.0'; } $(".ping_line"+ts).siblings('.current_score').find('span').text(sc); } if(btnL+es.pageX-startX>-12&&btnL+es.pageX-startX<693){ $(".ping_line"+ts).find(".ping_line_btn").css('left',btnL+es.pageX-startX+'px'); } }); }); $(".ping_line"+ts).find(".ping_line_btn").bind('mouseup',function(){ $(".ping_line"+ts).unbind('mousemove'); }); $(".ping_line"+ts).bind('mouseup',function(){ $(".ping_line"+ts).unbind('mousemove'); }); })(t) }; } function checkLogin(is_go_login){//验证登录 var is_login = localStorage.getItem('08_user_token'); if(is_go_login && !is_login){ window.location.href = "/login/"; } return is_login; } function checkAnswer(){ //是否已测过过当前题 return true; } function checkCommand(){ //是否已评论过当前题 return false; } function init(){ } init(); linersInit(); arcInit(); $('#start_answer').click(function(){ if(start_lock){ return; } start_lock = true; // if(!checkLogin(true)){ // start_lock = false; // return false; // } //过渡动画,正在准备测试题目 $.ajax({ type: "get", url: "/api_v1/test/questions", dataType: 'json', data: { topic_id:topic_id, user_token:localStorage.getItem('08_user_token') }, success:function(res){ // if(res.status == 0){ // window.location.href = "/login/"; // return; // } var questions = res.data.questions; question_type = questions[0].options[0].type; for(var i = 0;i' + answer.value +'.'+ answer.title + '' } var swiper_silde =$('
\n' + '
' + (i+1) + '/'+res.data.questions.length+'
\n' + '
' + res.data.questions[i].title + '
\n' + '
\n' + answer_arr + '
\n' + '
') $('#ques').append(swiper_silde); } $('.ques_start').hide(); $('.ques_ing').show(); setTimeout(function(){ var swiper_question = new Swiper('.ques_ing', { onInit:function(){ $('.btn_prev').hide(); }, autoHeight:true, speed:answer_frequency, onSlideChangeStart: function(swiper){ if(swiper.activeIndex == 0){ $('.btn_prev').hide(); }else{ $('.btn_prev').show(); } if(swiper.activeIndex + 1 == swiper.slides.length){ //显示结果按钮 $('.btn_result').css('display','inline-block'); }else{ $('.btn_result').hide(); } }, }); $('.btn_prev').click(function(){ if(question_type == "score"){ swiper_question.slidePrev(); }else{ if(answer_history.length == 0){ return; } var index = $('.swiper-slide[ques-id="'+ answer_history[answer_history.length-1] + '"]').index(); answer_history.pop(); swiper_question.slideTo(index); } }) $('.answer').click(function(){ if(!answer_click){ console.log('禁止连续点击'); return; } answer_click = false; setTimeout(function(){ answer_click = true; },answer_frequency) var next_id = $(this).attr('next-id'); if(question_type == "score"){ swiper_question.slideNext(); }else{ var next_id = $(this).attr('next-id'); var que_id = $(this).attr('que-id'); answer_history.push(que_id); if(next_id == 0 || !next_id){ $('.btn_result').css('display','inline-block'); }else{ var index = $('.swiper-slide[ques-id="'+ next_id + '"]').index(); swiper_question.slideTo(index); } } console.log(answer_history); }) $("body,html").animate({scrollTop:0},400); },10) start_lock = false; }, error: function () { //获取题目失败 start_lock = false; } }); }) $('#command_btn').click(function(){ if(!checkLogin(true)){ return false; } $('#test_score_1').hide(); $('#test_score_2').show(); }) $('#submit_command').click(function(){ //提交评分 //提交内容 var content = $('#textarea').val(); if(content.length > 200){ alert('sorry,评论有点长了鸭~'); return false; } if(content.length == 0){ alert('写一些呗'); return false; } //提交评论 axios({ url: '/api_v1/test/user/comment/', method: 'post', data: { topic_id:topic_id, user_token:checkLogin(), content:content }, }).then(function (res) { console.log(res); if(res.errorCode == 0){ alert('评论成功'); $('#test_score_2').hide(); $('#test_score_1').show(); }else{ alert('评论失败'); } }).catch(function (error) { console.log(error); alert('评论失败'); }) }) $('.btn_result').click(function(){ //等待动画 //获取答案 $.ajax({ type: 'POST', url: '/api_v1/test/user/result/', dataType: 'json', data: { user_token:checkLogin(), topic_id:topic_id, }, success: function (res) { if(res.errorCode != 0){ //错误啦 return; } $('#answer_content').text(res.data.content); $('#answer_tit').text(res.data.title); $('#answer_time span').text(getDate(new Date().getTime())); $('.test_info').hide(); $('.ques_result').show(); }, error: function (err) { //提示获取答案失败 } }); }) function getDate(sjc){ var date = new Date(sjc); Y = date.getFullYear() + '-'; M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'; D = date.getDate() + ' '; h = date.getHours() + ':'; m = date.getMinutes() + ':'; s = date.getSeconds(); return Y+M+D+h+m+s; } $('.yxd_banner').click(function(){ //打开意向单 }) $('.back_testing').click(function(){ window.history.back(); // $('.ques_ing').hide(); // $('.ques_start').show(); }) $(".sou").click(function(){ $(".souDiv").fadeIn(); }); $(".souClose").click(function(){ $(".souDiv").fadeOut(); }); $(".souInput ._span").click(function(){ var href = location.origin; var val = $(".souInput input").val(); location.href = href + '/search?name=' + val; }); // if(localStorage.getItem('08_user_token')){ // $('.afterLogin').removeClass('hideAvatar').addClass('showAvatar'); // $(".side_login a").text('个人中心').attr('href','/user/') // } // //用户登陆状态校验 // $.ajax({ // type: "get", // url: '/api_v1/user/status', // dataType: 'json', // cache: false, // success: function (data) { // if (data.status == 'success') { // $('.afterLogin img').attr('src', data.data.head_image); // $('.afterLogin').removeClass('hideAvatar').addClass('showAvatar'); // } // }, // error: function (xhr, status, error) { // // } // }); });