<!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-edit" th:object="${badge}">
        <input name="badgeId" th:field="*{badgeId}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">徽章名称：</label>
            <div class="col-sm-8">
                <input name="name" th:field="*{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" th:field="*{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" th:field="*{type}" 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" th:field="*{sort}" class="form-control" type="number" min="0" placeholder="数值越大越靠前">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">分享文案：</label>
            <div class="col-sm-8">
                <textarea name="shareText" th:field="*{shareText}" class="form-control" rows="3" maxlength="255" placeholder="请输入徽章分享文案"></textarea>
            </div>
        </div>
        <div class="form-group" id="ticketTimesDiv" th:style="${badge.type == 2 ? 'display:block;' : 'display:none;'}">
            <label class="col-sm-3 control-label is-required">关联演出：</label>
            <div class="col-sm-8">
                <input name="performanceId" id="performanceId" th:field="*{performanceId}" class="form-control" type="text" placeholder="请输入演出ID" th:required="${badge.type == 2}">
                <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-edit").validate({
        focusCleanup: true
    });

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