123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949 |
- <script src="/js/jquery.datetimepicker.js"></script>
- <link rel="stylesheet" href="/fonts/fpdf/iconfont.css" />
- <link rel="stylesheet" href="/css/modelCreatePaper.css" />
- <link rel="stylesheet" href="/css/jquery.datetimepicker.css" />
- <style>
- #choose-error{color: #FF0000;}
- #examName-error{color: #FF0000;}
- #classIds-error{color: #FF0000;}
- #type-error{color: #FF0000;}
- #markType-error{color: #FF0000;}
- #subject-error{color: #FF0000;}
- #examDate{color: #FF0000;}
- .icon-add,.icon-del{
- width:20px;height:25px;display: inline-block;
- margin-bottom:-5px;
- }
- .icon-add{
- background:url("/images/timg.jpg") left center no-repeat ;
- background-size:18px 18px;
- margin-left:20px;
- }
- .icon-del{background: url("/images/u434.png") left center no-repeat;
- background-size:18px 18px;
- position: relative;
- top: 2px;
- }
- .tag {
- display: inline-block;
- padding: 3px 8px;
- border-radius: 3px;
- color: #ffffff;
- font-size: 12px;
- cursor: pointer;
- }
- .bg-green {
- background: #2977ff;
- }
- .topic_type_select{margin-bottom: 5px;}
- .topic_type_select input{height:26px;}
- .topic_type_select select{height:26px;}
- .border-box{
- border:1px solid #ccc;
- display: inline-block;
- margin-right:20px;
- height:34px;
- }
- .score{color:#333;margin-right:20px;}
- .up_score{color:#2977ff;}
- .confirmbox {
- background: #fff;
- border: 1px solid #cccccc;
- border-radius: 3px;
- padding: 40px 40px 30px;
- text-align: center;
- position: fixed;
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
- z-index: 99;
- }
- .confirmbox-mask {
- background: rgba(0, 0, 0, .7);
- left: 0;
- right: 0;
- top: 0;
- bottom: 0;
- z-index: 99;
- position: fixed;
- }
- button {
- border: none;
- background: #2977ff;
- width: 80px;
- height: 26px;
- border-radius: 3px;
- font-size: 14px;
- color: #fff;
- outline: none;
- cursor: pointer;
- }
- button.save {
- display: block;
- margin: 40px auto;
- }
- .confirmbox .confirmbox-btns {
- margin-top: 40px;
- }
- .class-modal {
- width: 500px;
- min-height: 400px;
- background: #fff;
- // border-radius: 5px;
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- }
- .class-modal-head {
- font-size: 14px;
- background:#2977ff;
- color:#fff;
- height:25px;
- line-height: 25px;
- padding: 0 0 0 15px;
- }
- .class-modal-body {
- margin-top: 20px;
- max-height: 300px;
- overflow: auto;
- margin-left:50px;
- }
- .class-modal-body .classes {
- margin-bottom: 20px;
- }
- .class-modal-body .classes > div {
- display: inline-block;
- max-width: 640px;
- vertical-align: top;
- }
- .class-modal-body .classes a {
- text-decoration: none;
- display: inline-block;
- margin: 0 5px 5px;
- color: #136bfb;
- font-size: 14px;
- }
- .class-modal-body .classes a.active {
- color: #fc091b
- }
- .class-modal .icon-close{
- position: absolute;
- right: 20px;
- top: 2px;
- color:#fff;
- }
- .c-red {
- color: #CC3300
- }
- .avg{
- margin:0 10px;
- }
- .class_btn{
- text-align: center;
- }
- .confirmbox-mask p{
- word-wrap : break-word ;
- }
- .template-flag-box{padding-left:150px;}
- .template-flag-box a{display:inline-block;color:#fff;text-decoration:none;border-radius:3px;width: 100px;text-align: center;background: #2977ff;height: 30px;margin-right:20px;line-height:30px}
- .class-modal-body p span{display: inline-block;width:60px;}
- .class_btn{position: fixed;bottom: 2%;text-align: center;width:500px;}
- .topic_type,.topic_count{
- vertical-align:middle;
- }
- </style>
- <div class="main-content-inner">
- <!-- 导航栏开始-->
- <?php include(Yii::app()->basePath.'/views/layouts/view_navigation.php');?>
- <!-- 导航栏结束-->
- <div class="page-content">
- <div class="mcp-title">模板组卷</div>
- <form class="saveForm" action="<?php echo Yii::app()->createUrl('third/createthirdunderline')?>" method="post" enctype="multipart/form-data">
- <div class="mcp-main-con">
- <div class="mcp-form-list clearfix">
- <div class="mcp-form-menu fl">试卷名称</div>
- <div class="mcp-form-detail fl"><input type="text" placeholder="必填" class="test-paper-name" name="examName"></div>
- <div id="examName-error"></div>
- </div>
- <div class="mcp-form-list clearfix">
- <div class="mcp-form-menu fl">试卷格式</div>
- <div class="mcp-form-detail topic_area fl">
- <div class="topic_type_select">
- <div class="border-box">
- <select class="topic_type" source="0">
- <option value="0">请选择题型</option>
- <?php
- if(isset(Yii::app()->params['third_paper_logic'][Yii::app()->session['session_duoxueke_subject_id']])){
- foreach (Yii::app()->params['third_paper_logic'][Yii::app()->session['session_duoxueke_subject_id']] as $logic=>$type){
- echo '<option value="'.$logic.'" >'.$type.'</option>';
- }
- }else{
- foreach (Yii::app()->params['third_paper_logic'][3] as $logic=>$type){
- echo '<option value="'.$logic.'" >'.$type.'</option>';
- }
- }
- ?>
- </select>
- <input type="text" class="core topic_count" name="topic_count" value="0">小题
- <span class="icon-add"></span>
- <span class="icon-del"></span>
- </div>
- <span class="score">共--分</span>
- <span class="up_score">修改分值</span>
- <input type="hidden" class="score_list" name="score_list" value="">
- <input type="hidden" class="score_sum" name="score_sum" value="0">
- </div>
- <span class="tag bg-green add_topic_type">新增题型</span>
- <span class="tag bg-green preview">试卷预览</span>
- <span id="topic_error" class="c-red"></span>
- </div>
- </div>
- <div class="mcp-form-list clearfix">
- <div class="mcp-form-menu fl">选择考试类型</div>
- <div class="mcp-form-detail fl clearfix">
- <div class="mcp-radio-sel fl">
- <span class="sel-btn examType" value="1"></span>
- <span class="examType" value="1">周考</span>
- </div>
- <div class="mcp-radio-sel fl">
- <span class="sel-btn examType" value="2"></span>
- <span class="examType" value="2">单元考</span>
- </div>
- <div class="mcp-radio-sel fl">
- <span class="sel-btn examType" value="3"></span>
- <span class="examType" value="3">月考</span>
- </div>
- <div class="mcp-radio-sel fl">
- <span class="sel-btn examType" value="4"></span>
- <span class="examType" value="4">联考</span>
- </div>
- <div class="mcp-radio-sel fl">
- <span class="sel-btn examType" value="5"></span>
- <span class="examType" value="5">期中考试</span>
- </div>
- <div class="mcp-radio-sel fl">
- <span class="sel-btn examType" value="6"></span>
- <span class="examType" value="6">期末考试</span>
- </div>
- <div class="mcp-radio-sel fl">
- <span class="sel-btn examType" value="7"></span>
- <span class="examType" value="7">模拟考</span>
- </div>
- <div class="mcp-radio-sel fl">
- <span class="sel-btn examType" value="8"></span>
- <span class="examType" value="8">冲刺考</span>
- </div>
- </div>
- <div id="type-error"></div>
- </div>
- <div class="mcp-form-list clearfix">
- <div class="mcp-form-menu fl">主考教师</div>
- <div class="mcp-form-detail fl">
- <div class="inp-text pointer">选择主考教师</div>
- <ul class="select-con tac">
- <!--<li class="sel-option pointer" id="1">高三一班</li>-->
- <?php foreach($teacher_arr as $t):?>
- <li class="sel-option pointer" id="<?php echo $t['teacher_id']?>"><?php echo $t['teacher_name']?></li>
- <?php endforeach;?>
- <!--<li class="sel-option pointer" id="2">高三二班</li>-->
- <!--<li class="sel-option pointer" id="3">高三三班</li>-->
- </ul>
- </div>
- <div id="choose-error"></div>
- </div>
- <div class="mcp-form-list clearfix">
- <div class="mcp-form-menu fl">考试班级</div>
- <div class="mcp-form-detail fl">
- <div class="test-classes-desc">默认已选我执教的班级(<span class="">单击移除</span>)<span id="classIds-error"></span></div>
- <?php
- if(isset(Yii::app()->params['grade_config'])){
- $first=true;
- foreach (Yii::app()->params['grade_config'] as $id =>$item){
- if($first){
- $first=false;
- echo '<div class="sel-classes g'.$id.'" status="1"></div>';
- }else{
- echo '<div class="sel-classes g'.$id.'" style="display: none;" status="0"></div>';
- }
- }
- }
- ?>
- <div class="clearfix">
- <div class="grade-sel fl">
- <div class="grade-top">年级</div>
- <ul>
- <?php
- if(isset(Yii::app()->params['grade_config'])){
- foreach (Yii::app()->params['grade_config'] as $id =>$item){
- echo '<li grade="'.$id.'">'.$item['grade_name'].'</li>';
- }
- }
- ?>
- </ul>
- </div>
- <?php
- if(isset(Yii::app()->params['grade_config'])){
- $first=true;
- foreach (Yii::app()->params['grade_config'] as $id =>$item){
- if($first){
- $first=false;
- echo '<div class="bj-sel fl" id="grade'.$id.'">';
- echo '<div class="class-top">班级</div>';
- echo '<ul></ul>';
- echo '</div>';
- }else{
- echo '<div class="bj-sel fl" id="grade'.$id.'" style="display: none;">';
- echo '<div class="class-top">班级</div>';
- echo '<ul></ul>';
- echo '</div>';
- }
- }
- }
- ?>
- </div>
- </div>
- </div>
- <div class="mcp-form-list clearfix">
- <div class="mcp-form-menu fl">考试时间</div>
- <div class="mcp-form-detail fl clearfix">
- <input type="text" readonly class='core datetimepicker8' style="width: 100px;" name="examDate" />
- </div>
- <div id="examDate"></div>
- </div>
- </div>
- <input name="type" value="" type="hidden"/>
- <input name="teacherId" value="0" type="hidden"/>
- <input name="markType" value="3" type="hidden"/>
- <input name="classIds" value="0" type="hidden"/>
- <input name="topic_data" value="" type="hidden">
- <input name="subjectId" value="<?php echo Yii::app()->session['session_duoxueke_subject_id']?>" type="hidden">
- </form>
- <div class="mcp-form-list mcp-fl-btns clearfix">
- <input type="button" value="确定" class="mcp-sure-btn" id="createThird" active="true">
- <input type="button" value="返回" class="mcp-back-btn">
- </div>
- </div>
- <div class="confirmbox-mask" style="display: none" id="classModal">
- <div class="class-modal">
- <i class="icon icon-close">关闭</i>
- <div class="class-modal-head">修改分值</div>
- <div class="class-modal-body">
- <p><span>总分:</span> <input type="text" name="total_score" /><button class="avg">平均分配</button><span>无法平均分配</span></p>
- </div>
- <p class="class_btn">
- <input type="hidden" name="topic_type_index" value="0">
- <button type="button" class="save_score">确定</button>
- </p>
- </div>
- </div>
- <div class="confirmbox-mask" style="display: none" id="examModal">
- <div class="class-modal">
- <i class="icon icon-close">关闭</i>
- <div class="class-modal-head">试卷预览</div>
- <div class="class-modal-body">
- </div>
- <p class="class_btn">
- <button type="button" class="exam-close">确定</button>
- </p>
- </div>
- </div>
- </div>
- <script>
- $(document).ready(function(){
- $('.datetimepicker8').datetimepicker({
- onGenerate:function( ct ){
- $(this).find('.xdsoft_date').toggleClass('xdsoft_disabled');
- $(this).find('.xdsoft_today').removeClass('xdsoft_disabled');
- },
- format:'Y-m-d',
- formatDate:'Y-m-d',
- minDate:'-1970/01/2',
- maxDate:'+1970/01/2',
- //minDate: '-<?php echo date('Y-m-d', strtotime('Yesterday')); ?>',
- timepicker:false
- });
- //选择考试时间
- //选择教材题源
- var subjects = <?php echo json_encode($teacherSubjectNames); ?>;
- var textbooks = <?php echo json_encode($teacherSubjectMaterialNames); ?>;
- for(var key in subjects){
- $(".choose-grade").append('<option value="'+ key +'">'+ subjects[key] +'</option>');
- }
- $(".choose-grade").change(function(){
- var obj = $(this);
- var val = obj.val();
- var child = $('.choose-book');
- child.html('<option value="0">选择教材</option>');
- for (var key in textbooks) {
- if (key == val) {
- child.html('');
- for (var name in textbooks[key]) {
- child.append('<option value="'+ [name] +'">'+ textbooks[key][name] +'</option>');
- }
- }
- }
- });
- //返回
- $('.mcp-back-btn').click(function(){
- location.href="<?php echo Yii::app()->createUrl('third/index?list_type=1')?>";
- });
- $('input[name="examName"]').keydown(function(event){
- $('#examName-error').html("");
- });
- //阅卷方式
- $('.markType').click(function(){
- var markType = $(this).attr('value');
- if(markType){
- $('#markType-error').html("");
- }
- $('input[name="markType"]').val(markType);
- });
- //选择教师
- $('.sel-option').click(function(){
- var teacher_id = $(this).attr('id');
- if(teacher_id){
- $('#choose-error').html("");
- }
- $('input[name="teacherId"]').val(teacher_id);
- $.post(
- "<?php echo Yii::app()->createUrl('third/ajaxchangeclasses')?>",
- {teacher_id:teacher_id},
- function(result){
- if(result.error){
- $('#choose-error').html(result.error);
- }else{
- $.each(result.class_arr_select,function(k,v){
- $('.g'+v.grade).html($('.g'+v.grade).html()+"<span grade='"+v.grade+"' classid='"+v.class_id+"'>"+v.class_name+"</span>");
- });
- $.each(result.class_arr_noselect,function(k,v){
- $('#grade'+v.grade+' ul').html($('#grade'+v.grade+' ul').html()+'<li class="bjs-lis ellipsis" grade="'+v.grade+'" classid="'+v.class_id+'" ><span class="judge-sel"></span>'+v.class_name+'</li>');
- });
- }
- },
- 'json'
- );
- });
- var gradeArr=[];
- <?php
- if(Yii::app()->params['grade_list']){
- foreach (Yii::app()->params['grade_list'] as $param){
- echo "gradeArr.push('".$param['id']."');";
- }
- }
- ?>
- //切换年级
- $('.a-years,.a-province,.paper-type > span, .grade-sel ul li').click(function(){
- if(!$(this).hasClass('active')){
- $(this).addClass('active').siblings().removeClass('active');
- var grade=$(this).attr("grade");
- for(var i=0;i<=gradeArr.length;i++){
- if(gradeArr[i]==grade){
- $("#grade"+grade).show();
- $('.g'+grade).show();
- $('.g'+grade).attr('status',1);
- }else{
- $("#grade"+gradeArr[i]).hide();
- $(".g"+gradeArr[i]).hide();
- $(".g"+gradeArr[i]).attr('status',0);
- }
- }
- }
- });
- //添加班级
- $(".bj-sel ul").on("click","li", function(){
- $('#classIds-error').html("");
- $(this).find('.judge-sel').addClass('active');
- $(this).remove();
- var grade = $(this).attr('grade');
- $('.g'+grade).append('<span grade="'+$(this).attr("grade")+'" classid="'+$(this).attr("classid")+'">'+$(this).text()+'</span>');
- });
- //移除班级
- $('.sel-classes').delegate('span','click',function(){
- $(this).remove();
- $("#grade"+$(this).attr("grade")).children("ul").append('<li class="bjs-lis" grade="'+$(this).attr("grade")+'" classid="'+$(this).attr("classid")+'"><span class="judge-sel"></span>'+$(this).html()+'</li>');
- });
- if ($('.sel-classes > span').length > 0){
- for (var i = 0;i < $('.sel-classes > span').length; i++){
- for (var k = 0;k < $('.bjs-lis').length; k++){
- if ($('.bjs-lis').eq(k).text().trim()==$('.sel-classes > span').eq(i).text().trim()) {
- $('.bjs-lis').eq(k).find('.judge-sel').addClass('active');
- }
- }
- }
- }
- $('.mcp-radio-sel').click(function(){
- if (!$(this).find('.sel-btn').hasClass('select')) {
- $(this).find('.sel-btn').addClass('select');
- $(this).siblings().find('.sel-btn').removeClass('select');
- var type = $(this).find('.sel-btn').attr('value');
- if(type){
- $('#type-error').html("");
- }
- $('input[name="type"]').val(type);
- }
- });
- $('.grade-sel ul li').click(function(){
- $(this).addClass('active').siblings().removeClass('active');
- });
- // $('.judge-sel').on('click',function(){
- // alert(1);
- // if (!$(this).hasClass('active')) {
- // $(this).addClass('active');
- // $('.sel-classes').append('<span>'+$(this).closest('.bjs-lis').text()+'</span>');
- // } else {
- // $(this).removeClass('active');
- // for (var i = 0;i < $('.sel-classes > span').length; i++) {
- // console.log($('.sel-classes > span').eq(i).text());
- // if ($('.sel-classes > span').eq(i).text().trim() == $(this).closest('.bjs-lis').text().trim()){
- // $('.sel-classes > span').eq(i).remove();
- // }
- // }
- // }
- // });
- $('.sel-classes > span').click(function(){
- $(this).remove();
- for (var i = 0;i < $('.bjs-lis').length; i++) {
- if ($('.bjs-lis').eq(i).text().trim()==$(this).text().trim()){
- $('.bjs-lis').eq(i).find('.judge-sel').removeClass('active');
- }
- }
- });
- // 下拉列表模拟
- $('.inp-text').click(function(){
- if ($(this).next().is(':hidden')){
- $(this).next().show();
- } else {
- $(this).next().hide();
- }
- });
- // 点下拉列表选项
- $('.select-con li').click(function(){
- $(this).closest('.select-con').hide();
- $(this).closest('.mcp-form-detail').find('.inp-text').text($(this).text());
- });
- // 点击空白处下拉列表消失
- $(document).click(function(e){
- var targetNode = $(e.target).closest(".inp-text");
- if (targetNode.length>0){
- return;
- }else{
- $(".select-con").hide();
- }
- });
- $("body").delegate("#createThird[active='true']", "click", function(e) {
- var classIds='';
- $(".sel-classes[status=1]").children("span").each(function(){
- classIds += $(this).attr('classid')+",";
- });
- $('input[name="classIds"]').val(classIds);
- var error = new Array();
- var classIds = $('input[name="classIds"]').val();
- var examName = $('input[name="examName"]').val();
- var type = $('input[name="type"]').val();
- var teacherId = $('input[name="teacherId"]').val();
- var examDate = $("input[name='examDate']").val();
- if(examName == "" || examName == null){
- $('#examName-error').html('请指定考试名称');
- error.push('没有指定考试名称');
- }else{
- $('#examName-error').html('');
- }
- //检测试题设置
- $select_obj=$('.topic_type_select');
- $isFoundErr=false;
- $topicData=[];
- for (var i=0;i<$select_obj.length;i++){
- if($select_obj.eq(i).find('.topic_count').val()==0 || $select_obj.eq(i).find('.score_list').val()=='' || $select_obj.eq(i).find('topic_type').val()=='0'){
- $isFoundErr=true;
- break;
- }else{
- $topicData.push('{"topic_type":'+$select_obj.eq(i).find('.topic_type').val()+',"topic_count":'+$select_obj.eq(i).find('.topic_count').val()+','+'"topic_score":"'+$select_obj.eq(i).find('.score_list').val()+'"}');
- }
- }
- if($isFoundErr){
- error.push('试题类型数量或分数未设置');
- $('#topic_error').html('试题数量或分数未设置');
- }else{
- $('input[name=topic_data]').val('['+$topicData.join(',')+']');
- $('#topic_error').html('');
- }
- if(type == "" || type == null){
- $('#type-error').html('请指定考试类型');
- error.push('没有指定考试类型');
- }else{
- $('#type-error').html('');
- }
- if(teacherId == '0' || teacherId == null){
- $('#choose-error').html('请指定阅卷老师');
- error.push('没有指定阅卷老师');
- }else{
- $('#choose-error').html('');
- if(classIds == "" || classIds == null){
- $('#classIds-error').html('请指定考试班级');
- error.push('没有指定考试班级');
- }else{
- $('#classIds-error').html('');
- }
- }
- if (examDate == '') {
- $('#examDate').html('请设置考试日期');
- error.push('请设置考试日期');
- } else if (examDate < '<?php echo date('Y-m-d'); ?>') {
- //$('#examDate').html('考试日期设置错误');
- //error.push('考试日期设置错误');
- }else{
- $('#examDate').html('');
- }
- if(error.length == 0){
- $(this).attr("active","false");
- //$(".saveForm").submit();
- //改为ajax提交
- index=layer.msg('正在保存,请稍候......',{time:9000000});
- $.ajax({
- url:'<?php echo Yii::app()->createUrl('third/createthirdunderline')?>',
- method:'POST',
- dataType:'json',
- data:$(".saveForm").serialize(),
- success:function (res) {
- layer.close(index);
- if(res.status==1){
- window.location="<?php echo Yii::app()->createUrl('third/index?list_type=1')?>";
- }else{
- layer.msg(res.msg);
- }
- }
- });
- }
- });
- //================题型选择部分操作代码=================================
- var selected_type=[]; //已选题型
- $('.topic_type_select').eq(0).find('.topic_type').val(1);
- $('.topic_type_select').eq(0).find('.topic_type').attr('source',1);
- selected_type.push('1');
- function create_topic_type_select_obj(){
- $obj=$('.topic_type_select').eq(0).clone();
- $obj.find('.topic_count').val(0);
- $obj.find('.score_list').val('');
- $obj.find('.score_sum').val(0);
- $obj.find('.score').html('共-分');
- var option=$obj.find('.topic_type option');
- var is_have_topic_type=false;
- for(var i=0;i<option.length;i++){
- if(option.eq(i).attr('value')==0 || $.inArray(option.eq(i).attr('value'),selected_type)!=-1){
- continue;
- }else{
- $obj.find('.topic_type').val(option.eq(i).attr('value'));
- selected_type.push(option.eq(i).attr('value'));
- $obj.find('.topic_type').attr('source',option.eq(i).attr('value'));
- is_have_topic_type=true;
- break;
- }
- }
- if(is_have_topic_type){
- return $obj;
- }else{
- return false;
- }
- }
- $('.add_topic_type').click(function () {
- $obj=create_topic_type_select_obj();
- console.log(selected_type);
- if(!$obj){
- layer.msg('没有可用题型!');
- }else{
- $(this).before($obj);
- }
- });
- $('.icon-close,.exam-close').click(function(){
- $(this).closest('.confirmbox-mask').hide();
- });
- $('.save_score').click(function(){
- var topicScore=[];
- for(var i=1;i<=$('.topic_score').length;i++){
- if($('input[name=total_score_'+i+']').val()==0 || $('input[name=total_score_'+i+']').val()==''){
- layer.msg('请填写题目分数!');
- return false;
- }
- topicScore.push($('input[name=total_score_'+i+']').val());
- }
- var obj_index=$('input[name=topic_type_index]').val();
- $('.topic_type_select').eq(obj_index).find('.score_list').val(topicScore.join(','));
- $('.topic_type_select').eq(obj_index).find('.score').html('共'+$('input[name=total_score]').val()+'分');
- $('.topic_type_select').eq(obj_index).find('.score_sum').val($('input[name=total_score]').val());
- classModal.style.display = 'none';
- });
- //试卷预览
- $('.preview').click(function(){
- $obj=$('.topic_type_select');
- for(var i=0;i<$obj.length;i++){
- if($obj.eq(i).find('.topic_count').val()==0 ){
- layer.msg('试题数量或分数未设置!');
- return false;
- }
- }
- $('#examModal').show();
- var html='';
- var digit=['一','二','三','四','五','六','七','八','九','十','十一','十二','十三','十四','十五','十六','十七','十八','十九','二十','二十一'];
- var topic_num=1;
- for(var i=0;i<$obj.length;i++){
- topic_count=parseInt($obj.eq(i).find('.topic_count').val());
- score_sum=$obj.eq(i).find('.score_sum').val();
- html+='<p>'+ digit[i]+'、'+$obj.eq(i).find('.topic_type').find("option:selected").text()+'(共'+topic_count+'题,'+score_sum+'分)</p>';
- html+='<p>';
- while (topic_count>0){
- html+=topic_num+',';
- topic_num++;
- topic_count--;
- }
- html+='</p>';
- }
- $('#examModal').find('.class-modal-body').html(html);
- });
- $('input[name=examName]').change(function () {
- if($(this).val().length>30){
- layer.msg('考试名称不能超过30字');
- $(this).val('');
- }
- });
- $('.class-modal-body')
- .on('click','.avg',function(){
- var total_score=$('input[name=total_score]').val();
- var topic_count=$('.topic_score').length;
- if(total_score==0 || total_score==''){
- layer.msg('请填写题目总分!');
- }else{
- var avg_score=total_score/topic_count;
- if(checkFloat(avg_score)==false){
- $('.avg_result').html('无法平均分配');
- $('.avg_result').addClass('red');
- }else{
- $('.avg_result').html('');
- for(var i=1;i<=topic_count;i++){
- $('.topic_score').val(avg_score);
- }
- }
- }
- })
- .on('change','.total_score',function(){
- $(this).val($(this).val().replace(/[^\d+|\.]/g,""));
- if(checkFloat($(this).val())==false){
- layer.msg('分数设置不正确!');
- $(this).val(0);
- }
- if( $(this).val()!=''){
- $(this).val(parseFloat($(this).val()));
- }
- $('.topic_score').val(0);
- $('#topic_error').html('');
- })
- .on('change','.topic_score',function(){
- $(this).val($(this).val().replace(/[^\d+|\.]/g,""));
- if(checkFloat($(this).val())==false){
- layer.msg('分数设置不正确!');
- $(this).val(0);
- }
- if( $(this).val()!=''){
- $(this).val(parseFloat($(this).val()));
- }
- var sum=0;
- for(var i=0;i<$('.topic_score').length;i++){
- if($('.topic_score').eq(i).val()!=''){
- sum+=parseFloat($('.topic_score').eq(i).val());
- }
- }
- $('.total_score').val(sum);
- $('#topic_error').html('');
- });
- $('.topic_area')
- .on('click','.icon-add',function(){
- $obj=create_topic_type_select_obj();
- if(!$obj){
- layer.msg('没有可用题型!');
- }else{
- $(this).closest('.topic_type_select').before($obj);
- }
- })
- .on('mouseover','.icon-del',function(){
- $(this).css('background','url(/images/u436.png) left center no-repeat');
- $(this).css('background-size','18px 18px');
- })
- .on('mouseout','.icon-del',function(){
- $(this).css('background','url(/images/u434.png) left center no-repeat');
- $(this).css('background-size','18px 18px');
- })
- .on('click','.icon-del',function(){
- $obj=$(this).closest('.topic_type_select');
- if($('.topic_type_select').length>1){
- layer.msg('您确定要删除该题型吗?', {
- time: 0,
- btn: ['确定', '取消'],
- yes: function(index){
- layer.close(index);
- selected_type.splice(selected_type.indexOf($obj.find('.topic_type').val()),1);
- $obj.remove();
- }
- });
- }
- })
- .on('change','input[name=topic_count]',function(){
- $(this).val($(this).val().replace(/[^\d+]/g,""));
- if( $(this).val()!=''){
- $(this).val(parseInt($(this).val()));
- }
- if($(this).val()>100){
- $(this).val(0);
- }
- $(this).closest('.topic_type_select').find('.score_list').val(''); //修改试题数量,分值清空
- $(this).closest('.topic_type_select').find('.score').html('共-分');
- $('#topic_error').html('');
- })
- .on('click','.up_score',function(){
- $obj=$(this).closest('.topic_type_select');
- $topic_num=parseInt($obj.find('.topic_count').val());
- var start_topic_num=0;
- for(var i=0;i<$obj.index();i++){
- topic_count_befor=parseInt($('.topic_type_select').eq(i).find('.topic_count').val());
- start_topic_num+=topic_count_befor;
- }
- $('input[name=topic_type_index]').val($obj.index());
- var ScoreArr=[];
- var score_list=$obj.find('.score_list').val();
- var total_score=$obj.find('.score_sum').val();
- if(score_list!=''){
- ScoreArr=score_list.split(',');
- }
- if($topic_num==0 || $topic_num==''){
- layer.msg('请填写题目数量!');
- }else{
- classModal.style.display = 'block';
- $('#classModal').find('.class-modal-body').html('');
- $('#classModal').find('.class-modal-body').html('');
- if(ScoreArr.length>0){
- var html='<p><span>总分:</span><input type="text" class="total_score" name="total_score" value="'+total_score+'" /><button class="avg">平均分配</button><span class="avg_result"></span></p>';
- for(var i=0;i<$topic_num;i++){
- html+='<p><span>第'+(start_topic_num+i+1)+'题:</span><input type="text" class="topic_score" name="total_score_'+(i+1)+'" value="'+ScoreArr[i]+'" /></p>';
- }
- }else{
- var html='<p><span>总分:</span><input type="text" class="total_score" name="total_score" /><button class="avg">平均分配</button><span class="avg_result"></span></p>';
- for(var i=0;i<$topic_num;i++){
- html+='<p><span>第'+(start_topic_num+i+1)+'题:</span><input type="text" value="0" class="topic_score" name="total_score_'+(i+1)+'" /></p>';
- }
- }
- $('#classModal').find('.class-modal-body').html(html);
- }
- })
- .on('change','.topic_type',function () {
- var source=$(this).attr('source');
- var select_topic_type=$(this).val();
- var this_index=$('.topic_type').index(this);
- var new_selected_type=[];
- for(var i=0;i<$('.topic_type').length;i++){
- new_selected_type.push($('.topic_type').eq(i).val());
- if(i==this_index){
- continue;
- }
- if(select_topic_type==$('.topic_type').eq(i).val()){
- layer.msg('该题型已存在,请重新选择!');
- $(this).val(source);
- return false;
- }
- }
- selected_type=new_selected_type;
- $(this).attr('source',select_topic_type);
- console.log(selected_type);
- });
- function checkFloat(num){
- num=String(num);
- arr=num.split(".");
- //console.log(arr[1]);
- if(arr[1]==undefined){
- return true;
- }else if(arr[1]==5){
- return true;
- }
- return false;
- }
- });
- </script>
|