<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">
                    66号: <input type="text" class="input-medium" name="erbanNoStr" id="erbanNoStr" placeholder="填多个用,隔开">
                    开始时间：<input type="text" name="startTime" id="startTime" class="input-sm">
                    结束时间：<input type="text" name="endTime" id="endTime" class="input-sm">
                    <button id="btnSearch" class="btn btn-default">
                        <i class="glyphicon glyphicon-search"></i>查询
                    </button>
                    <button id="btnExport" class="btn btn-sm btn-primary">导出</button>
                </div>
            </div>

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

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

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

export default {
    name: "ActCallBattleUserStatAdminView",
    setup() {
        return {};
    },
    created() {
        this.$nextTick(function () {
            this.initData();
        });
    },
    methods: {
        initData() {
            $(function () {
                $('#table').bootstrapTable('destroy');
                $('#table').bootstrapTable({
                    columns: [
                        { field: 'uid', title: 'uid', align: 'center', width: '5%' },
                        { field: 'erbanNo', title: '66号', align: 'center', width: '5%' },
                        { field: 'nick', title: '昵称', align: 'center', width: '5%' },
                        { field: 'roundId', title: '轮次', align: 'center', width: '5%' },
                        {
                            field: 'endTime', title: '结束时间', align: 'center', width: '5%',
                            formatter: function (val, row, index) {
                                if (val) {
                                    var date = new Date(val);
                                    return date.format('yyyy-MM-dd hh:mm:ss');
                                } else {
                                    return '-';
                                }
                            }
                        },
                        { field: 'costPieceNum', title: '投入', align: 'center', width: '5%' },
                        { field: 'prizePieceNum', 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,
                            erbanNoStr: $('#erbanNoStr').val(),
                            startTime: $('#startTime').val(),
                            endTime: $('#endTime').val(),
                        };
                        return param;
                    },
                    toolbar: '#toolbar',
                    url: '/admin/callBattle/listUserDrawRecordList',
                    onLoadSuccess: function () {  //加载成功时执行
                        console.log("load success");
                    },
                    onLoadError: function () {  //加载失败时执行
                        console.log("load fail");
                    }
                });

                // 导出
                $('#btnExport').on('click', function () {
                    console.log("导出")
                    window.location.href = `/admin/callBattle/exportUserDrawRecordList?${param(getQueryParams())}`
                })

                function param(json) {
                    if (!json) return ''
                    return cleanArray(Object.keys(json).map(key => {
                        if (json[key] === undefined) return ''
                        return encodeURIComponent(key) + '=' +
                            encodeURIComponent(json[key])
                    })).join('&')
                }

                function getQueryParams() {
                    var param = {
                        erbanNoStr: $('#erbanNoStr').val(),
                        startTime: $('#startTime').val(),
                        endTime: $('#endTime').val(),
                    };
                    return param;
                }

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

                var picker1 = $("#startTime").datetimepicker({
                    format: 'yyyy-mm-dd hh:ii:00',
                    autoclose: true
                })
                var picker2 = $('#endTime').datetimepicker({
                    format: 'yyyy-mm-dd hh:ii:00',
                    autoclose: true
                })

            });
        }
    },

};
</script>

<style scoped></style>