<!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-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">
                    <select id="discountWay" name="discountWay" class="form-control m-b" th:with="type=${@dict.getType('discountWay')}" required onchange="changeDiscountWay(this)">
                        <option value="">--请选择--</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">优惠值：</label>
                <div class="col-sm-8">
                    <input id="discountValue" name="discountValue" class="form-control" min="0" max="10000" type="text" placeholder="请输入区间0~10000" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">开始时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="startTime" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">过期天数：</label>
                <div class="col-sm-8">
                    <input name="expireDays" class="form-control" type="number" placeholder="请输入区间0~366" min="0" max="366" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "manage/coupon"
        $("#form-coupon-add").validate({
            focusCleanup: true
        });

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

        $("input[name='startTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        function changeDiscountWay(obj){
            var discountWay = $(obj).val();
            if(discountWay == '3'){
                $("#discountValue").attr("placeholder","请输入2位小数折扣").attr("max","1");
            }else{
                $("#discountValue").attr("placeholder","请输入区间0~10000").attr("max","10000");
            }
        }

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