answer_jx2.js
4.11 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//24input,7个textarea
var paperType=5
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;
$("input[name='answer']").each(function(j,item){
var param={
"orders":j+1,
"answer":item.value
}
orderNum=j;
d[j]=param;
});
var pic='';
$("input[name='pic']").each(function(){
pic+=$(this).val()+","
}
)
var pic2='';
$("input[name='pic2']").each(function(){
pic2+=$(this).val()+","
}
)
$("textarea[name='answer']").each(function(j,item){
var num=j+1+orderNum;
var param={};
if(j==5){
param={
"orders":num,
"answer":item.value,
"pic":pic
}
}else if(j==6){
param={
"orders":num,
"answer":item.value,
"pic":pic2
}
}else{
param={
"orders":num,
"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) {
//location.href = '#';
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);
var inputIndex=0;
answerDetails.forEach(function(obj,index,array){
if(index<=23){
$("input[name='answer']")[index].value=obj.answer;
$("input[name='answer']")[index].readOnly=true;
}else{
$("textarea[name='answer']")[inputIndex].value=obj.answer;
$("textarea[name='answer']")[inputIndex].readOnly=true;
inputIndex++;
}
});
} else {
}
}
});
}
$(document).ready(function(){
});