<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>后台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="shortcut icon" th:href="@{/images/logo.jpg}"/>
    <link rel="stylesheet" th:href="@{/js/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/js/layui/css/admin.css}">
    <script type="text/javascript" th:src="@{/js/jquery-3.3.1.min.js}"></script>
    <script th:src="@{/js/layui/layui.js}" charset="utf-8"></script>
</head>
<body>
<div class="layui-form" style="padding: 20px 0 0 0;">
    <form id="formId" onsubmit="return false;">

        <input type="hidden" name="discountId" th:value="${obj.discountId}">

        <div class="layui-form-item">
            <label class="layui-form-label">总金额</label>
            <div class="layui-input-inline">
                <input type="number" class="layui-input" id="totalPrice" name="totalPrice" th:value="${obj.totalPrice}">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">减免金额</label>
            <div class="layui-input-inline">
                <input type="number" class="layui-input" id="reductionPrice" name="reductionPrice"
                       th:value="${obj.reductionPrice}">
            </div>
        </div>


        <label class="layui-form-label"><span style="color: red">*</span>是否包邮</label>
        <div class="layui-input-inline">
            <select name="discountType" id="discountType">
                <option value="1">否</option>
                <option value="2">是</option>
            </select>
        </div>

        <button class="layui-btn" style="display: none;" id="saveBtn" onclick="save()">保存</button>
    </form>
</div>
<script>


    $(function () {
        $("#discountType").find("option[value=" + '[[${obj.discountType}]]' + "]").attr("selected", true);
    })


    layui.use('form', function () {
        var form = layui.form;
        form.render();
    });

    function save() {
        var totalPrice = $("#formId input[id='totalPrice']").val();
        if (totalPrice == '') {
            layer.msg("自取地址不能为空!");
            return false;
        }

        var formdata = $("#formId").serialize()
        $.ajax({
            url: "updateDiscount",
            data: formdata,
            type: "POST",
            dataType: "json",
            success: function (result) {
                if (result.code == 100) {
                    layer.msg(result.msg, {icon: 6, time: 1000}, function () {
                        closeLayer();
                        parent.layui.table.reload('tableId');
                    });
                } else {
                    layer.msg(result.msg, {icon: 5});
                }
            }
        });
    }

    function closeLayer() {
        var index = parent.layer.getFrameIndex(window.name);
        //关闭当前frame
        parent.layer.close(index);
    }

</script>
</body>

</html>