<!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>
<style>
    td {
        horiz-align: center;
        text-align: left;
        padding: 10px;
    }

</style>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <div class="col-sm-12 search-collapse">
        <form id="formId">
            <div class="select-list">
                <ul>
                    <li>
                        <label>搜索类型：</label>
                        <select id="type" name="type">
                            <option value="0">请选择</option>
                            <option value="1">商品[订单时间]</option>
                            <option value="2">演出[订单时间]</option>
                            <option value="3">演出[演出id]</option>
                            <option value="4">演出[演出时间]</option>
                            <option value="5">会员[订单时间]</option>
                        </select>
                    </li>
                    <li>
                        <label>演出id：</label>
                        <input id="performanceId" type="text" name="performanceId"/>
                    </li>
                    <li>
                        <div class="form-group">
                            <label>时间范围：</label>
                            <input type="text" style="width: 200px;float: left"
                                   class="form-control" id="startTime" placeholder="开始时间选择" name="timeStart"/>
                            <span class="control-label"
                                  style="float: left;margin-left: 10px;margin-right: 10px"> - </span>
                            <input type="text" style="width: 200px;float: left"
                                   class="form-control" id="endTime" placeholder="结束时间选择" name="timeEnd"/>
                        </div>
                    </li>
                    <li>
                        <a class="btn btn-primary btn-rounded btn-sm" onclick="searchExport()"><i
                                class="fa fa-search"></i>导出</a>
                    </li>
                </ul>
            </div>
        </form>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>

<script th:inline="javascript">
    var prefix = ctx + "tools/export";
    var url = prefix;
    var formData = new FormData();

    $("input[name='timeStart']").datetimepicker({
        format: "yyyy-mm-dd hh:ii:ss",
        autoclose: true
    });

    $("input[name='timeEnd']").datetimepicker({
        format: "yyyy-mm-dd hh:ii:ss",
        autoclose: true
    });

    function searchExport() {
        var type = document.getElementById("type").value;
        var performanceId = document.getElementById("performanceId").value;
        var st = document.getElementById("startTime").value;
        var et = document.getElementById("endTime").value;
        var exportType = 0;
        if (type == 2) {
            exportType = 1;
        } else if (type == 3) {
            exportType = 3;
        } else if (type == 4) {
            exportType = 2;
        }
        if (type == 0) {
            alert("请选择导出类型");
            return
        } else if (type == 1) {//商品导出逻辑
            if (st == "" || et == "") {
                alert("请选择时间范围");
                return
            } else {
                url = url + "/export/commodityOrder";
            }
        } else if (type == 2) {//演出[订单时间]
            if (st == "" || et == "") {
                alert("请选择时间范围");
                return
            } else {
                url = url + "/export/orderInfo";
            }
        } else if (type == 3) {//演出[演出id]
            if (performanceId == "") {
                alert("演出id不能为空");
                return
            } else {
                url = url + "/export/orderInfo";
            }
        } else if (type == 4) {//演出[演出时间]
            if (st == "" || et == "") {
                alert("请选择时间范围");
                return
            } else {
                url = url + "/export/orderInfo";
            }
        } else if (type == 5) {//会员[订单时间]
            if (st == "" || et == "") {
                alert("请选择时间范围");
                return
            } else {
                url = url + "/export/memberOrder";
            }
        }
        var options = {
            modalName: "财务导出",
            exportUrl: url,
        }
        $.table.init(options);
        var param = {
            "beginTime": st,
            "endTime": et,
            "showId": performanceId,
            "exportType": exportType
        };
        $.table.exportExcel("", param)
        url = prefix;
    }
</script>
</body>
</html>
