<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="searchForm" action="/admin/car/export" method="get" target="_blank">
                        <div class="col-sm-12">
                            <label for="carId" class="col-sm-1 control-label">座驾ID:</label>
                            <div class="col-sm-2"><input type="text" class="form-control" name="carId" id="carId"></div>
                            <label for="carName" class="col-sm-1 control-label">座驾名称:</label>
                            <div class="col-sm-2"><input type="text" class="form-control" name="carName" id="carName"></div>
                            <label for="beginDate" class="col-sm-1 control-label">开始日期:</label>
                            <div class="col-sm-2"><input type="text" class="form-control" name="beginDate" id="beginDate">
                            </div>
                            <label for="endDate" class="col-sm-1 control-label">结束日期:</label>
                            <div class="col-sm-2"><input type="text" class="form-control" name="endDate" id="endDate"></div>
                        </div>
                    </form>
                    <div class="col-sm-12">
                        <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>
        </div>
    </section>
</template>

<script>
import TableHelper from '@/utils/bootstrap-table-helper';

export default {
    name: "CarStatisticsView",
    setup() {
        return {};
    },
    created() {
        this.$nextTick(function () {
            this.initData();
        });
    },
    methods: {
        initData() {
            $(function () {
                $('#table').bootstrapTable('destroy');
                $('#table').bootstrapTable({
                    columns: [
                        { field: 'tmp', title: 'id', align: 'center', checkbox: true, width: '5%' },
                        { field: 'createTime', title: '日期', align: 'center', width: '5%' },
                        { field: 'carId', title: '座驾ID', align: 'center', width: '5%' },
                        { field: 'carName', title: '座驾名称', align: 'center', width: '5%' },
                        { field: 'carPrice', title: '座驾金额(钻石)', align: 'center', width: '5%' },
                        { field: 'carRadishPrice', title: '座驾金额(萝卜)', align: 'center', width: '5%' },
                        { field: 'carStatus', title: '座驾状态', align: 'center', width: '5%' },
                        { field: 'receivedCarNum', title: '用户收到数量', align: 'center', width: '5%' },
                    ],
                    cache: false,
                    striped: true,
                    showRefresh: false,
                    pageSize: 20,
                    pagination: true,
                    pageList: [20, 50, 100, 200, 300, 500],
                    search: false,
                    sidePagination: "server", //表示服务端请求
                    queryParamsType: "undefined",
                    queryParams: function queryParams(params) {   //设置查询参数
                        var param = {
                            pageNum: params.pageNumber,
                            pageSize: params.pageSize,
                            carId: $('#carId').val(),
                            carName: $('#carName').val(),
                            beginDate: $('#beginDate').val(),
                            endDate: $('#endDate').val(),
                        };
                        return param;
                    },
                    toolbar: '#toolbar',
                    url: '/admin/car/statisticsCar',
                    onLoadSuccess: function () {  //加载成功时执行
                        console.log("load success");
                    },
                    onLoadError: function () {  //加载失败时执行
                        console.log("load fail");
                    }
                });

                // 导出EXCEL
                $('#btnExport').on('click', function () {
                    $("#searchForm").submit();
                });

                // 查询刷新
                $('#btnSearch').on('click', function () {
                    TableHelper.doRefresh('#table');
                });

                var picker1 = $("#beginDate").datetimepicker({
                    format: 'yyyy-mm-dd hh:ii:00',
                    todayBtn: true,
                    autoclose: true,
                });
                var picker2 = $("#endDate").datetimepicker({
                    format: 'yyyy-mm-dd hh:ii:00',
                    todayBtn: true,
                    autoclose: true
                });
                picker1.on('changeDate', function () {
                    var date = $('#beginDate').datetimepicker('getDate');
                    picker2.datetimepicker('setStartDate', date);
                });
                picker2.on('changeDate', function () {
                    var date = $('#endDate').datetimepicker('getDate');
                    picker1.datetimepicker('setEndDate', date);
                });
            });
        }
    },

};
</script>

<style scoped></style>