<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-teachSatisfaction-add">
        <!--隐藏班级编号-->
        <input name="classId" type="hidden" id="classId"/>

        <div class="form-group">
            <label class="col-sm-3 control-label">班级编号：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="classNo" onclick="selectList()" readonly="true"
                       id="className">
            </div>
        </div>
        <!--<div class="form-group">	-->
        <!--<label class="col-sm-3 control-label">评级时间：</label>-->
        <!--<div class="col-sm-8">-->
        <!--<input id="createtime" name="createtime" class="form-control" type="text">-->
        <!--</div>-->
        <!--</div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">教师编号：</label>
            <div class="col-sm-8">
                <!--<input id="teacherId" name="teacherId" class="form-control" type="text">-->
                <select name="teacherId" id="teacherId" class="form-control">
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">满意度：</label>
            <div class="col-sm-8">
                <input id="satisfaction" name="satisfaction" class="form-control" type="text">
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    var prefix = ctx + "teach/teachSatisfaction";
    $("#form-teachSatisfaction-add").validate({
        rules: {
            classNo: {
                required: true
            },
            teacherId: {
                required: true
            },
            satisfaction: {
                required: true
            }
        }
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-teachSatisfaction-add').serialize());
        }
    };

    /*选择班级*/
    function selectList() {
        var url = ctx + "teach/teachClasses/selectList";
        var options = {
            title: '选择班级',
            width: "900",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = layer.getChildFrame('body', index);
        var data = body.find('.selected')[0];
        if (data != "undefined" && data != "" && data != null) {
            $("#className").val(body.find('.selected')[0].children[2].innerHTML);
            $("#classId").val(body.find('.selected')[0].children[1].innerHTML);
            //判断是否为空
            if (classId != undefined && classId != null) {
                checkInput();
            }
        } else {
            layer.msg("请选择一个班级");
        }
        layer.close(index);
    };

    //当班级发生改变的时候  清空下拉框  重新赋值
    function checkInput(){
        var classId = $("#classId").val();
        var codeurl = ctx + "teach/teachSatisfaction/classId";
        //清空之后再赋值
        $("#teacherId").children().remove();
        //判断是否为空
        if (classId != undefined && classId != null) {
            $.post(codeurl, {classId: classId}, function (data) {
                $.each(data.rows, function (i, d) {
                    $("select[name='teacherId']").append("<option value='" + d.teacher_id + "'>" + d.teacher_name + "</option>");
                });
            }, 'json');
        }
    }


</script>
</body>
</html>
