<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/css/bootstrap-datepicker.standalone.min.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>
                    <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/trafficPermitSta/<?php echo $type;?>" name="stanpform">
                                        <input type="hidden" name="fromsta_traffic" value="1">
                                        <span class="gap"></span>
                                        <?php if($type == 'task'){ ?>
                                            <div class="form-group">
                                                <select class="form-control" name="taskId">
                                                    <?php foreach($taskArr as $k => $val){ ?>
                                                        <option <?php if($taskId == $k) echo 'selected';?> value="<?php echo $k;?>"><?php echo $val;?></option>
                                                    <?php } ?>
                                                </select>
                                            </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>
                                        <button type="submit" class="btn btn-primary">查询</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>

        <?php if($type == 'table'){ ?>
            <div class="row">
                <div class="col-sm-12">
                    <aside>
                        <section>
                            <div class="container-fluid">
                                <div class="row">
                                    <div class="table-responsive">
                                        <table id="reportTable" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                                            <thead>
                                            <tr>
                                                <th style="text-align: center;vertical-align: middle;">任务ID</th>
                                                <th style="text-align: center;vertical-align: middle;">达标人数</th>
                                                <th style="text-align: center;vertical-align: middle;">总完成次数</th>
                                                <th style="text-align: center;vertical-align: middle;">通行证完成次数</th>
                                                <th style="text-align: center;vertical-align: middle;">免费完成次数</th>
                                                <th style="text-align: center;vertical-align: middle;">平均完成次数</th>
                                            </tr>

                                            </thead>
                                            <tbody id="reportBody">
                                            <?php if(is_array($data)){ foreach($data as $k => $val){ ?>
                                                <tr>
                                                    <td style="white-space: nowrap" rowspan="1"><?php echo $val['name'];?></td>
                                                    <td style="white-space: nowrap" rowspan="1"><?php echo $val['standard'];?></td>
                                                    <td style="white-space: nowrap" rowspan="1"><?php echo $val['complete_1'] + $val['complete_2'];?></td>
                                                    <td style="white-space: nowrap" rowspan="1"><?php echo $val['complete_1'];?></td>
                                                    <td style="white-space: nowrap" rowspan="1"><?php echo $val['complete_2'];?></td>
                                                    <td style="white-space: nowrap" rowspan="1"><?php echo $val['completePro'];?></td>
                                                </tr>
                                            <?php } } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </aside>
                </div>
            </div>
        <?php }else{ ?>
            <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 id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
                                </div>
                            </div>
                        </section>
                    </aside>
                </div>
            </div>
        <?php } ?>
    </div>
</div>
<script type="text/javascript" src="<?php echo base_url();?>public/js/highcharts/highcharts.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>public/js/highcharts/modules/exporting.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>public/js/highcharts/modules/export-data.js"></script>
<script type="text/javascript">
    //设置图表导出格式选项
    Highcharts.setOptions({
        lang: {
            printChart: '打印图表',
            downloadJPEG: '下载 JPEG 文件',
            downloadPDF: '下载 PDF   文件',
            downloadPNG: '下载 PNG  文件',
            downloadSVG: '下载 SVG  文件',
            downloadCSV: '下载 CSV  文件',
            downloadXLS: '下载 XLS   文件',
            viewData: '查看数据表格'
        },
        navigation: {
            menuItemStyle: {
                padding: '6px 14px'
            }
        },
        exporting: {
            url: ''
        },
        credits: {
            text: '',
            url: ''
        }
    });

    Highcharts.chart('container', {
        chart: {
            type: 'line'
        },
        title: {
            text: ''
        },
        subtitle: {
            text: ''
        },
        xAxis: {
            categories: [<?php echo "'".implode("','", $dayList)."'";?>]
        },
        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
        }],
        plotOptions: {
            line: {
                dataLabels: {
                    enabled: true
                },
                enableMouseTracking: false
            }
        },

        <?php if($type == 'buy'){ ?>
            series: [{
                name: '购买量',
                data: [<?php echo implode(",", $data['buyNum']);?>]
            },{
                name: '购买率',
                data: [<?php echo implode(",", $data['buyPro']);?>]
            }]
        <?php }else if($type == 'task'){ ?>
            series: [{
                name: '达标人数',
                data: [<?php echo implode(",", $data['standard']);?>]
            },{
                name: '总完成次数',
                data: [<?php echo implode(",", $data['complete']);?>]
            },{
                name: '平均每人控制次数',
                data: [<?php echo implode(",", $data['completePro']);?>]
            }]
        <?php }else if($type == 'props'){ ?>
            series: [<?php foreach($data as $k => $val){ ?>{
                    name: '<?php echo $val['name'];?>',
                    data: [<?php echo implode(",", $val['normal']);?>]
                },<?php }?><?php foreach($data as $k => $val){ ?>{
                    name: '<?php echo $val['name'];?>',
                    data: [<?php echo implode(",", $val['special']);?>],
                    dataStyle:"dash"
                },<?php }?>]
        <?php }else if($type == 'level'){ ?>
            series: [{
                name: '在该等级购买通信证人数',
                data: [<?php echo implode(",", array_column($data,'buyTrafficPermitNum'));?>]
            },{
                name: '该等级玩家数量',
                data: [<?php echo implode(",", array_column($data,'playerNum'));?>]
            },{
                name: '在该等级购买等级玩家数量',
                data: [<?php echo implode(",", array_column($data,'buyLevelNum'));?>]
            }]
        <?php }?>

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