<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">
<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>
<div class="content_wrapper">

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-inline" role="form" method="POST" action="#activitysta/rankChart" id="totalForm">
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>活动ID</label>
                                            <input type="text" class="form-control" value="<?php if($aid) echo $aid;?>" placeholder="活动ID" name="aid" />
                                        </div>
                                        <span class="gap"></span>
                                        <button type="submit" class="btn btn-primary">查询</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <a href="#activitysta/rankChart/<?php echo $aid ?? 0;?>" class="btn btn-primary">排名图表展示</a>
                                    <a href="#activitysta/rankTable/<?php echo $aid ?? 0;?>" class="btn btn-primary">排名数据来源</a>
                                    <?php
                                    if($config['type'] == "rank"){
                                        ?>
                                        <a href="#activitysta/speedChart/<?php echo $aid ?? 0;?>/rank" class="btn btn-primary">进度图表展示</a>
                                        <a href="#activitysta/speedTable/<?php echo $aid ?? 0;?>/rank" class="btn btn-primary">进度数据来源</a>
                                        <?php
                                    }
                                    ?>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
        <?php if(empty($config)){
            echo '没有数据';
        }else if($config['type'] != 'rank'){
            echo '不是锦标赛活动';
        }else{ ?>
        <?php foreach($rankData['spinsSet'] as $arrId => $number){
            $arrId = $arrId + 1;
            ?>
            <!--图表-->
            <div class="row">
                <div class="col-sm-12">
                    <aside>
                        <header><i class="fa fa-fw fa-file"></i><?php echo $config['type']?>数据展示<?php echo ">=".$number; ?></header>
                        <section>
                            <div class="container-fluid">
                                <div class="row">
                                    <div id="container<?php echo $arrId; ?>" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
                                </div>
                                <button type="button" class="btn btn-primary" id="all_checked<?php echo $arrId; ?>">全选</button>
                                <button type="button" class="btn btn-primary" id="all_no_checked<?php echo $arrId; ?>">全不选</button>
                                <button type="button" class="btn btn-primary" onclick="initContainer<?php echo $arrId; ?>()">折线图</button>
                                <button type="button" class="btn btn-primary" onclick="initContainer<?php echo $arrId; ?>('column')">柱形图</button>
                            </div>
                        </section>
                    </aside>
                </div>
            </div>
        <?php } } ?>

    </div>

</div>
<script type="text/javascript" src="<?php echo base_url();?>public/js/highcharts/highcharts.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/plugins/validate/jquery.validate-1.15.0.min.js"></script>
<script>
    //选择日期
    $('.datetimepicker').datepicker({
        language:'zh-CN',
        format:'yyyy-mm-dd',
        zIndexOffset:906  //控制z-index
    });

    <?php foreach($rankData['spinsSet'] as $arrId => $number){
    $arrId = $arrId + 1;
        ?>
    var chart<?php echo $arrId; ?> = null;
    initContainer<?php echo $arrId; ?>();
    function initContainer<?php echo $arrId; ?>(type = 'line') {
        chart<?php echo $arrId; ?> = Highcharts.chart('container<?php echo $arrId; ?>', {
            chart: {
                type: type
            },
            title: {
                text: "<?php echo $config['type']?>数据展示<?php echo ">=".$number; ?>"
            },
            subtitle: {
                text: "房间数量<?php echo $rankData['blockData'][$arrId]['roomNumber'] ?? 0; ?>"
            },
            xAxis: [{
                categories: [<?php
                    for($i = 1; $i <= 10; $i++){
                        echo $i.",";
                    }
                    ?>],
                crosshair: true
            }],
            yAxis: [{ // Primary yAxis
                labels: {
                    format: '{value}',
                    style: {
                        color: Highcharts.getOptions().colors[1]
                    }
                },
                title: {
                    text: '数值',
                    style: {
                        color: Highcharts.getOptions().colors[1]
                    }
                }
            }, { // Secondary yAxis
                title: {
                    text: '百分比',
                    style: {
                        color: Highcharts.getOptions().colors[1]
                    }
                },
                labels: {
                    format: '{value} %',
                    style: {
                        color: Highcharts.getOptions().colors[1]
                    }
                },
                opposite: true
            }],
            tooltip: {
                shared: true
            },
            series: [{
                name: '机器人数量',
                data: [<?php
                    for($i = 1; $i <= 10; $i++){
                        echo ($rankData['blockData'][$arrId]['rankingRobot'][$i] ?? 0).",";
                    }
                    ?>],
                tooltip: {
                    valueSuffix: ''
                }
            },{
                name: '玩家数',
                data: [<?php
                    for($i = 1; $i <= 10; $i++){
                        echo ($rankData['blockData'][$arrId]['ranking'][$i] ?? 0).",";
                    }
                    ?>],
                tooltip: {
                    valueSuffix: ''
                }
            },{
                name: '玩家数',
                data: [<?php
                    for($i = 1; $i <= 10; $i++){
                        echo ($rankData['blockData'][$arrId]['ranking'][$i] ?? 0).",";
                    }
                    ?>],
                tooltip: {
                    valueSuffix: ''
                }
            },{
                name: '付费率',
                yAxis: 1,
                data: [<?php
                    for($i = 1; $i <= 10; $i++){
                        echo (empty($rankData['blockData'][$arrId]['ranking'][$i]) ? 0 : number_format($rankData['blockData'][$arrId]['payNum'][$i] / $rankData['blockData'][$arrId]['ranking'][$i] * 100,1,'.','')).",";
                    }
                    ?>],
                tooltip: {
                    valueSuffix: '%'
                }
            },{
                name: 'ARPPU',
                data: [<?php
                    for($i = 1; $i <= 10; $i++){
                        echo (empty($rankData['blockData'][$arrId]['payNum'][$i]) ? 0 : number_format($rankData['blockData'][$arrId]['payTotal'][$i] / $rankData['blockData'][$arrId]['payNum'][$i],1,'.','')).",";
                    }
                    ?>],
                tooltip: {
                    valueSuffix: ''
                }
            },{
                name: 'ARPU',
                data: [<?php
                    for($i = 1; $i <= 10; $i++){
                        echo (empty($rankData['blockData'][$arrId]['ranking'][$i]) ? 0 : number_format($rankData['blockData'][$arrId]['payTotal'][$i] / $rankData['blockData'][$arrId]['ranking'][$i],1,'.','')).",";
                    }
                    ?>],
                tooltip: {
                    valueSuffix: ''
                }
            },{
                name: '活动期间付费总额',
                data: [<?php
                    for($i = 1; $i <= 10; $i++){
                        echo number_format($rankData['blockData'][$arrId]['payTotal'][$i] ?? 0,2,".","").",";
                    }
                    ?>],
                tooltip: {
                    valueSuffix: ''
                }
            }]
        });
    }
    $(document).on("click","#all_checked<?php echo $rid; ?>",function(){
        $(".highcharts-legend-item").each(function(index){
            chart<?php echo $rid; ?>.series[index].show();//显示
        })
    })
    $(document).on("click","#all_no_checked<?php echo $rid; ?>",function(){
        $(".highcharts-legend-item").each(function(index){
            chart<?php echo $rid; ?>.series[index].hide();//隐藏
        })
    })

    <?php } ?>
</script>
