<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/speedChart" 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>
                                        <input type="hidden" name="actType" value="<?php if($type) echo $type ?? '';?>">
                                        <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/speedChart/<?php echo $aid ?? 0;?>/<?php echo $type; ?>" class="btn btn-primary">进度图表展示</a>
                                    <a href="#activitysta/speedTable/<?php echo $aid ?? 0;?>/<?php echo $type; ?>" class="btn btn-primary">进度数据来源</a>
                                    <?php
                                        if($config['type'] == "rank"){
                                            ?>
                                            <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
                                        }
                                    ?>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
        <?php if(empty($config)){
            echo '没有数据';
        }else if($type && $config['type'] != $type){
            echo '不是'.$type.'活动';
        }else{ ?>
        <?php foreach($retStage['config'] as $rid => $actConfig){ ?>
        <!--图表-->
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i><?php echo $config['type']?>数据展示<?php echo $actConfig['star']."~".$actConfig['end'] ?></header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div id="container<?php echo $rid; ?>" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
                            </div>
                            <button type="button" class="btn btn-primary" id="all_checked<?php echo $rid; ?>">全选</button>
                            <button type="button" class="btn btn-primary" id="all_no_checked<?php echo $rid; ?>">全不选</button>
                            <button type="button" class="btn btn-primary" onclick="initContainer<?php echo $rid; ?>()">折线图</button>
                            <button type="button" class="btn btn-primary" onclick="initContainer<?php echo $rid; ?>('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($retStage['config'] as $rid => $actConfig){ ?>
    var chart<?php echo $rid; ?> = null;
    initContainer<?php echo $rid; ?>();
    function initContainer<?php echo $rid; ?>(type = 'line') {
        chart<?php echo $rid; ?> = Highcharts.chart('container<?php echo $rid; ?>', {
            chart: {
                type: type
            },
            title: {
                text: "<?php echo $config['type']?>数据展示<?php echo $actConfig['star']."~".$actConfig['end'] ?>"
            },
            xAxis: [{
                categories: [<?php
                        foreach($actConfig['list'] as $vo){
                            $stage = $vo['stage'];
                            echo $stage.",";
                        }
                    ?>],
                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
                    foreach($actConfig['list'] as $vo){
                        echo (empty($actStageLog[$rid][$vo['stage']]) ? 0 :$actStageLog[$rid][$vo['stage']]).",";
                    }
                    ?>],
                tooltip: {
                    valueSuffix: ''
                }
            },{
                name: '到达过当前层的人数',
                data: [<?php
                    foreach($actConfig['list'] as $vo){
                        echo (empty($stageSum[$rid][$vo['stage']] ? 0 :$stageSum[$rid][$vo['stage']])).",";
                    }
                    ?>],
                tooltip: {
                    valueSuffix: ''
                }
            },{
                name: '处于当前层付费的人数',
                data: [<?php
                    foreach($actConfig['list'] as $vo){
                        echo ($payNum[$rid][$vo['stage']] ?? 0).",";
                    }
                    ?>],
                tooltip: {
                    valueSuffix: ''
                }
            },{
                name: '当前层通过率',
                yAxis: 1,
                data: [<?php
                    foreach($actConfig['list'] as $vo){
                        echo number_format($passRate[$rid][$vo['stage']] ?? 0,1,".","").",";
                    }
                    ?>],
                tooltip: {
                    valueSuffix: '%'
                }
            },{
                name: '当前层付费率',
                yAxis: 1,
                data: [<?php
                    foreach($actConfig['list'] as $vo){
                        echo ((empty($stageSum[$rid][$vo['stage']]) || empty($payNum[$rid][$vo['stage']])) ? 0 : number_format($payNum[$rid][$vo['stage']] / $stageSum[$rid][$vo['stage']] * 100,1,".","")).",";
                    }
                    ?>],
                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>
