$(document).ready(function(){ 
  var form = layui.form;
});

//增加规则
function optionAdded(){
  var data = $("#add_rule_example").html();
  $("#addordelbuttonbox").before(data);
}

//删除规则
function optionDelete(){
  if($("#addordelbuttonbox").prev().length>0){
    $("#addordelbuttonbox").prev().remove();
  }else{
    layer.msg("已经没有规则了", {icon:2});
  }
}

//提交表单
$("#finished_button").on("click", function(){
  var rulenum = $("#detail_form").find("input[name='score_lower[]']").length;
  if(rulenum==0){
    layer.msg("请先添加规则", {icon:2});
    return false;
  }
  var iserror_1 = 0;
  $("#detail_form").find("input[name='score_lower[]']").each(function(index, el) {
    if($(this).val()=="" || isNaN($(this).val())){
      iserror_1 = 1;
    }
  });
  $("#detail_form").find("input[name='score_upper[]']").each(function(index, el) {
    if($(this).val()=="" || isNaN($(this).val())){
      iserror_1 = 1;
    }
  });
  if(iserror_1==1){
    layer.msg("得分区间请填写数字", {icon:2});
    return false;
  }
  var iserror_2 = 0;
  $("#detail_form").find("input[name='remark[]']").each(function(index, el) {
    if($(this).val()==""){
      iserror_2 = 1;
    }
  });
  if(iserror_2==1){
    layer.msg("请填写评语", {icon:2});
    return false;
  }
  $("#detail_form").ajaxSubmit({
    url: '/glexam/onekeyrule/basicok', 
    type: 'POST',
    dataType: "json", 
    success: function(data){
      if(data.code=="success"){
        layer.msg("成功", {icon:1});
      }else{
        layer.msg(data.msg, {icon:2});
      }
    },
    error: function(){
      layer.msg("系统错误，请联系管理员", {icon:2});
    }
  });
  return false;
});