<!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-post-add">
        <input hidden="hidden" type="text" name="orderTicketsId" id="orderTicketsId">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">订单编号：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="orderCode" id="orderCode" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">快递费：</label>
            <div class="col-sm-8">
                <input class="form-control" type="number" min="0" name="RefundPriceExpress">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">入场人：</label>
            <div class="col-sm-8">
                <div class="col-sm-12 select-table table-bordered">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
        <div class="form-group">
			<label class="col-sm-3 control-label layui-required is-required">备注：</label>
			<div class="col-sm-8">
            	<textarea name="reason" maxlength="500" class="form-control layui-required" rows="3"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
    var prefix = ctx + "kylin/refund";

    $("#form-post-add").validate({
        onkeyup: false,
        rules: {
            orderCode: {
                submitHandler: function (form) {
                    var config = {
                        url: prefix + "/applyOrder",
                        type: "post",
                        dataType: "json",
                        data: {
                            "orderCode": function () {
                                return $.common.trim($("#orderCode").val());
                            }
                        },
                        beforeSend: function () {
                            $.modal.loading("正在查询订单，请稍后...");
                        },
                        success: function (result) {
                            if (result.msg) {
                                layer.msg("未找到该订单信息");
                            } else {
                                $("#orderTicketsId").val(result.orderTicketVo.orderTicketsId);
                                $('input[name="RefundPriceExpress"]').val(result.orderTicketVo.priceExpress);
                                $('input[name="RefundPriceExpress"]').attr("max", result.orderTicketVo.priceExpress);
                                var options = {
                                    data: result.orderTicketEntitiesVo,
                                    pagination: false,
                                    columns: [{
                                        checkbox: true
                                    },
                                        {
                                            field: 'orderTicketEntitiesId',
                                            title: '入场人id'
                                        },
                                        {
                                            field: '',
                                            title: '退款金额',
                                            formatter: function (value, row, index) {
                                                var price = result.orderTicketVo.price;
                                                var html = '<input class="form-control" type="number" min="0.01" max="'+price+'" name="entitiesPrice" value="'+price+'">';
                                                return html;
                                            }
                                        },
                                    ]
                                };
                                $.table.init(options);
                                // $('#bootstrap-table').
                            }
                            $.modal.closeLoading();
                        }
                    };
                    $.ajax(config)
                }
            },
        },
        focusCleanup: true
    });

    function submitHandler() {
        var reason = $('#form-post-add').find("[name='reason']").val();
        var orderTicketsId = $('#form-post-add').find("[name='orderTicketsId']").val();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
		if (!orderTicketsId || !reason || rows.length <= 0) {
			layer.msg("请完善数据");
			return false;
		}
        if ($.validate.form()) {
            var data = $('#form-post-add').serializeArray();
            data.push({"name":"ticketEntityIds","value":rows});
            $.operate.save(prefix + "/apply", data);
        }
    }
</script>
</body>
</html>
