<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('发放代金券')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-coupon">
        <!-- 隐藏字段，用于传递代金券ID -->
        <input name="voucherId" th:value="${voucher.id}" type="hidden">

        <!-- 代金券信息 -->
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">代金券名称：</label>
                <div class="col-sm-8">
                    <input name="displayCardNumber" th:value="${voucher.voucherName}" class="form-control" type="text"
                           disabled>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">代金券金额：</label>
                <div class="col-sm-8">
                    <input name="displayCardNumber" th:value="${voucher.voucherPrice}" class="form-control" type="text"
                           disabled>
                </div>
            </div>
        </div>
        <!-- 有效期 -->
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">有效期：</label>
                <div class="col-sm-8">
                    <input name="validityTime" type="text" class="form-control" id="datetimepicker-demo-2"
                           placeholder="yyyy-MM-dd" required>
                </div>
            </div>
        </div>
        <!-- 用户列表 -->
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">发放用户：</label>
                <div class="col-sm-8">
                    <select name="memberId" class="form-control">
                        <option value="">请选择用户</option>
                        <option th:each="member : ${members}" th:value="${member.id}" th:text="${member.username}" required></option>
                    </select>
                </div>
            </div>
        </div>
        <!-- 隐藏提交按钮 -->
<!--        <div class="col-xs-12" style="display:none;">-->
<!--            <div class="form-group">-->
<!--                <div class="col-sm-8 col-sm-offset-3">-->
<!--                    <button class="btn btn-primary" type="button" onclick="submitHandler()">发放</button>-->
<!--                </div>-->
<!--            </div>-->
<!--        </div>-->
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:inline="javascript">
    $("#datetimepicker-demo-2").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true,
        clearBtn: true
    });

    var prefix = ctx + "voucher/member";
    $("#form-coupon").validate({
        focusCleanup: true,
        rules: {
            validityTime: {
                required: true
            },
            memberId: {
                required: true
            },
        }
    });
    
    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-coupon').serialize());
        }
    }
</script>
</body>
</html>
