<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">
        <!--<aside>-->
        <!--    <header><i class="fa fa-fw fa-file"></i>金币体力来源分布</header>-->
        <!--    <section>-->
        <!--        <div class="container-fluid">-->
        <!--            <div class="row">-->
        <!--                <div class="col-sm-12">-->
        <!--                    <a style="margin:5px;" class="btn btn-primary " href="#abnormal/moneySpinsSource/<?php echo $uid;?>/money" role="button">金币</a>-->
        <!--                    <a style="margin:5px;" class="btn btn-primary " href="#abnormal/moneySpinsSource/<?php echo $uid;?>/spins" role="button">体力</a>-->
        <!--                </div>-->
        <!--            </div>-->
        <!--        </div>-->
        <!--    </section>-->
        <!--</aside>-->
        <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="/#abnormal/moneySpinsSource">
                                        <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="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>
                                        <span class="gap"></span>
                                        
                                        <div class="form-group">
                                            <label>查询玩家:</label>
                                            
                                            <input type="text" class="form-control" value="<?php if($uid) echo $uid;?>" placeholder="uid" name="uid" />
                                        </div>
                                        <span class="gap"></span>
                                        <button type="submit" class="btn btn-primary" id="query">查询</button>
                                        <span class="gap"></span>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
        <div class="row">
 
            <div class="col-sm-6">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>金币来源分布 总计</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div id="containerMoney" style="min-width: 310px; height: 600px; margin: 0 auto"></div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
            
            <div class="col-sm-6">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>体力来源分布 总计</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div id="containerSpins" style="min-width: 310px; height: 600px; margin: 0 auto"></div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
			
			<div class="col-sm-6">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>金币来源分布 单天</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div id="containerMoneyDay" style="min-width: 310px; height: 600px; margin: 0 auto"></div>
                            </div>
                            <button type="button" class="btn btn-primary" id="all_checked1">全选</button>
                            <button type="button" class="btn btn-primary" id="all_no_checked1">全不选</button>
                        </div>
                    </section>
                </aside>
            </div>
            
            <div class="col-sm-6">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>体力来源分布 单天</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div id="containerSpinsDay" style="min-width: 310px; height: 600px; margin: 0 auto"></div>
                            </div>
                            <button type="button" class="btn btn-primary" id="all_checked2">全选</button>
                            <button type="button" class="btn btn-primary" id="all_no_checked2">全不选</button>
                        </div>
                    </section>
                </aside>
            </div>
        </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
    });
	
	
	$(document).on("click","#query",function(){
		var uid = $("input[name='uid']").val();
		location.href = "#abnormal/moneySpinsSource/"+uid;
	})
	
	// 构建图表
	var chartSum = Highcharts.chart('containerMoney',{
		title: {
			text: '金币来源总值<?php echo array_sum($money['addData']);?>'
		},
		tooltip: {
			pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
		},
		plotOptions: {
			pie: {
				allowPointSelect: true,
				cursor: 'pointer',
				dataLabels: {
					enabled: true,
					format: '<b>{point.name}</b>: {point.percentage:.1f} %',
					style: {
						color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
					},
					connectorColor: 'silver'
				}
			}
		},
		series: [{
			type: 'pie',
			name: '占比',
			data: [
				<?php
					foreach($money['addData'] as $p_k => $p_v){
				?>
				{
					name: '<?php echo $money['addType'][$p_k]; ?>',
					sliced: true,
					selected: true,
					y:<?php echo ($p_v / array_sum($money['addData'])); ?>
				},
				<?php
					}
				?>
			]
		}]
	});
	
	// 构建图表
	var chartSum = Highcharts.chart('containerSpins',{
		title: {
			text: '体力来源总值<?php echo array_sum($spins['addData']);?>'
		},
		tooltip: {
			pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
		},
		plotOptions: {
			pie: {
				allowPointSelect: true,
				cursor: 'pointer',
				dataLabels: {
					enabled: true,
					format: '<b>{point.name}</b>: {point.percentage:.1f} %',
					style: {
						color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
					},
					connectorColor: 'silver'
				}
			}
		},
		series: [{
			type: 'pie',
			name: '占比',
			data: [
				<?php
					foreach($spins['addData'] as $p_k => $p_v){
				?>
				{
					name: '<?php echo $spins['addType'][$p_k]; ?>',
					sliced: true,
					selected: true,
					y:<?php echo ($p_v / array_sum($spins['addData'])); ?>
				},
				<?php
					}
				?>
			]
		}]
	});
	
	var chart1 = Highcharts.chart('containerMoneyDay', {
        chart: {
            type: 'column'
        },
        title: {
            text: ''
        },
        xAxis: {
            categories: [<?php 
            	foreach($money['addDataDay'] as $k => $v){
            		echo $k.",";
            	}
            ?>]
        },
        yAxis: {
            allowDecimals: false,
            min: 0,
            title: {
                text: '数量'
            }
        },
        tooltip: {
            formatter: function () {
                return '<br/>' +
                    this.series.name + ': ' + this.y + '<br/>' +
                    '总量: ' + this.point.stackTotal;
            }
        },
        plotOptions: {
            column: {
                stacking: 'normal'
            }
        },
        series: [<?php foreach ($money['addType'] as $k => $v){
        		
        	?>
            {
                name: '<?php echo $v;?>',
                data: [<?php 
                	foreach($money['addDataDay'] as $d_k => $d_v){
                		if(isset($d_v[$k])){
                			echo $d_v[$k].",";
                		}else{
                			echo "0,";
                		}
                	}
                ?>],
                stack: '来源' // stack 值相同的为同一组
            },
            <?php 
        		}
        	?>
        	<?php foreach ($money['lowType'] as $k => $v){
        		
        	?>
            {
                name: '<?php echo $v;?>',
                data: [<?php 
                	foreach($money['lowDataDay'] as $d_k => $d_v){
                		if(isset($d_v[$k])){
                			echo $d_v[$k].",";
                		}else{
                			echo "0,";
                		}
                	}
                ?>],
                stack: '消耗' // stack 值相同的为同一组
            },
            <?php 
        		}
        	?>
        ]
    });
    
    var chart2 = Highcharts.chart('containerSpinsDay', {
        chart: {
            type: 'column'
        },
        title: {
            text: ''
        },
        xAxis: {
            categories: [<?php 
            	foreach($spins['addDataDay'] as $k => $v){
            		echo $k.",";
            	}
            ?>]
        },
        yAxis: {
            allowDecimals: false,
            min: 0,
            title: {
                text: '数量'
            }
        },
        tooltip: {
            formatter: function () {
                return '<br/>' +
                    this.series.name + ': ' + this.y + '<br/>' +
                    '总量: ' + this.point.stackTotal;
            }
        },
        plotOptions: {
            column: {
                stacking: 'normal'
            }
        },
        series: [<?php foreach ($spins['addType'] as $k => $v){
        		
        	?>
            {
                name: '<?php echo $v;?>',
                data: [<?php 
                	foreach($spins['addDataDay'] as $d_k => $d_v){
                		if(isset($d_v[$k])){
                			echo $d_v[$k].",";
                		}else{
                			echo "0,";
                		}
                	}
                ?>],
                stack: '来源' // stack 值相同的为同一组
            },
            <?php 
        		}
        	?>
        	<?php foreach ($spins['lowType'] as $k => $v){
        		
        	?>
            {
                name: '<?php echo $v;?>',
                data: [<?php 
                	foreach($spins['lowDataDay'] as $d_k => $d_v){
                		if(isset($d_v[$k])){
                			echo $d_v[$k].",";
                		}else{
                			echo "0,";
                		}
                	}
                ?>],
                stack: '消耗' // stack 值相同的为同一组
            },
            <?php 
        		}
        	?>
        ]
    });
    
    $(document).on("click","#all_checked1",function(){
    	$(".highcharts-legend-item").each(function(index){
    		chart1.series[index].show();//显示
    	})
    })
    $(document).on("click","#all_no_checked1",function(){
    	$(".highcharts-legend-item").each(function(index){
    		chart1.series[index].hide();//隐藏
    	})
    })
    $(document).on("click","#all_checked2",function(){
    	$(".highcharts-legend-item").each(function(index){
    		chart2.series[index].show();//显示
    	})
    })
    $(document).on("click","#all_no_checked2",function(){
    	$(".highcharts-legend-item").each(function(index){
    		chart2.series[index].hide();//隐藏
    	})
    })
</script>