var guid;
var name;
$(function () {
guid = getQueryString("eid");
name = getQueryString("name");
Load(guid);
$("#Add").click(Add);
})
function Load() {
$.ajax({
type: "POST",
url: actionUrl + "?method=GetSujectByExamId",
data: { guid: guid },
cache: false,
success: function (d) {
$("#name").html(name);
$("#f_ExamId").val(name);
$("#f_ExamName").val(name);
if (d["subscore"].length > 0) {
initcheckSubject("SubjectName", d["subject"]);
SubScoreLoad(d["subscore"]);
} else {
initcheckSubject("SubjectName", d["subject"]);
}
}
})
}
//拼接学科
function initcheckSubject(id, jsondata) {
var pmyesorno = jsondata[0].f_Rank == 0 ? "<a href=‘#‘ onclick=‘javascript:SetCannocmstEdit(\"" + jsondata[0].f_Id + "\",\"" + 1 + "\",\"" + 0 + "\")‘ value=‘0‘ id=‘f_Rank0‘ class=‘ranking_button true‘></a>" : "<a href=‘#‘ id=‘f_Rank0‘ onclick=‘javascript:SetCannocmstEdit(\"" + jsondata[0].f_Id + "\",\"" + 0 + "\",\"" + 0 + "\")‘ value=‘1‘ class=‘ranking_button false‘></a>";
var strq = "<td><input type=‘text‘ id=‘f_SubName0‘ name=‘f_SubName‘ value=‘" + jsondata[0].f_SubJectName + "‘/><input type=‘hidden‘ name=‘f_Id‘ id=‘f_Id" + i + "‘ value=‘" + jsondata[0].f_Id + "‘/><input type=‘hidden‘ name=‘f_SubId‘ value=‘" + jsondata[0].f_SubJectId + "‘ id=‘f_SubId0‘/></td>" +
"<td><input type=‘text‘ id=‘f_Out0‘ name=‘f_Out‘ required=‘true‘ onKeyUp=‘clearNoNum(event,this)‘ onBlur=‘GetAllOut()‘ onfocus=‘GetAllOut()‘ onpaste=‘return false‘ value=‘100‘ maxlength=‘3‘ /></td>" +
"<td><select class=‘term‘ id=‘f_Type0‘ name=‘f_Type‘><option value=‘1‘>分数</option><option value=‘2‘ >百分比</option><option value=‘3‘ >人数</option></select></td>" +
"<td><input type=‘text‘ id=‘f_Fine0‘ name=‘f_Fine‘ required=‘true‘ onKeyUp=‘clearNoNum(event,this)‘ onBlur=‘GetAllOut()‘ onfocus=‘GetAllOut()‘ onpaste=‘return false‘ value=‘90‘ maxlength=‘3‘ /></td>" +
"<td><input type=‘text‘ id=‘f_Good0‘ name=‘f_Good‘ required=‘true‘ onKeyUp=‘clearNoNum(event,this)‘ onBlur=‘GetAllOut()‘ onfocus=‘GetAllOut()‘ onpaste=‘return false‘ value=‘80‘ maxlength=‘3‘ /></td>" +
"<td><input type=‘text‘ id=‘f_Pass0‘ name=‘f_Pass‘ required=‘true‘ onKeyUp=‘clearNoNum(event,this)‘ onBlur=‘GetAllOut()‘ onfocus=‘GetAllOut()‘ onpaste=‘return false‘ value=‘60‘ maxlength=‘3‘ /></td>" +
"<td><input type=‘text‘ id=‘f_Score0‘ name=‘f_Score‘ style=‘width:200px‘readOnly=‘true‘ value=‘0-60,60-80,80-100‘ onclick=‘javascript:UpdateScore(\"" + 0 + "\",\"" + name + "\")‘ /></td><td>" + pmyesorno + "</td>" +
"<td><input type=‘button‘ value=‘统一设置‘ onclick=‘javascript:UnitySetUp(\"" + jsondata.length + "\")‘ id=‘Set‘ class=‘op_button‘ style=‘background: #6263F9;cursor:pointer‘/></td>";
$("#SubjectName0").append(strq);
var pmyetype = "";
for (var i = 1; i < jsondata.length ; i++) {
pmyetype = jsondata[i].f_Rank == 0 ? "<a href=‘#‘ onclick=‘javascript:SetCannocmstEdit(\"" + jsondata[i].f_Id + "\",\"" + 1 + "\",\"" + i + "\")‘ id=‘f_Rank" + i + "‘ value=‘0‘ class=‘ranking_button true‘></a>" : "<a href=‘#‘ onclick=‘javascript:SetCannocmstEdit(\"" + jsondata[i].f_Id + "\",\"" + 0 + "\",\"" + i + "\")‘ id=‘f_Rank" + i + "‘ value=‘1‘ class=‘ranking_button false‘></a>";
var str = "<tr id=‘SubjectName" + i + "‘ name=‘SubjectName‘><td><input type=‘text‘ id=‘f_SubName" + i + "‘ name=‘f_SubName‘ value=‘" + jsondata[i].f_SubJectName + "‘/><input type=‘hidden‘ name=‘f_Id‘ id=‘f_Id" + i + "‘ value=‘" + jsondata[i].f_Id + "‘ /> <input type=‘hidden‘ value=‘" + jsondata[i].f_SubJectId + "‘ name=‘f_SubId‘ id=‘f_SubId" + i + "‘/> </td>" +
"<td><input type=‘text‘ id=‘f_Out" + i + "‘ name=‘f_Out‘ required=‘true‘ onKeyUp=‘clearNoNum(event,this)‘ onBlur=‘GetAllOut()‘ onfocus=‘GetAllOut()‘ onpaste=‘return false‘ value=‘100‘ maxlength=‘3‘ /></td> " +
"<td><select class=‘term‘ id=‘f_Type" + i + "‘ name=‘f_Type‘><option value=‘1‘ >分数</option><option value=‘2‘ >百分比</option><option value=‘3‘ >人数</option></select></td>" +
"<td><input type=‘text‘ id=‘f_Fine" + i + "‘ name=‘f_Fine‘ required=‘true‘ onKeyUp=‘clearNoNum(event,this)‘ onBlur=‘GetAllOut()‘ onfocus=‘GetAllOut()‘ onpaste=‘return false‘ value=‘90‘ maxlength=‘3‘ /></td>" +
"<td><input type=‘text‘ id=‘f_Good" + i + "‘ name=‘f_Good‘ required=‘true‘ onKeyUp=‘clearNoNum(event,this)‘ onBlur=‘GetAllOut()‘ onfocus=‘GetAllOut()‘ onpaste=‘return false‘ value=‘80‘ maxlength=‘3‘ /></td>" +
"<td><input type=‘text‘ id=‘f_Pass" + i + "‘ name=‘f_Pass‘ required=‘true‘ onKeyUp=‘clearNoNum(event,this)‘ onBlur=‘GetAllOut()‘ onfocus=‘GetAllOut()‘ onpaste=‘return false‘ value=‘60‘ maxlength=‘3‘ /></td>" +
"<td><input type=‘text‘ id=‘f_Score" + i + "‘ name=‘f_Score‘ style=‘width:200px‘readOnly=‘true‘ value=‘0-60,60-80,80-100‘ onclick=‘javascript:UpdateScore(\"" + i + "\",\"" + name + "\")‘ /></td><td>" + pmyetype + "</td>" +
"<td><input type=‘button‘ value=‘同上‘ id=‘Ditto‘ onclick=‘javascript:SetDitto(\"" + (i - 1) + "\",\"" + i + "\")‘ style=‘cursor:pointer;‘ class=‘op_button‘/></td></tr>";
$("#" + id).append(str);
}
var last = tarPhtml.format(jsondata.length,name);
$("#" + id).append(last);
GetAllOut();
}
//设置分数段
function UpdateScore(i, examname) {
var AddDialog = top.$.hDialog({
href: add_html,
content: add_html,
title: ‘成绩分数段设置‘,
width: 420,
height: 350,
modal: true,
shadow: true,
minimizable: false,
maximizable: false,
collapsible: false,
onLoad: function () {
top.$("#ExamName").html(examname);
top.$("#SubjectName").html($("#f_SubName" + i).val());
var ss;
var test = $("#f_Score" + i).val();
ss = test.replace(/-/g, ",");
ScoreSet(ss,test);
},
submit: function () {
var num = top.document.getElementsByName("Score");
var score = Score(num.length);
$("#f_Score" + i).val(score);
AddDialog.dialog(‘close‘);
}
})
}
//分数段设置
function ScoreSet(ss, test) {
var arry = ss.split(",");
for (var i = 0; i < arry.length; i++) {
top.$("#BuyNumber" + i).val(arry[i]);
}
}
//分数段设置
function Score(num) {
var list = [];
var obj = {};
for (var i = 0; i < num; i++) {
obj = {};
var score = "";
obj.Score = top.$("#BuyNumber" + i).val();
score = top.$("#BuyNumber" + (i + 1)).val();
obj.Score = obj.Score + ‘-‘;
obj.Score = obj.Score + score;
if (i != (num - 1)) {
obj.Score = obj.Score + ‘,‘;
}
i++;
list.push(obj);
}
return ArrayToString(list);
}
//数组转换为字符串
function ArrayToString(arr) {
var strTmp = "";
for (var i = 0; i < arr.length; i++) {
if (arr[i]["Score"] != "") {
if (strTmp == "") {
strTmp = arr[i]["Score"];
} else {
strTmp = strTmp + arr[i]["Score"];
}
}
}
var newstr = strTmp.substring(0, strTmp.length - 1);
return newstr;
}
//设置分数保存
function Add() {
$.ajax({
type: "POST",
url: actionUrl + "?method=ScoreGradeSet",
data: {
list: JSON.stringify(List()),
guid: guid
},
cache: false,
success: function (data) {
$.messager.alert("提示", "设置成功!", "info");
location.reload(true);
}
});
}
//把设置好的分数加入到list数组中
function List() {
var num = document.getElementsByName("SubjectName");
var list = [];
var score = "";
for (var i = 0; i < num.length; i++) {
obj = {};
obj.f_GUID = guidGenerator();
obj.f_ExamName = name;
obj.f_ExamId = guid;
obj.f_Out = $("#f_Out" + i).val();
obj.f_SubId = $("#f_SubId" + i).val();
obj.f_SubName = $("#f_SubName" + i).val();
obj.f_Type = $("#f_Type" + i).val();
if (obj.f_Type == 1) {
obj.f_TypeName = "分数";
} else if (obj.f_Type == 2) {
obj.f_TypeName = "百分比";
} else {
obj.f_TypeName = "人数";
}
obj.f_Score = $("#f_Score" + i).val();
obj.f_Fine = $("#f_Fine" + i).val();
obj.f_Good = $("#f_Good" + i).val();
obj.f_Pass = $("#f_Pass" + i).val();
list.push(obj);
}
return list
}
//加载分数
function SubScoreLoad(jsondata) {;
for (var i = 0; i < jsondata.length - 1 ; i++) {
$("#f_Out" + i).val(jsondata[i].f_Out);
$("#f_SubId" + i).val(jsondata[i].f_SubId);
$("#f_SubName" + i).val(jsondata[i].f_SubName);
$("#f_Type" + i).val(jsondata[i].f_Type);
$("#f_Fine" + i).val(jsondata[i].f_Fine);
$("#f_Good" + i).val(jsondata[i].f_Good);
$("#f_Pass" + i).val(jsondata[i].f_Pass);
$("#f_Score" + i).val(jsondata[i].f_Score);
}
}
//设置排序是否
function SetCannocmstEdit(id, rank, i) {
if (rank == 1) {
$.ajax({
type: "POST",
cache: false,
dataType: "json",
url: actionUrl + "?method=SetCannocms",
data: {
Id: id,
Rank: rank
},
success: function (data) {
$.messager.alert("成功", "设置成功", "info");
// location.reload(true);
$("#f_Rank" + i).attr("value", "1");
$("#f_Rank" + i).attr("class", "ranking_button false");
$("#f_Rank" + i).attr("onclick", "SetCannocmstEdit(‘" + id + "‘,‘" + 0 + "‘,‘" + i + "‘)");
GetAllOut();
}
});
} else {
$.ajax({
type: "POST",
cache: false,
dataType: "json",
url: actionUrl + "?method=SetCannocms",
data: {
Id: id,
Rank: rank
},
success: function (data) {
$.messager.alert("成功", "设置成功", "info");
//location.reload(true);
$("#f_Rank" + i).attr("value", "0");
$("#f_Rank" + i).attr("class", "ranking_button true");
$("#f_Rank" + i).attr("onclick", "SetCannocmstEdit(‘" + id + "‘,‘" + 1 + "‘,‘" + i + "‘)");
GetAllOut();
}
});
}
}
//统一设置
function UnitySetUp(jsondata) {
var f_Out = "";
var f_Fine = "";
var f_Good = "";
var f_Pass = "";
var f_Type = "";
var rank = $("#f_Rank0").attr("value")
$.ajax({
type: "POST",
cache: false,
dataType: "json",
url: actionUrl + "?method=SetAllRank",
data: {
ExamId: guid,
Rank: rank
},
success: function (data) {
$.messager.alert("成功", "设置成功", "info");
}
});
for (var i = 1; i < jsondata; i++) {
f_Out = $("#f_Out0").val();
f_Fine = $("#f_Fine0").val();
f_Good = $("#f_Good0").val();
f_Pass = $("#f_Pass0").val();
f_Type = $(‘#f_Type0‘).val();
$("#f_Out" + i).val(f_Out);
$("#f_Fine" + i).val(f_Fine);
$("#f_Good" + i).val(f_Good);
$("#f_Pass" + i).val(f_Pass);
$("#f_Type" + i).val(f_Type);
if (rank == 0) {
$("#f_Rank" + i).attr("class", "ranking_button true");
$("#f_Rank" + i).attr("value", "0");
$("#f_Rank" + i).attr("onclick", "SetCannocmstEdit(‘" + $("#f_Id" + i).val() + "‘,‘" + 1 + "‘,‘" + i + "‘)");
} else {
$("#f_Rank" + i).attr("class", "ranking_button false");
$("#f_Rank" + i).attr("value", "1");
$("#f_Rank" + i).attr("onclick", "SetCannocmstEdit(‘" + $("#f_Id" + i).val() + "‘,‘" + 0 + "‘,‘" + i + "‘)");
}
}
GetAllOut();
}
//同上
function SetDitto(j, i) {
SetCannocmstEdit($("#f_Id" + i).val(), $("#f_Rank" + j).attr("value"), i)
var f_Out = $("#f_Out" + j).val();
var f_Fine = $("#f_Fine" + j).val();
var f_Good = $("#f_Good" + j).val();
var f_Pass = $("#f_Pass" + j).val()
var f_Score = $("#f_Score" + j).val()
var type = $(‘#f_Type‘ + j).val();
$("#f_Out" + i).val(f_Out);
$("#f_Fine" + i).val(f_Fine);
$("#f_Good" + i).val(f_Good);
$("#f_Pass" + i).val(f_Pass);
$("#f_Score" + i).val(f_Score);
$("#f_Type" + i).val(type);
}
//根据字段名获取request里面对应的值
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = decodeURI(window.location.search.substr(1)).match(reg);
if (r != null) return unescape(r[2]); return null;
}
function clearNoNum(event, obj) {
//响应鼠标事件,允许左右方向键移动
event = window.event || event;
if (event.keyCode == 37 | event.keyCode == 39) {
return;
}
//先把非数字的都替换掉,除了数字和.
obj.value = obj.value.replace(/[^\d.]/g, "");
//必须保证第一个为数字而不是.
obj.value = obj.value.replace(/^\./g, "");
//保证只有出现一个.而没有多个.
obj.value = obj.value.replace(/\.{2,}/g, ".");
//保证.只出现一次,而不能出现两次以上
obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
}
//总分设置
function GetAllOut() {
var num = document.getElementsByName("SubjectName");
var f_outscore = "";//满分
var f_finescore = "";//优秀
var f_goodscore = "";//良好
var f_passscore = "";//及格
for (var i = 0; i < num.length - 1; i++) {
if ($("#f_Rank" + i).attr("value") == 0) {
f_outscore = Number(f_outscore) + Number($("#f_Out" + i).val());
f_finescore = Number(f_finescore) + Number($("#f_Fine" + i).val());
f_goodscore = Number(f_goodscore) + Number($("#f_Good" + i).val());
f_passscore = Number(f_passscore) + Number($("#f_Pass" + i).val());
$("#SubjectName" + i).attr("style", "background:White");
} else {
$("#SubjectName" + i).attr("style", "background:red");
}
if ((i + 1) == (num.length - 1)) {
$("#f_Out" + (num.length - 1)).val(f_outscore);
$("#f_Fine" + (num.length - 1)).val(f_finescore);
$("#f_Good" + (num.length - 1)).val(f_goodscore);
$("#f_Pass" + (num.length - 1)).val(f_passscore);
}
}
}
//原光标离开事件(现改为GetAllOut())
//function checkNum(obj) {
// //onBlur、onfocus事件换为checkNum(this)
// //checkNum(this)
// var num = document.getElementsByName("SubjectName");
// var f_outscore = "";//满分
// var f_finescore = "";//优秀
// var f_goodscore = "";//良好
// var f_passscore = "";//及格
// for (var i = 0; i < num.length-1; i++) {
// if ($("#f_Rank" + i).attr("value") == 0) {
// f_outscore = Number(f_outscore) + Number($("#f_Out" + i).val());
// f_finescore = Number(f_finescore) + Number($("#f_Fine" + i).val());
// f_goodscore = Number(f_goodscore) + Number($("#f_Good" + i).val());
// f_passscore = Number(f_passscore) + Number($("#f_Pass" + i).val());
// }
// if ((i + 1) == num.length - 1) {
// $("#f_Out" + (num.length - 1)).val(f_outscore);
// $("#f_Fine" + (num.length - 1)).val(f_finescore);
// $("#f_Good" + (num.length - 1)).val(f_goodscore);
// $("#f_Pass" + (num.length - 1)).val(f_passscore);
// }
// }
//}
function DigitInput(obj, event) {
//响应鼠标事件,允许左右方向键移动
event = window.event || event;
if (event.keyCode == 37 | event.keyCode == 39) {
return;
}
obj.value = obj.value.replace(/\D/g, "");
}
//生成GUID
function guidGenerator() {
var S4 = function () {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
};
return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}
//拼接总分
var tarPhtml = "<tr id=‘SubjectName{0}‘ name=‘SubjectName‘><td><input type=‘text‘ id=‘f_SubName{0}‘ name=‘f_SubName‘ value=‘总分‘/><input type=‘hidden‘ value=‘0‘ name=‘f_SubId‘ id=‘f_SubId{0}‘/> </td>" +
"<td><input type=‘text‘ id=‘f_Out{0}‘ name=‘f_Out‘ required=‘true‘ readOnly=‘true‘ onpaste=‘return false‘ maxlength=‘4‘ /></td> " +
"<td><select class=‘term‘ id=‘f_Type{0}‘ name=‘f_Type‘><option value=‘1‘>分数</option><option value=‘2‘>百分比</option><option value=‘3‘>人数</option></select></td>" +
"<td><input type=‘text‘ id=‘f_Fine{0}‘ name=‘f_Fine‘ required=‘true‘ onKeyUp=‘clearNoNum(event,this)‘ onBlur=‘checkNum(this)‘ onpaste=‘return false‘ maxlength=‘3‘ /></td>" +
"<td><input type=‘text‘ id=‘f_Good{0}‘ name=‘f_Good‘ required=‘true‘ onKeyUp=‘clearNoNum(event,this)‘ onBlur=‘checkNum(this)‘ onpaste=‘return false‘ maxlength=‘3‘ /></td>" +
"<td><input type=‘text‘ id=‘f_Pass{0}‘ name=‘f_Pass‘ required=‘true‘ onKeyUp=‘clearNoNum(event,this)‘ onBlur=‘checkNum(this)‘ onpaste=‘return false‘ maxlength=‘3‘ /></td>" +
"<td><input type=‘text‘ id=‘f_Score{0}‘ name=‘f_Score‘ style=‘width:200px‘ readOnly=‘true‘ value=‘0-400,400-500,500-600‘ onclick=‘javascript:UpdateScore(\"{0}\",\"{1}\")‘ />" +
"</td><td><a id=‘f_Rank{0}‘ value=‘0‘ class=‘ranking_button true‘></a></td>" +
"<td><input type=‘button‘ value=‘/‘ id=‘Ditto‘ class=‘op_button‘/></td></tr>";