<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block 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-badge-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">徽章名称：</label>
            <div class="col-sm-8">
                <input name="name" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">徽章图标：</label>
            <div class="col-sm-8">
                <input name="icon" class="form-control" type="text" placeholder="输入Emoji或图片URL" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">徽章类型：</label>
            <div class="col-sm-8">
                <select name="type" class="form-control m-b" required onchange="typeChange(this.value)">
                    <option value="">请选择</option>
                    <option value="1">护照纪念徽章</option>
                    <option value="2">演出纪念徽章</option>
                    <option value="3">特殊徽章</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">排序：</label>
            <div class="col-sm-8">
                <input name="sort" class="form-control" type="number" min="0" value="0" placeholder="数值越大越靠前">
            </div>
        </div>
        <div class="form-group" id="ticketTimesDiv" style="display: none;">
            <label class="col-sm-3 control-label is-required">关联演出：</label>
            <div class="col-sm-8">
                <input name="performanceId" id="performanceId" class="form-control" type="text" placeholder="请输入演出ID">
                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 演出纪念徽章必填</span>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
    var prefix = ctx + "adam/caomei/badge";

    function typeChange(val) {
        if (val == 2) {
            $("#ticketTimesDiv").show();
            $("#performanceId").prop("required", true);
        } else {
            $("#ticketTimesDiv").hide();
            $("#performanceId").prop("required", false);
            $("#performanceId").val("");
        }
    }

    $("#form-badge-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-badge-add').serialize());
        }
    }
</script>
</body>
</html>