<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('提交订单退款')"/>
    <th:block th:include="include :: select2-css"/>
    <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-post-add">
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">标题：</label>
            <div class="col-sm-10">
                <input class="form-control" type="text" name="banners_id" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">展示位置</label>
            <div class="col-sm-10">
                <label th:each="type : ${BannersDisplayLocation}" class="checkbox-inline">
                    <input name="positionList[]" th:text="${type.name}" th:value="${type.id}" type="checkbox">
                </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">请选择跳转类型</label>
            <div class="col-sm-5">
                <select class="form-control" name="target_type">
                    <option value="">--请选择跳转类型--</option>
                    <option th:each="type : ${BannersTargetType}" th:text="${type.name}" th:value="${type.id}"></option>
                </select>
            </div>
            <div class="col-sm-5">
                <input class="form-control" type="text" name="target_obj" placeholder="请填写url">
                <select class="form-control" name="target_obj">
                    <option value="">--请选择--</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">推广省份</label>
            <div class="col-sm-10">
                <div class="radio check-box">
                    <label>
                        <input type="radio" value="1" name="promotionType" checked=""> 全国
                    </label>
                </div>
                <div class="radio check-box">
                    <label>
                        <input type="radio" value="2" name="promotionType"> 省份
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">请选择省份</label>
            <div class="col-sm-5">
                <select class="form-control" name="provincesList[]">
                    <option value="">--请选择省份--</option>
                    <option value=".NET">.NET</option>
                </select>
            </div>
            <div class="col-sm-5">
                <button type="button" class="btn btn-w-m btn-danger">删除</button>
                <button type="button" class="btn btn-w-m btn-success">添加</button>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">是否上线</label>
            <div class="col-sm-10">
                <div class="radio check-box">
                    <label>
                        <input type="radio" value="1" name="is_online" checked=""> <i></i> 上线
                    </label>
                </div>
                <div class="radio check-box">
                    <label>
                        <input type="radio" value="0" name="is_online"> <i></i> 下线
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">上线开始/结束时间</label>
            <div class="col-sm-10">
                <div class="input-daterange input-group">
                    <input name="online_start_time" type="text" class="input-sm form-control" id="laydate-startTime"
                           placeholder="yyyy-MM-dd HH:mm:ss"/>
                    <span class="input-group-addon">到</span>
                    <input name="online_end_time" type="text" class="input-sm form-control" id="laydate-endTime"
                           placeholder="yyyy-MM-dd HH:mm:ss"/>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: datetimepicker-js" />
<script type="text/javascript">
    var prefix = ctx + "kylin/refund";

    $("#form-post-add").validate({
        onkeyup: false,
        rules: {
            orderTicketsId: {
                submitHandler: function (form) {
                    var config = {
                        url: prefix + "/applyOrder",
                        type: "post",
                        dataType: "json",
                        data: {
                            "orderTicketsId": function () {
                                return $.common.trim($("#orderTicketsId").val());
                            }
                        },
                        beforeSend: function () {
                            $.modal.loading("正在查询订单，请稍后...");
                        },
                        success: function (result) {
                            var options = {
                                data: result.orderTicketEntitiesVo,
                                pagination: false,
                                columns: [{
                                    checkbox: true
                                },
                                    {
                                        field: 'orderTicketEntitiesId',
                                        title: '入场人id'
                                    },
                                ]
                            };
                            $.table.init(options);
                            $.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({"ticketEntityIds": rows.join()});
            data.push({"name": "ticketEntityIds", "value": rows});
            $.operate.save(prefix + "/apply", data);
        }
    }
    $(function (){
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            var startDate = laydate.render({
                elem: '#laydate-startTime',
                type: 'datetime',
                max: $('#laydate-endTime').val(),
                theme: 'molv',
                trigger: 'click',
                done: function(value, date) {
                    // 结束时间大于开始时间
                    if (value !== '') {
                        endDate.config.min.year = date.year;
                        endDate.config.min.month = date.month - 1;
                        endDate.config.min.date = date.date;
                    } else {
                        endDate.config.min.year = '';
                        endDate.config.min.month = '';
                        endDate.config.min.date = '';
                    }
                }
            });

            var endDate = laydate.render({
                elem: '#laydate-endTime',
                type: 'datetime',
                min: $('#laydate-startTime').val(),
                theme: 'molv',
                trigger: 'click',
                done: function(value, date) {
                    // 开始时间小于结束时间
                    if (value !== '') {
                        startDate.config.max.year = date.year;
                        startDate.config.max.month = date.month - 1;
                        startDate.config.max.date = date.date;
                    } else {
                        startDate.config.max.year = '';
                        startDate.config.max.month = '';
                        startDate.config.max.date = '';
                    }
                }
            });
        });
    })
</script>
</body>
</html>
