var QuestionOption = new arrayHelper("Sort");//选项 var QuestionAnswer = new arrayHelper("Sort");//答案 var QuestionAttachments = new arrayHelper("Name");//附件 var QuestionOption2 = new arrayHelper("Sort");//选项 var QuestionAnswer2 = new arrayHelper("Sort");//答案 var QuestionAttachments2 = new arrayHelper("Name");//附件 var CurQuestionCount = 0; $(function () { //文件选择 $("#FileChoose").click(function () { $("#HFilePath").click(); }); //将file的值赋值给input $("#HFilePath").live("change", function () { var filepath = $(this).val(); $("#filePath").val(filepath); }); $("#btnAdd").attr('disabled', false); //上传附件按钮 $("#btnAdd").click(function () { dialogHelper.Show("addpop", 756); $("#txtResourceName").val(""); $("#filePath").val(""); }); //附件确定按钮 $("#FileUpload").click(function () { FileUpload(); }); //附件上传取消按钮 $("#addclose").click(function () { dialogHelper.Close("addpop"); $("#filePath").val(""); $("#HFilePath").val(""); var CurQuestionCounts = $("#CurQuestionCount").html(); QuestionAttachments.Remove(CurQuestionCounts); }); //保存按钮 $("#preserve").click(function () { //章节Id var TheoryChapterId = $.getUrlParam("TheoryChapterId"); var typeid = $.getUrlParam("typeid"); var PaperId = $("#TestPapersId").val(); AddTitle(TheoryChapterId, typeid, PaperId); }); }); var Index = 0; //加载试题 function LoadTitle(QuestionId) { var Id = $("#TestPapersId").val(); $.ajax({ url: "/Teacher/TheoryQuestion/GetQuestionObj", async: false, type: "POST", data: { QuestionId: QuestionId, PapersId: Id }, success: function (data) { QuestionOption.RemoveAll();//选项 QuestionAnswer.RemoveAll(); //答案 QuestionAttachments.RemoveAll(); //附件 QuestionOption2.RemoveAll();//选项 QuestionAnswer2.RemoveAll(); //答案 QuestionAttachments2.RemoveAll(); //附件 var mode = data.TE; if (mode.Context != "") { $("#Context").val(mode.Context); $("#Analysis").val(mode.Analysis); $("#option").find("li").remove(); $("#QuestionIdAdd1").val(mode.Id); if (mode.Source == 1) { $("#CurFrom").html("内置"); $("#preserve").attr('disabled', true); $("#preserve").css("background-color", "#808080"); } else { $("#CurFrom").html("自定义"); $("#preserve").attr('disabled', false); $("#preserve").css("background-color", "#00a2e2"); } } //选项 if (mode.OptionList != null) { var html = ""; $.each(mode.OptionList, function (i, n) { QuestionOption.Add(n); QuestionOption2.Add(n); }); } //附件 if (mode.AttachmentList != null) { $.each(mode.AttachmentList, function (i1, n1) { QuestionAttachments.Add(n1); QuestionAttachments2.Add(n1); }); } createOptions(); var typeName = $("#TypeName").find("option:selected").text(); if (typeName == "单选题" || typeName == "多选题" || typeName == "判断题") { CreateSelect(); } if (typeName != "单选题" && typeName != "多选题" && typeName != "判断题") { $("#xuanxaing1").hide(); $("#jiexi").hide(); } else { $("#xuanxaing1").show(); $("#jiexi").show(); } //答案 if (mode.AnswerList != null) { $.each(mode.AnswerList, function (i2, n2) { QuestionAnswer.Add(n2); QuestionAnswer2.Add(n2); switch (n2.Answer1) { case 0: $("#A").attr("checked", true); break; case 1: $("#B").attr("checked", true); break; case 2: $("#C").attr("checked", true); break; case 3: $("#D").attr("checked", true); break; default: $("#option").find("li:eq(4)").find("input").attr("checked", true); break; } }); } dialogHelper.Reset('popQuestionBankAdd'); jinyong(); if (data.index==0) { $("#upward").attr('disabled', true); $("#upward").css("background-color", "#808080"); } else { $("#upward").attr('disabled', false); $("#upward").css("background-color", "#00a2e2"); } if (data.maxIndex == $("#CurQuestionCount").html()) { $("#down").attr('disabled', true); $("#down").css("background-color", "#808080"); } else { $("#down").attr('disabled', false); $("#down").css("background-color", "#00a2e2"); } var CurQuestionCount = GetTitleCount(Id); Index = data.index; if ((CurQuestionCount-1)==Index) { $("#down").attr("disabled", true); $("#down").css("background-color", "#808080"); } else { $("#down").attr("disabled", false); $("#down").css("background-color", "#00a2e2"); } SaveDefaultValueCommon("popQuestionBankAdd"); } }); } var type = ""; //查询对应题型 function SelectTitle(strList) { //题型下拉列表 selectHelper.GetSelect({ url: "/Teacher/TheoryQuestion/TiXingSelList", Id: "#TypeName", value: "全部", data: { strList: strList } }); } //保存题目 function AddTitle(TheoryChapterId, typeid, PaperId) { if ($("#preserve").val() == "编辑") { var bo = neizhi($("#QuestionIdAdd1").val()); if (bo) { dialogHelper.Error({ content: "内置题目不能进行编辑!", success: function () { } }); return false; } $("#preserve").val("保存"); //启用文本框 $("#Context").removeClass('disabled').attr("readonly",false); //选项 var Fobj = $("#option").find("li"); $.each(Fobj, function (i, n) { $(n).find("input:eq(0)").attr('disabled', false); $(n).find("input:eq(1)").attr('disabled', false); $(n).find("span").show(); }); $("#btnAdd").attr('disabled', false); //添加选项按 var Fobj = $("#option").find("li"); if (Fobj.length <= 4) { $("#Add1").show(); } else { $("#Add1").hide(); } //附件 var Fobj = $("#Dappendix").find("a"); $.each(Fobj, function (i, n) { $(n).find("b").show(); }); //解析 $("#Analysis").removeClass('disabled').attr("readonly", false);; $("#upward").attr('disabled', true); $("#upward").css("background-color", "#808080"); $("#down").attr('disabled', true); $("#down").css("background-color", "#808080"); } else { if (!VerificationHelper.checkFrom("popQuestionBankAdd")) { return false; } QuestionOption.RemoveAll();//选项 QuestionAnswer.RemoveAll();//答案 QuestionOption2.RemoveAll();//选项 QuestionAnswer2.RemoveAll();//答案 //添加试题 var obg = new Object(); obg["Id"] = $("#QuestionIdAdd1").val();//Id obg["Context"] = $("#Context").val();//题干 obg["LibraryID"] = 1;//所属题库(理论考核/认证考试) var typeName = $("#TypeName").find("option:selected").text(); if (typeName == "单选题") { obg["StructType"] = 1;//题目类型(枚举) } else if (typeName == "多选题") { obg["StructType"] = 2;//题目类型(枚举) } else if (typeName == "判断题") { obg["StructType"] = 3;//题目类型(枚举) } else if (typeName == "填空题") { obg["StructType"] = 4;//题目类型(枚举) } else { obg["StructType"] = 5;//题目类型(枚举) } obg["CharpterID"] = typeid;//认证类型Id/章节Id(对应下面的题型) obg["Analysis"] = $("#Analysis").val();//解析 obg["Status"] = 1;//状态 开启 obg["PaperId"] = PaperId;//状态 开启 //添加选项和答案 var num = 0; var num2 = 0; var Fobj = $("#option").find("li"); $.each(Fobj, function (i, n) { var obj = new Object(); obj["OptionName"] = $(n).find("input:eq(1)").val(); obj["Sort"] = i; QuestionOption.Add(obj); QuestionOption2.Add(obj); num2 = num2 + 1; //选中的为答案 if ($(n).find("label").find("input").attr("checked") == "checked") { var objs = new Object(); objs["Answer1"] = i; objs["Sort"] = i; QuestionAnswer.Add(objs); QuestionAnswer2.Add(objs); num = num + 1; } }); obg["OptionList"] = QuestionOption.GetList();//选项 obg["AnswerList"] = QuestionAnswer.GetList();//答案 obg["AttachmentList"] = QuestionAttachments.GetList();//附件 var number = 0; var lis = QuestionOption.GetList(); $.each(lis, function (i, n) { $.each(lis, function (a, b) { if (i != a) { if (n.OptionName == b.OptionName) { number = number + 1; } } }); }); if (typeName == "单选题" || typeName == "多选题") { if (num2 < 3) { dialogHelper.Error({ content: "请至少输入3个选项!", success: function () { } }); return false; } if (number > 0) { number = 0; dialogHelper.Error({ content: "不能添加相同的选项!", success: function () { } }); return false; } if (num == 0) { dialogHelper.Error({ content: "请选择正确答案!", success: function () { } }); return false; } } if (typeName == "多选题") { if (num < 2) { dialogHelper.Error({ content: "多选题请至少选择两个答案!", success: function () { } }); return false; } } $(QuestionAttachments.GetList()).each(function (i, n) { QuestionAttachments2.Add(n); }); $.ajax({ url: "/Teacher/TheoryQuestion/AddUpdateQuestion2", type: "POST", async: false, dataType: "json", data: JSON.stringify(obg), contentType: "application/json", success: function (data) { dialogHelper.Success({ content: "保存成功!", success: function () { Index = data.index; $("#QuestionIdAdd1").val(data.result); $("#preserve").val("编辑"); //更新题目选择JS缓存 var old_question = AlreadyQuestionsHelper.FindRecord(obg["Id"]); if (old_question != null && old_question != undefined) { AlreadyQuestionsHelper.Remove(obg["Id"]); old_question.QuesionId = data.result; AlreadyQuestionsHelper.Add(old_question); } var PaperId = $("#TestPapersId").val(); var CurQuestionCount = GetTitleCount(PaperId); $("#CurQuestionCount").html(Index + 1) var count = $("#CurQuestionCount").html(); if (count == 1) { $("#upward").attr('disabled', true); $("#upward").css("background-color", "#808080"); $("#down").attr('disabled', false); $("#down").css("background-color", "#00a2e2"); } else if (count == CurQuestionCount) { $("#down").attr('disabled', true); $("#down").css("background-color", "#808080"); $("#upward").attr('disabled', false); $("#upward").css("background-color", "#00a2e2"); } else { $("#upward").attr('disabled', false); $("#upward").css("background-color", "#00a2e2"); $("#down").attr('disabled', false); $("#down").css("background-color", "#00a2e2"); } if (count == 1 && count == CurQuestionCount) { $("#upward").attr('disabled', true); $("#upward").css("background-color", "#808080"); $("#down").attr('disabled', true); $("#down").css("background-color", "#808080"); } $("#AddTitle").attr('disabled', false); $("#AddTitle").css("background-color", "#00a2e2"); //激活按钮 //禁用文本框 $("#Context").addClass('disabled').attr("readonly", true);; //选项 var Fobj = $("#option").find("li"); $.each(Fobj, function (i, n) { $(n).find("input:eq(0)").attr('disabled', true); $(n).find("input:eq(1)").attr('disabled', true); $(n).find("span").hide(); }); $("#btnAdd").attr('disabled', true); //添加选项按 $("#Add1").hide(); //附件 var Fobj = $("#Dappendix").find("a"); $.each(Fobj, function (i, n) { $(n).find("b").hide(); }); //解析 $("#Analysis").addClass('disabled').attr("readonly", true);; if (Index == 0) { $("#upward").attr('disabled', true); $("#upward").css("background-color", "#808080"); } QuestionOption.RemoveAll();//选项 QuestionAnswer.RemoveAll(); //答案 //QuestionAttachments.RemoveAll(); //附件 ShowQuestionsList("", ""); SaveDefaultValueCommon("popQuestionBankAdd"); } }); }, error: function (msg) { $(".background,.progressBar").hide(); } }); } } //删除选项 function DeleteSelect(obj) { $(obj).parent().remove(); var optionName = $(obj).parent().find("input:eq(1)").val(); QuestionOption.Remove(optionName); //$(obj).parent().remove(); var Fobj = $("#option").find("li"); var num = 0; $.each(Fobj, function (i, n) { var valu = Option(i); var typeName = $("#TypeName").find("option:selected").text(); if (typeName == "单选题") { var li = $(n).find("label").html('