var firstchoose = 1;

//弹出层索引
var index11, index12;

//弹出课程列表
function showCourseList(){
  layer.load(0, {shade: [0.2, '#393D49']});
  index11 = layer.open({
    id: 'onedialog',
    type: 2,
    title: '选择课程',
    area: ['900px', '570px'],
    fixed: false, //不固定
    content: '/glketang/mycourse/index'
  });
  layer.closeAll('loading');
}

//关闭课程列表
function closeCourseList(){
  layer.close(index11);
}

//临时课
function tempCoursename(){
  $("#detail_form").find("input[name='courseid']").val("-1");
  $("#coursenamebox").html('<span class="layui-badge layui-bg-blue" style="height:36px;line-height:36px;">临时课</span>');
}

//弹出班级列表
function showXzclassList(){
  layer.load(0, {shade: [0.2, '#393D49']});
  index12 = layer.open({
    id: 'onedialog',
    type: 2,
    title: '选择班级',
    area: ['900px', '570px'],
    fixed: false, //不固定
    content: '/glketang/xzclass/index'
  });
  layer.closeAll('loading');
}

//关闭班级列表
function closeXzclassList(){
  layer.close(index12);
}

//临时班
function tempClassname(){
  $("#detail_form").find("input[name='forclass']").val(",-1,");
  $("#forclassnamebox").html('<span class="layui-badge layui-bg-blue" style="height:36px;line-height:36px;">临时班</span>');
}

//清空所选班级
function clearForclassnames(){
  $("#forclassnamebox").empty();
  $("#detail_form").find("input[name='forclass']").val("");
}

//提交表单
$("#finished_button").on("click", function(){
  var title = $("#detail_form").find("input[name='title']");
  var courseid = $("#detail_form").find("input[name='courseid']");
  var forclass = $("#detail_form").find("input[name='forclass']");
  if($(title).val()==""){
    layer.tips('请填写课堂标题', $(title), {tips: [1, '#FF5722']});
    return false;
  }
  if($(courseid).val()=="" || $(courseid).val()=="0"){
    layer.msg("请选择所属课程", {icon:2});
    return false;
  }
  if($(forclass).val()=="" || $(forclass).val()=="0"){
    layer.msg("请选择适用班级", {icon:2});
    return false;
  }
  $("#detail_form").ajaxSubmit({
    url: '/glketang/detail/basicok', 
    type: 'POST',
    dataType: "json", 
    success: function(data){
      if(data.code=="success"){
        layer.msg("成功", {icon:1});
        setTimeout(function(){window.location.href = "/glketang/default/index";}, 2000);
      }else{
        layer.msg(data.msg, {icon:2});
      }
    },
    error: function(){
      layer.msg("系统错误，请联系管理员", {icon:2});
    }
  });
  return false;
});