<!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;">

        <div class="layui-form-item">
            <label class="layui-form-label">订单编号</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="orderId" th:value="${obj.orderId}" readonly="readonly">
            </div>

            <label class="layui-form-label">商品名称</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" th:value="${obj.goodsName}" disabled>
            </div>

            <label class="layui-form-label">商品押金</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" th:value="${obj.goodsPrice}" disabled>
            </div>
        </div>
        <div class="layui-form-item" id="leaseShow">
            <label class="layui-form-label">租赁天数</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" th:value="${obj.leaseDay}" disabled>
            </div>

            <label class="layui-form-label">租赁开始</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" th:value="${obj.leaseStartDate}" disabled>
            </div>

            <label class="layui-form-label">租赁到期</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" th:value="${obj.leaseEndDate}" disabled>
            </div>
        </div>

        <div class="layui-form-item">

            <label class="layui-form-label">商品数量</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" th:value="${obj.goodsNum}" disabled>
            </div>

            <label class="layui-form-label">租金/天</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" th:value="${obj.leaseDayPrice}" disabled>
            </div>

            <label class="layui-form-label">实付金额</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" th:value="${obj.payAmount}" disabled>
            </div>


        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">退款金额</label>
            <div class="layui-input-inline">
                <input type="number" step="0.01" class="layui-input" name="refundAmount" th:value="${obj.refundAmount}">
            </div>
        </div>
        <button class="layui-btn" style="display: none;" id="saveBtn" onclick="save()"></button>
    </form>
</div>
<script>

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

    function save() {
        var trackingName = $("#formId input[name='refundAmount']").val();
        if (trackingName == '') {
            layer.msg("退款金额不能为空!");
            return false;
        }

        if (!b) {
            return false;
        }
        b = false;
        var formdata = $("form").serialize();
        // var form = document.querySelector("#formId");
        // var formdata = new FormData(form);
        // formdata.append("orderId", '[[${obj.orderId}]]');
        $.ajax({
            url: "refund",
            data: formdata,
            type: "POST",
            dataType: "json",
            // processData: false,
            // contentType: false,
            success: function (result) {
                b = true;
                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>