answer_net.js
3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//14
var paperType=4;
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=[];
var orderNum=0;
$("textarea[name='answer']").each(function(j,item){
var param={
"order":j+1,
"answer":item.value
}
orderNum=j;
d[j]=param;
});
$("input[name='answer']").each(function(j,item){
var num=j+1+orderNum;
var param={
"order":j+1+orderNum,
"answer":item.value
}
d[num]=param;
});
result.answerDetails=d;
console.log(result)
$.ajax({
type: "post",
dataType: "json",
contentType:"application/json",
url:prefix+"/answer/submitExam",
data: JSON.stringify( result),
success:function(r) {
if (r.code == 200) {
layer.open({
time:3000,
content:'提交成功!每人限制提交一次。'
})
getAnswerByPhone(userPhone);
permitKey()
} else if(r.code==202){
layer.open({
time:3000,
content:r.msg
})
getAnswerByPhone(userPhone);
permitKey()
}
}
});
}
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){
$("textarea[name='answer']")[index].value=obj.answer;
$("textarea[name='answer']")[index].readOnly=true;
});
} else {
}
}
});
}
$(document).ready(function(){
});