<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>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-inline" role="form" method="POST" action="#statistics/eventReport" name="stanpform">
                                        <input type="hidden" name="moneyinout_post" value="1">
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>开始时间</label>
                                            <input type="text" class="form-control datetimepicker" value="<?php if($stime) echo $stime;?>" placeholder="开始时间" name="moneyinout_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="moneyinout_etime" />
                                        </div>
                                        <button type="submit" class="btn btn-primary">查询</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
            <div class="col-sm-12">
                <aside>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <?php
                                    foreach ($data['event'] as $val) {
                                    	if(in_array($val['event_id'],[10006,10007])){
                                    		echo '<a class="btn btn-success" href="#statistics/eventReport/'.$val['event_id'].'" role="button">'.$val['name'].'</a>';
                                    	}
                                        
                                    }
                                    ?>

                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
			
			
			<?php 
            	if($event_id == '10005'){
            ?>
            <div class="col-sm-12">
                <aside>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <a class="btn btn-success" href="#statistics/eventReport/10005" role="button">全部</a>
									<a class="btn btn-success" href="#statistics/eventReport/10005/2" role="button">FB</a>
									<a class="btn btn-success" href="#statistics/eventReport/10005/3" role="button">游客</a>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
            
            <?php
            	}
            ?>
        </div>
            <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">
                                        <div class="table-responsive">
                                            <table id="reportTable" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                                                <thead>
                                                <tr>
                                                    <!--                                    <th rowspan="2" 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 colspan="12" style="text-align: center;vertical-align: middle;">发放</th>-->
<!--                                                    <th colspan="5" style="text-align: center;vertical-align: middle;">消耗</th>-->
                                                    <!--                                    <th colspan="7" style="text-align: center">其他</th>-->
<!--                                                    <th rowspan="2" style="text-align: center;vertical-align: middle;">单日汇总</th>-->
                                                    <?php
                                                    foreach ($data['title'] as $val) {
                                                            echo '<th style="text-align: center;vertical-align: middle;">'.$val.'</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" style="overflow-y: scroll;">
                                                <?php
                                                if(is_array($data)){
													if($event_id == '10005' && $eveltType == '2'){
                                                		$data['data'] = $data['dataFb'];
                                                	}elseif($event_id == '10005' && $eveltType == '3'){
                                                		$data['data'] = $visitor;
                                                	}
                                                    foreach ($data['data'] as $val) {
                                                        ?>
                                                        <tr style="background-color: rgba(191,255,178,0.39)">
                                                            <?php echo '<td rowspan="2">'.$val['time'].'</td>'; ?>
                                                            <?php echo '<td>流失数值</td>'; ?>
                                                            <?php
                                                                foreach ($data['title'] as $k=>$r) {
                                                                    $temp = ($val['data'][$k+1])??0;
                                                                    echo '<td>'.$temp.'</td>';
                                                                }
                                                            ?>
                                                            <?php
                                                                $temp = (array_sum($val['data']))??0;
                                                                //echo '<td>'.$temp.'</td>';
                                                            ?>
															
															<td rowspan="2"><?php echo $val['reg_total'];?></td>
                                                            <td rowspan="2"><?php echo $val['success_total'];?></td>
															<td rowspan="2"><?php 
																//总通过率
                                                            	$successPercent = round($val['success_total']/$val['reg_total']*100,2);
                                                            	//echo empty($successPercent) || empty($val['success_total'])?0:$successPercent;
																
																//总流失率
																$losePercent = round($val['total']/$val['reg_total']*100,2);
																echo empty($losePercent) || empty($val['total'])?0:$losePercent;
																
                                                            ?>%</td>
                                                        </tr>
                                                        <tr>
                                                            <?php echo '<td>流失比率</td>'; ?>
                                                            <?php
                                                                foreach ($data['title'] as $k=>$r) {
                                                                    $temp = ($val['data'][$k+1])??0;
                                                                    $total = (!empty($val['reg_total']))?intval($val['reg_total']):1;
                                                                    $percent = round($temp/$total*100,2);
                                                                    $str = ($percent != 0)?$percent.'%':0;
                                                                    echo '<td>'.$str.'</td>';
                                                                }
                                                            ?>
                                                            <?php
                                                                $temp = (array_sum($val['data']))??0;
                                                                $total = (!empty($val['total']))?intval($val['total']):1;
                                                                $percent = round($temp/$total*100,2);
                                                                $str = ($percent != 0)?$percent.'%':0;
                                                                //echo '<td>'.$str.'</td>';
                                                            ?>
															
                                                        </tr>
                                                    <?php } } else{?>
                                                    <tr>
                                                        <td colspan="10">暂无数据</td>
                                                    </tr>
                                                <?php } ?>
                                                </tbody>

                                            </table>
                                        </div>

<!--                                        <nav>-->
<!--                                            <ul class="pagination">-->
<!--                                                <li class="disabled"><a href="#">共<span class="pagetotal">--><?php //echo $totalNum;?><!--</span>条</a></li>-->
<!--                                                --><?php //echo $pageurl;?>
<!--                                            </ul>-->
<!--                                        </nav>-->
                                    </div>
                                </div>
                            </div>
                        </section>
                    </aside>
                </div>
            </div>
			
			<!--图表-->
            <?php 
            	if(in_array($event_id,[10006,10007])){
            		
            ?>
            <div class="row">
	            <div class="col-sm-12">
	                <aside>
	                    <header><i class="fa fa-fw fa-file"></i>新手流失事件统计</header>
	                    <section>
	                        <div class="container-fluid">
	                        	<?php
	                        		foreach($data['data'] as $val){
	                        	?>
	                            <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 rowspan="1" width="150" style="text-align: center;vertical-align: middle;"><?php echo $val['time']; ?></th>
	                                            <th colspan="1"  style="text-align: center;vertical-align: middle;"></th>
	                                            <th colspan="1" width="100" style="text-align: center;vertical-align: middle;">流失数值</th>
	                                            <th colspan="1" width="100" style="text-align: center;vertical-align: middle;">流失比率</th>
	                                        </tr>
	                                        
	                                        </thead>
	                                        <tbody id="reportBody">
		                                        <?php
		                                         $length = count($data['title']);
		                                         
		                                         for($i = 1; $i <= $length; $i++){
		                                         	$val['data'][$i] = isset($val['data'][$i])?$val['data'][$i]:0;
		                                         }
		                                         
		                                         ksort($val['data']);
		                                         
		                                         foreach ($data['title'] as $title_k => $title_val) {
		                                         	echo '<tr>';
	                                                echo '<th style="text-align: center;vertical-align: middle;">'.$title_val.'</th>';
	                                                $temp = (array_sum(array_slice($val['data'],$title_k,$length-$title_k)))??0;
                                                    $total = (!empty($val['reg_total']))?intval($val['reg_total']):1;
                                                    $percent = round($temp/$total*100,2);
                                                    $str = ($percent != 0)?$percent.'%':0;
                                                ?>
                                                	<td>
		                                                <div class="progress">
														  <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="<?php echo $percent; ?>" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo $str; ?>;">
														    <?php echo $str; ?>
														  </div>
														</div>
                                                	</td>
                                                <?php 
	                                                echo '<td style="text-align: center;vertical-align: middle;">'.$temp.'</td>';
	                                                echo '<td style="text-align: center;vertical-align: middle;">'.$str.'</td>';
	                                                echo '</tr>';
	                                             }
	                                             
		                                        ?>
		                                        <tr>
		                                        	<th style="text-align: center;vertical-align: middle;">注册总计</th>
		                                        	<td colspan="3" style="text-align: center;vertical-align: middle;"><?php echo $val['reg_total'];?></td>
		                                        </tr>
		                                        <tr>
		                                        	<th style="text-align: center;vertical-align: middle;">通过总计</th>
		                                        	<td colspan="3" style="text-align: center;vertical-align: middle;"><?php echo $val['success_total'];?></td>
		                                        </tr>
		                                        <tr>
		                                        	<th style="text-align: center;vertical-align: middle;">总流失率</th>
		                                        	<td colspan="3" style="text-align: center;vertical-align: middle;">
		                                        	<?php 
		                                        		//总流失率
														$losePercent = round($val['total']/$val['reg_total']*100,2);
														echo empty($losePercent) || empty($val['total'])?0:$losePercent;
		                                        	?>%
		                                        	</td>
		                                        </tr>
	                                        </tbody>
	                                    </table>
	                                </div>
	                            </div>
	                            
	                            <?php } ?>
	                        </div>
	                    </section>
	                </aside>
	            </div>
	        </div>
            
            <?php } ?>
    </div>
</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">
    //选择日期
    $('.datetimepicker').datepicker({
        language:'zh-CN',
        format:'yyyy-mm-dd',
        zIndexOffset:906  //控制z-index
    });
</script>