<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/css/bootstrap-datepicker.standalone.min.css">
<link rel="stylesheet" href="<?php echo base_url();?>public/plugins/datatables/jquery.dataTables.min.css">
<link rel="stylesheet" href="<?php echo base_url();?>public/plugins/datatables/extensions/Responsive/css/dataTables.responsive.css">

<div class="content_wrapper">

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>查询</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-inline" role="form" method="POST" action="#statistics/miningGame/<?php echo $type;?>" name="stanpform">
                                        <input type="hidden" name="fromsta_miningGame" value="1">
                                        <?php if($type == 'levelId'){ ?>
                                            <div class="form-group"><input type="text" class="form-control " value="<?php echo $levelId;?>" placeholder="关卡" name="levelId" /></div>
                                        <?php } ?>
                                        <?php if($type == 'playNum'){ ?>
                                            <div class="form-group"><input type="text" class="form-control " value="<?php echo $num;?>" placeholder="游戏次数" name="num" /></div>
                                        <?php } ?>
                                        <?php if($type == 'uid'){ ?>
                                            <div class="form-group"><input type="text" class="form-control " value="<?php echo $uid;?>" placeholder="用户ID" name="uid" /></div>
                                        <?php } ?>
                                        <div class="form-group">
                                            <label>开始时间</label>
                                            <input type="text" class="form-control datetimepicker" value="<?php if($stime) echo $stime;?>" placeholder="开始时间" name="stime" />
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>结束时间</label>
                                            <input type="text" class="form-control datetimepicker" value="<?php if($etime) echo $etime;?>" placeholder="结束时间" name="etime" />
                                        </div>
                                        <?php if(in_array($type,['levelId','playNum','uid'])){ ?>
                                            <button type="button" class="btn btn-primary" id="searchBtn">查询</button>
                                        <?php }else{ ?>
                                            <button type="submit" class="btn btn-primary">查询</button>
                                        <?php }?>

                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>

        <?php if($type == 'pro'){ ?>
            <div class="row">
                <div class="col-sm-12">
                    <aside>
                        <section>
                            <div class="container-fluid">
                                <div class="row">
                                    <div class="table-responsive">
                                        <table class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                                            <thead>
                                            <tr>
                                                <th style="text-align: center;vertical-align: middle;">日期</th>
                                                <th style="text-align: center;vertical-align: middle;">类型</th>
                                                <?php for($i=0;$i<=20;$i++){ ?>
                                                    <th style="text-align: center;vertical-align: middle;">关卡<?php echo $i;?></th>
                                                <?php } ?>
                                            </tr>
                                            </thead>
                                            <tbody id="reportBody">
                                            <?php  foreach($dayList as $k => $val){ ?>
                                                <tr>
                                                    <td style="white-space: nowrap" rowspan="3"><?php echo $val;?></td>
                                                    <td style="white-space: nowrap" rowspan="1">参与次数</td>
                                                    <?php  foreach($data[$k] as $da){ ?>
                                                        <td style="white-space: nowrap" rowspan="1"><?php echo $da['play'];?></td>
                                                    <?php }  ?>

                                                </tr>
                                                <tr>
                                                    <td style="white-space: nowrap" rowspan="1">通过次数</td>
                                                    <?php  foreach($data[$k] as $da){ ?>
                                                        <td style="white-space: nowrap" rowspan="1"><?php echo $da['pass'];?></td>
                                                    <?php }  ?>
                                                </tr>
                                                <tr>
                                                    <td style="white-space: nowrap" rowspan="1">通过率</td>
                                                    <?php  foreach($data[$k] as $da){ ?>
                                                        <td style="white-space: nowrap" rowspan="1"><?php echo $da['pass']/max($da['play'],1);?></td>
                                                    <?php }  ?>
                                                </tr>
                                            <?php }  ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </aside>
                </div>
            </div>
        <?php } ?>
        <?php if($type == 'playSta'){ ?>
            <div class="row">
                <div class="col-sm-12">
                    <aside>
                        <section>
                            <div class="container-fluid">
                                <div class="row">
                                    <div class="table-responsive">
                                        <table class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                                            <thead>
                                            <tr>
                                                <th style="text-align: center;vertical-align: middle;">日期</th>
                                                <?php for($i=1;$i<=9;$i++){ ?>
                                                    <th style="text-align: center;vertical-align: middle;">玩<?php echo $i;?>次的人数</th>
                                                <?php } ?>
                                                <th style="text-align: center;vertical-align: middle;">玩大于10次的人数</th>
                                            </tr>
                                            </thead>
                                            <tbody id="reportBody">
                                            <?php  foreach($dayList as $k => $val){ ?>
                                                <tr>
                                                    <td style="white-space: nowrap" rowspan="1"><?php echo $val;?></td>
                                                    <?php  foreach($data[$k] as $da){ ?>
                                                        <td style="white-space: nowrap" rowspan="1"><?php echo $da;?></td>
                                                    <?php }  ?>
                                                </tr>
                                            <?php }  ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </aside>
                </div>
            </div>
        <?php } ?>



        <?php if(in_array($type,['levelId','playNum','uid'])){ ?>
            <div class="row">
                <div class="col-sm-12">
                    <aside>
                        <?php if($type == 'levelId'){ ?>
                            <header><i class="fa fa-fw fa-file"></i>通关统计</header>
                        <?php } ?>
                        <?php if($type == 'playNum'){ ?>
                            <header><i class="fa fa-fw fa-file"></i>游戏次数统计</header>
                        <?php } ?>

                        <section>
                            <div class="container-fluid">
                                <div class="row">
                                    <div class="col-sm-12">
                                        <div class="table-responsive">
                                            <table id="reportTable" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                                                <thead>
                                                <tr>
                                                    <th>用户ID</th>
                                                    <?php if(in_array($type,['levelId','uid'])){ ?>
                                                        <th>关卡</th>
                                                        <th>获得金币</th>
                                                        <th>获得体力</th>
                                                        <th>获得钻石</th>
                                                        <th>使用钻石数</th>
                                                        <th>复活次数</th>
                                                        <th>游戏时间</th>
                                                    <?php } ?>
                                                </tr>
                                                </thead>
                                                <tbody>

                                                </tbody>
                                            </table>
                                        </div>

                                    </div>
                                </div>
                            </div>
                        </section>
                    </aside>
                </div>
            </div>
        <?php } ?>
    </div>
</div>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<script src="<?php echo base_url();?>public/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="<?php echo base_url();?>public/plugins/datatables/extensions/Responsive/js/dataTables.responsive.min.js"></script>
<script src="<?php echo base_url();?>public/js/common.js?version=1"></script>
<script type="text/javascript">
    $(function () {
        var reportTable = $("#reportTable").DataTable({
            "paging": true,
            "select": true,
            "processing": true,
            "serverSide": true,
            "language": {
                'lengthMenu': '每页显示 _MENU_ 记录',
                'zeroRecords': '没有数据',
                'info': ' 第_PAGE_ 页/ _PAGES_页，共 _TOTAL_ 条',
                'infoEmpty': '没有符合条件的记录',
                'search': '查找',
                'infoFiltered': '(从  _MAX_ 条记录中过滤)',
                'paginate': {"first": "首页 ", "last": "末页", "next": "下一页", "previous": "上一页"}

            },
            "lengthChange": true,
            "searching": false,
            "ordering": false,
            "info": true,
            "autoWidth": false,
            "ajax": {
                url: "/statistics/miningGame/<?php echo $type;?>",
                type: "post",
                data: function (data) {
                    data.uid     = $('input[name="uid"]').val();
                    data.num     = $('input[name="num"]').val();
                    data.levelId = $('input[name="levelId"]').val();
                    data.stime   = $('input[name="stime"]').val();
                    data.etime   = $('input[name="etime"]').val();
                }
            },
            "columns": [
                {"data": "uid"},
                <?php if(in_array($type,['levelId','uid'])){ ?>
                {"data": "levelId"},
                {"data": "coins"},
                {"data": "spins"},
                {"data": "diamond"},
                {"data": "diamondSpend"},
                {"data": "resurrectionNum"},
                {"data": "time",render:function (data) {
                        var time = new Date(parseInt(data) * 1000);
                        var y = time.getFullYear();
                        var m = time.getMonth()+1;
                        var d = time.getDate();
                        var h = time.getHours();
                        var mm = time.getMinutes();
                        var s = time.getSeconds();
                        return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
                }}
                <?php } ?>
            ]
        });
        function add0(m){return m<10?'0'+m:m }
        //当点击search按钮时按条件重新加载数据
        $("#searchBtn").click(function () {
            reportTable.ajax.reload();
        });

    });
    $('.datetimepicker').datepicker({
        language:'zh-CN',
        format:'yyyy-mm-dd',
        zIndexOffset:906  //控制z-index
    });
</script>