<template>
    <section class="content">
        <div class="box box-primary">
            <div class="box-body">
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1 id="itemTitle"></h1>
                </section>
                <!-- .content -->
                <div id="table"></div>
                <div id="toolbar">
                    <form id="searchForm1" action="/admin/gamePartner/order/dayExport" method="get" target="_blank">
                        <div class="col-sm-12">
                            <label for="startTime" class="col-sm-2 control-label">日期:</label>
                            <div class="col-sm-4"><input type="text" class="form-control" name="startTime" id="startTime">
                            </div>
                            <label for="endTime" class="col-sm-1 control-label">-</label>
                            <div class="col-sm-4"><input type="text" class="form-control" name="endTime" id="endTime"></div>
                        </div>
                    </form>
                    <button id="btnSearch" class="btn btn-default">
                        <i class="glyphicon glyphicon-search"></i>查询
                    </button>
                    <button id="btnExport" class="btn btn-default">
                        <i class="glyphicon glyphicon-export"></i>导出
                    </button>
                </div>
            </div>
        </div>
    </section>


    <div class="modal fade" id="detailModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content" style="width: 190%; left: 50%; transform: translateX(-50%);">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title" id="modalLabel">订单详情</h4>
                </div>
                <form id="searchForm2" action="/admin/gamePartner/order/dayDetailExport" method="get" target="_blank">
                    <input type="hidden" name="orderDate" id="orderDate" />
                    <div class="modal-body">
                        <!-- .content -->
                        <div id="detailTable"></div>
                    </div>
                </form>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" id="detailExport">导出</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="tipModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">提示信息</h4>
                </div>
                <div class="modal-body" id="tipMsg"></div>
            </div>
        </div>
    </div>
</template>
<script>
import TableHelper from '@/utils/bootstrap-table-helper';
export default {
    name: "GamePartnerOrderDetailView",
    setup() { },
    created() {
        this.$nextTick(function () {
            this.initData();
        });
    },
    methods: {
        initData() {
            $(function () {
                $('#table').bootstrapTable('destroy');
                // 清空分页组件的容器
                $('.fixed-table-pagination').empty();
                $('#table').bootstrapTable({
                    columns: [
                        { field: 'orderTime', title: '日期', align: 'center', width: '5%' },
                        { field: 'orderNum', title: '下单用户数', align: 'center', width: '5%' },
                        { field: 'totalInning', title: '累积下单局数', align: 'center', width: '5%' },
                        { field: 'orderCount', title: '累积下单次数', align: 'center', width: '5%' },
                        { field: 'totalAmount', title: '累积下单金额（钻）', align: 'center', width: '5%' },
                        {
                            field: 'handle',
                            title: '详情',
                            align: 'center',
                            width: '5%',
                            valign: 'middle',
                            formatter: function (val, row, index) {
                                return '<button class="btn btn-sm btn-default opt-detail" data-index="' + index + '">详情</button>';
                            }
                        }
                    ],
                    cache: false,
                    striped: true,
                    showRefresh: false,
                    pageSize: 20,
                    pagination: true,
                    pageList: [20, 50, 100],
                    search: false,
                    sidePagination: "server", //表示服务端请求
                    //设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder
                    //设置为limit可以获取limit, offset, search, sort, order
                    queryParamsType: "undefined",
                    queryParams: function queryParams(params) {   //设置查询参数
                        var param = {
                            page: params.pageNumber,
                            pageSize: params.pageSize,
                            startTime: $('#startTime').val(),
                            endTime: $('#endTime').val(),
                        };
                        return param;
                    },
                    toolbar: '#toolbar',
                    url: '/admin/gamePartner/order/dayPage',
                    onLoadSuccess: function () {  //加载成功时执行
                        console.log("load success");
                    },
                    onLoadError: function () {  //加载失败时执行
                        console.log("load fail");
                    }
                });
                var picker1 = $("#startTime").datetimepicker({
                    format: 'yyyy-mm-dd hh:ii:00',
                    todayBtn: true,
                    autoclose: true,
                });
                var picker2 = $("#endTime").datetimepicker({
                    format: 'yyyy-mm-dd hh:ii:00',
                    todayBtn: true,
                    autoclose: true
                });
                picker1.on('changeDate', function () {
                    var date = $('#startTime').datepicker('getDate');
                    picker2.datepicker('setStartDate', date);
                });
                picker2.on('changeDate', function () {
                    var date = $('#endTime').datepicker('getDate');
                    picker1.datepicker('setEndDate', date);
                });
                $('#table').on('click', '.opt-detail', function () {
                    const currentData = $('#table').bootstrapTable('getData')[$(this).data('index')];
                    var orderTime = currentData.orderTime;
                    $('#orderDate').val(orderTime);
                    $("#detailModal").modal('show');
                    $('#detailTable').bootstrapTable('destroy');
                    // 清空分页组件的容器
                    $('.fixed-table-pagination').empty();
                    $('#detailTable').bootstrapTable({
                        columns: [
                            { field: 'fromErBanNo', title: '下单用户id', align: 'center', width: '5%' },
                            { field: 'fromNick', title: '下单用户昵称', align: 'center', width: '5%' },
                            { field: 'toErBanNo', title: '接单用户id', align: 'center', width: '5%' },
                            { field: 'toNick', title: '接单用户昵称', align: 'center', width: '5%' },
                            { field: 'hallErBanNo', title: '房主id', align: 'center', width: '5%' },
                            { field: 'hallRoomName', title: '房间名称', align: 'center', width: '5%' },
                            { field: 'gameName', title: '下单游戏', align: 'center', width: '5%' },
                            { field: 'amount', title: '下单金额（钻）', align: 'center', width: '5%' },
                            { field: 'orderTime', title: '下单时间', align: 'center', width: '5%' },
                        ],
                        cache: false,
                        striped: true,
                        showRefresh: false,
                        pageSize: 20,
                        pagination: true,
                        pageList: [20, 50, 100],
                        search: false,
                        //表示服务端请求
                        sidePagination: "server",
                        //设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder
                        //设置为limit可以获取limit, offset, search, sort, order
                        queryParamsType: "undefined",
                        //设置查询参数
                        queryParams: function queryParams(params) {
                            var param = {
                                page: params.pageNumber,
                                pageSize: params.pageSize,
                                orderDate: orderTime
                            };
                            return param;
                        },
                        url: '/admin/gamePartner/order/dayDetailPage',
                        //加载成功时执行
                        onLoadSuccess: function () {
                            console.log("load success");
                        },
                        //加载失败时执行
                        onLoadError: function () {
                            console.log("load fail");
                        }
                    });
                });
                // 查询刷新
                $('#btnSearch').on('click', function () {
                    TableHelper.doRefresh('#table');
                });
                //导出功能
                $("#btnExport").on('click', function () {
                    $("#searchForm1").submit();
                });
                //导出功能
                $("#detailExport").on('click', function () {
                    $("#searchForm2").submit();
                });
            });
        }
    }
};
</script>

<style scoped>
.fixed-table-pagination .page-list {
    display: block !important;
}

.fixed-table-pagination div.pagination,
.fixed-table-pagination .pagination-detail {
    display: block !important;
    margin-top: 10px;
    margin-bottom: 10px;
}
</style>
