answer_dq.js 4.37 KB
//31
var paperType=1;
function submitAnswer(){
    var result={};
    
    var usreName=$("#userName").val();
    var userPhone=$("#userPhone").val();
    if(userName==null||userName==undefined||userName==''){
        layer.msg("请填写姓名")
        return;
    }
    if(userPhone==null||userPhone==undefined||userPhone==''){
        //倒计时时间到了,还没有填写手机号信息,则无效
        if(maxtime==0){
            layer.msg('时间到!');
        }else{
            layer.msg("请填写电话号")
        }
        return;
    }
    if(!checkPhone()){
        return;
    }
    var paramAnswer={
        "paperType":paperType,
        "username":usreName,
        "userPhone":userPhone,
        "examTime":examTime
    }
    result.answer=paramAnswer;

    var d=[];
    $("input[name='answer']").each(function(j,item){
      var param={
          "orders":j+1,
          "answer":item.value
      }
      d[j]=param;
    });
    var textarea=$("#answer_text").val();
    var pic='';
    $("input[name='pic']").each(function(){
        pic+=$(this).val()+","
    }
    )
    var param={
          "orders":20,
          "answer":textarea,
          "pic":pic
      }
    d[30]=param;
    result.answerDetails=d;
   
    $.ajax({
        type: "post",
        dataType: "json",
        contentType:"application/json",
        url:prefix+"/answer/submitExam",
        data: JSON.stringify( result),
        success:function(r) {
            if (r.code == 200) {
                //location.href = ctx + 'index';
                layer.open({
                    time:3000,
                    content:'提交成功!每人限制提交一次。'
                })
                getAnswerByPhone(userPhone);
                permitKey()
                $(".pull-right").hide();
            } else if(r.code==202){
                layer.open({
                    time:3000,
                    content:r.msg
                })
                getAnswerByPhone(userPhone);
                permitKey()
                $(".pull-right").hide();
            }
        }
    });
}

function getAnswerByPhone(userPhone){
    //var userPhone=$("#userPhone").val();
    var result={
            "answer":{
            "userPhone":userPhone,
            "paperType":paperType
            },
             "answerDetails":[{
             }]

        }
    $.ajax({
        type: "post",
        dataType: "json",
        contentType:"application/json",
        url:prefix+"/answer/getAnswerByPhone",
        data: JSON.stringify( result),
        success:function(r) {
            if (r.code == 200) {
                $("#hiddenSubmit").hide();
                $(".pull-right").hide();
                var answer=r.data.answer;
                var answerDetails=r.data.answerDetails;
                $("#userPhone").val(answer.userPhone);
                $("#userName").val(answer.username);
                $("#userPhone").attr("readOnly",true);
                $("#userName").attr("readOnly",true);
                answerDetails.forEach(function(obj,index,array){
                    if(index!=30){
                        $("input[name='answer']")[index].value=obj.answer;
                        $("input[name='answer']")[index].readOnly=true;
                    }else{
                        $(".file").hide();
                        $("#answer_text").attr("readOnly",true);
                        $("#answer_text").val(obj.answer);        
                        var imgSrc=obj.pic;
                        var boxId = ".content-img-list";
                        addNewContentV(boxId,imgSrc);
                    }
                });
            } else {
            	
            }
        }
    });
}
 //图片展示
 function addNewContentV(obj,imgSrcs) {
    // console.log(imgSrc)
    $(obj).html("");
    var imgSrc=imgSrcs.split(",");
    for (var a = 0; a < imgSrc.length; a++) {
        if(imgSrc[a]!=''&&imgSrc[a]!=undefined){
            var oldBox = $(obj).html();
            $(obj).html(oldBox + '<li class="content-img-list-item"><img src="' + imgSrc[a] + '" alt="">' +
                '<div class="hide"><a index="' + a + '" class="delete-btn"><i class="gcl gcllajitong"></i></a>' +
                '<a index="' + a + '" class="big-btn" type="button" data-toggle="modal" data-target=".bs-example-modal-lg"><i class="gcl gclfangda"></i></a></div></li>');

        }
    }
}


$(document).ready(function(){
    
    });