<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>
                <div id="toolbar">
                    <div class="col-sm-12">

                        <div class="col-sm-4">
                            <label for="startTime" class="col-sm-4 control-label">开始日期:</label>
                            <div class="col-sm-8">
                                <input type="text" class="input-sm form-control" name="startTime" id="startTime">
                            </div>
                        </div>


                        <div class="col-sm-4">
                            <label for="endTime" class="col-sm-4 control-label">结束日期:</label>
                            <div class="col-sm-8">
                                <input type="text" class="input-sm form-control" name="endTime" id="endTime">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <button class="btn btn-default js-quick-search js-quick-search-1" data-days="1">
                            昨天
                        </button>
                        <button class="btn btn-default js-quick-search js-quick-search-7" data-days="7">
                            最近7天
                        </button>
                        <button class="btn btn-default js-quick-search js-quick-search-30" data-days="30">
                            最近30天
                        </button>
                    </div>
                    <div class="col-sm-12">
                        <button id="btnSearch" class="btn btn-default">
                            <i class="glyphicon glyphicon-search"></i>查询
                        </button>
                    </div>
                </div>
            </div>

            <!-- .content -->
            <div id="table"></div>

        </div>
    </section>
</template>

<script>
import TableHelper from '@/utils/bootstrap-table-helper';
import { formatTime } from '@/utils/maintainer';

export default {
    name: "ActCallBattlePlatformAdminView",
    setup() {
        return {};
    },
    created() {
        this.$nextTick(function () {
            this.initData();
        });
    },
    methods: {
        initData() {
            $(function () {
                $('#table').bootstrapTable('destroy');
                $('#table').bootstrapTable({
                    columns: [
                        {
                            field: 'queryDate', title: '日期', align: 'center', width: '5%',
                            formatter: function (val, row, index) {
                                if (val) {
                                    var date = new Date(val);
                                    return date.format('yyyy-MM-dd');
                                } else {
                                    return '-';
                                }
                            }
                        },
                        { field: 'memberNum', title: '总人数', align: 'center', width: '10%' },
                        { field: 'totalPlayTimes', title: '总人次', align: 'center', width: '10%', valign: 'center' },
                        { field: 'roundNum', title: '总轮数', align: 'center', width: '5%', },
                        { field: 'totalPiece', title: '总投入', align: 'center', width: '5%', },
                        { field: 'totalPlatformValue', title: '总平台价值', align: 'center', width: '5%', },
                        { field: 'totalTicket', title: '门票', align: 'center', width: '5%', },
                    ],
                    undefinedText: 0,
                    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 = {
                            page: params.pageNumber,
                            pageSize: params.pageSize,
                            startTime: $('#startTime').val(),
                            endTime: $('#endTime').val()
                        };
                        return param;
                    },
                    toolbar: '#toolbar',
                    url: '/admin/callBattle/listPlatformStat',
                    onLoadSuccess: function () {  //加载成功时执行
                        console.log("load success");
                    },
                    onLoadError: function () {  //加载失败时执行
                        console.log("load fail");
                    }
                });

                $('.js-quick-search').on('click', function () {
                    $('.js-quick-search').removeClass('active')
                    $(this).addClass('active');
                    setSearchTimeUseQuickWay($(this));

                    TableHelper.doRefresh('#table');
                });

                function setSearchTimeUseQuickWay(quickDom) {
                    const days = quickDom.attr("data-days");
                    const today = new Date(new Date().setHours(0, 0, 0, 0));
                    const todayStr = formatTime(today);
                    const startTime = formatTime(new Date(today.getTime() - days * 24 * 60 * 60 * 1000));

                    $('#startTime').val(startTime);
                    $('#endTime').val(todayStr);
                }

                const quickDom = $('.js-quick-search-7');
                quickDom.addClass('active');
                setSearchTimeUseQuickWay(quickDom);


                // 查询刷新
                $('#btnSearch').on('click', function () {
                    TableHelper.doRefresh('#table');
                });
                var chargeStart = $('#startTime').datepicker({
                    format: 'yyyy-mm-dd 00:00:00',
                    autoclose: true
                });

                var chargeEnd = $('#endTime').datepicker({
                    format: 'yyyy-mm-dd 00:00:00',
                    autoclose: true
                });
            });
        }
    },

};
</script>

<style scoped>
#teamDetailModal .modal-dialog,
#userDetailModal .modal-dialog {
    width: 50%;
}
</style>