<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">
                        <form action="/admin/ticket/access/exportList" id="searchForm" method="GET">
                            门票ID：<input type="text" name="ticketUid" id="ticketUid" class="input-sm" />
                            门票名称：<input type="text" name="ticketName" id="ticketName" class="input-sm" />
                            平台号：<input type="text" name="erbanNO" id="erbanNO" class="input-sm" />
                            类型及方式：<select id="objType" name="objType" class="input-sm">
                                <option value="" selected="selected">请选择</option>、
                                <option value="6">商城充值币购买</option>
                                <option value="1">注册获赠/</option>
                                <option value="2">每日登录获赠</option>
                                <option value="3">每周登录获赠</option>
                                <option value="4">成功邀请好友参赛获赠</option>
                                <option value="5">参赛使用</option>
                                <option value="7">退还</option>
                                <option value="8">后台赠送</option>
                                <option value="9">渠道门票包领取</option>
                            </select>
                            开始时间：<input type="text" name="queryMatchStartTime" id="queryMatchStartTime" class="input-sm"
                                placeholder="">
                            结束时间：<input type="text" name="queryMatchEndTime" id="queryMatchEndTime" class="input-sm"
                                placeholder="">
                        </form>
                        <button id="btnSearch" class="btn btn-sm btn-primary">查询</button>
                        <button id="btnExport" class="btn btn-sm btn-primary">导出</button>
                    </div>
                </div>
            </div>

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

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

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

const groupIdObj = {};
const ticketIdObj = {};
const integer_max = 2147483647;
export default {
    name: "GameManageTicketHistoryAdminView",
    setup() {
        return {};
    },
    created() {
        this.$nextTick(function () {
            this.initData();
        });
    },
    methods: {
        initData() {
            $(function () {
                const main = {
                    init: function () {
                        // this.getTicketDataFormBack();
                    },
                    // 获取游戏门票列表
                    getTicketDataFormBack: function () {
                        $.get('/admin/gameManage/listTicketByPage', { page: 1, pageSize: integer_max }, function (res) {
                            if (res) {
                                let str = '<option value="" selected= "selected" >请选择</option>';
                                for (let i = 0; i < res.rows.length; i++) {
                                    // id对象存储
                                    const id = '' + res.rows[i].ticketId;
                                    ticketIdObj[id] = res.rows[i];
                                    str += '<option value="' + res.rows[i].ticketId + '">' + res.rows[i].ticketName + '</option>';
                                }
                                $('#ticketId').html(str);
                                console.log('ticketIdObj', ticketIdObj);
                            }
                        });
                    },
                };
                // main.init();

                $('.datetime').datetimepicker({
                    format: 'yyyy-mm-dd hh:ii:00',
                    autoclose: true
                });

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

                $('#table').bootstrapTable('destroy');
                $('#table').bootstrapTable({
                    columns: [
                        { field: 'ticketUid', title: '门票ID', align: 'center', width: '5%' },
                        { field: 'ticketName', title: '名称', align: 'center', width: '8%' },
                        { field: 'price', title: '价格', align: 'center', width: '5%' },
                        {
                            field: 'type', title: '类型', align: 'center', width: '5%',
                            formatter: function (val, row) {
                                if (val == 1) {
                                    return '获取'
                                } else if (val == 2) {
                                    return '消耗'
                                }
                            }
                        },
                        {
                            field: 'objType', title: '方式', align: 'center', width: '5%',
                            formatter: function (val, row) {
                                if (val == 1) {
                                    return '注册获赠'
                                } else if (val == 2) {
                                    return '每日登录获赠'
                                } else if (val == 3) {
                                    return '每周登录获赠'
                                } else if (val == 4) {
                                    return '成功邀请好友参赛获赠'
                                } else if (val == 5) {
                                    return '参赛使用'
                                } else if (val == 6) {
                                    return '商城充值币购买'
                                } else if (val == 7) {
                                    return '退还'
                                } else if (val == 8) {
                                    return '后台赠送'
                                } else if (val == 9) {
                                    return '渠道门票包领取'
                                }
                            }
                        },
                        { field: 'nick', title: '用户昵称', align: 'center', width: '5%' },
                        { field: 'erbanNo', title: '用户平台号', align: 'center', width: '5%' },
                        { field: 'createTime', title: '时间', align: 'center', valign: 'middle', width: '10%', formatter: formatTime },
                    ],
                    undefinedText: "0",
                    cache: false,
                    striped: true,
                    showRefresh: true,
                    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,
                            ticketUid: $("#ticketUid").val(),
                            ticketName: $("#ticketName").val(),
                            objType: $("#objType").val(),
                            erbanNo: $("#erbanNO").val(),
                            startTime: $("#queryMatchStartTime").val(),
                            endTime: $("#queryMatchEndTime").val(),
                        };
                        return param;
                    },
                    url: '/admin/ticket/access/listTicketWalletHistory',
                    toolbar: '#toolbar',
                    onLoadSuccess: function (data) {  //加载成功时执行
                        console.log("load success");
                    },
                    onLoadError: function () {  //加载失败时执行
                        console.log("load fail");
                    }
                });
                // 查询刷新
                $('#btnSearch').on('click', function () {
                    TableHelper.doRefresh('#table');
                });


                function formatTime(val) {
                    if (val) {
                        var date = new Date(val);
                        return date.format('yyyy-MM-dd hh:mm:ss');
                    } else {
                        return '';
                    }
                }

                function serverError(req) {
                    $("#tipMsg").text(req.responseJSON.message);
                    $("#tipModal").modal('show');
                }

                function apiResult(json) {
                    if (json.code == 200 && json.message == 'success') {
                        return true;
                    }
                    $("#tipMsg").text("请求失败，错误信息：" + json.message);
                    $("#tipModal").modal('show');
                    return false;
                }

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

        }
    },

};
</script>

<style scoped>
#awardListModal .modal-dialog {
    width: 900px;
}

#awardListModal .fixed-table-body {
    height: 80%;
}</style>