<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>
<style>
	.today-size{
		font-size: 20px;
	}
	.today-size-title{
		font-size: 20px;
	}
</style>
<div class="content_wrapper">
	<div id="msg-tip"></div>
    <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="#operate/dailyList" name="stanpform">
                                    	<span class="gap"></span>
                                        
                                        <div class="form-group">
                                                <label>渠道</label>
                                                <select name="channel" class="form-control">
                                                	<option value="all">所有</option>
                                                	<option value="Android" <?php echo $channel == "Android"?"selected":""; ?>>Android</option>
                                                	<option value="IOS" <?php echo $channel == "IOS"?"selected":""; ?>>IOS</option>
                                                </select>
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                                <label>选择日期</label>
                                                <input type="text" class="form-control datetimepicker" value="<?php if($date) echo $date;?>" placeholder="开始时间" name="date" />
                                        </div>
                                        
                                        <button type="submit" class="btn btn-primary">查询</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
		<div class="btn-group" style="margin-bottom:20px;">
                            	<button type="button" style="width: 80px;" class="btn btn-danger" disabled id="commitBtn">提交</button>
                        	</div>
                        	<br>
        <div class="row">
            <div class="col-sm-12">
                <div class="table-responsive">
                    <table id="roleTable" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                    	<thead>
							<tr>
								<th>日期</th>
								<th>地区</th>
								<th>新增用户</th>
								<th>活跃用户</th>
								<th>内购流水</th>
								<th>广告流水</th>
								<th>付费人数</th>
								<th>付费率</th>
								<th>ARPU</th>
								<th>ARPPU</th>
								<th>市场花费</th>
								<th>GG下载排名</th>
								<th>GG畅销排名</th>
								<th>IOS下载排名</th>
								<th>IOS畅销排名</th>
							</tr>
						</thead>
						<tbody>
						<?php 
							foreach($addressList as $address => $name){
								echo '<tr>';
								echo '<td>'.$date.'</td>';
								echo '<td>'.$name.'</td>';
								echo '<td>'.$data[$name]['newplayer'].'</td>';
								echo '<td>'.$data[$name]['loginplayer'].'</td>';
								echo '<td>'.$data[$name]['gamesIncome'].'</td>';
								echo '<td>'.$data[$name]['advertIncome'].'</td>';
								echo '<td>'.$data[$name]['payNumber'].'</td>';
								echo '<td>'.$data[$name]['payRate'].'</td>';
								echo '<td>'.$data[$name]['ARPU'].'</td>';
								echo '<td>'.$data[$name]['ARPPU'].'</td>';
								echo '<td>'.$data[$name]['launchPay'].'</td>';
								echo '<td>'.$data[$name]['gg_download'].'</td>';
								echo '<td>'.$data[$name]['gg_seller'].'</td>';
								echo '<td>'.$data[$name]['ios_download'].'</td>';
								echo '<td>'.$data[$name]['ios_seller'].'</td>';
								echo '</tr>';
							}
						?>
						</tbody>
                    </table>
                </div>
            </div>                    
        </div>
        
        
        
    </div>
</div>
<!--<script type="text/javascript" src="--><?php //echo base_url().'public/js/chart/chart.js';?><!--"></script>-->
<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
    });
	
	$('#roleTable').on('dblclick','td',function(){
        var _this = $(this),//保存td
            tdText = _this.text();
        var  cellIndex =  _this[0].cellIndex;
        if(cellIndex == 0) {return false;} //点击操作列不可编辑
        if(cellIndex != 11 && cellIndex != 12 && cellIndex != 13 && cellIndex != 14){
        	//下拉框
        	return false;
        }
        if(!_this.is('.input')){
            _this.addClass('input').html('<input type="text" value="'+ tdText +'" />').find('input').focus().blur(function(){
                var _input = $(this); //保存input对象
                var thisvalue = $(this).val();
                
                _input.parent().removeClass('input').html(thisvalue || '');
                
                if($('#commitBtn').prop('disabled')){
                    $('#commitBtn').attr('disabled', false);
                }
            });
        }

    });
    
    //提交表格数据
    $('#commitBtn').click(function () {
        var tableContent = $('#roleTable').html(),
            msgTip = $('#msg-tip');
        //如果还有添加未编辑的，则不能提交
        if($('#roleTable td').hasClass('input')){
            msgTip.messager().warn('列表中还有未编辑的');
            return;
        }

        var tr = $('#roleTable tr');
        var arr = [];
        for (var i = 1; i < tr.length; i++) {
            var tempData = {};
            var arrayTemp ={};
            td = $(tr[i]).find('td');
            for (var j = 0; j < td.length; j++) {
                switch (j) {
                    case 0:
                        tempData['date'] = $(td[j]).html();
                    break;
                    case 1:
                        tempData['address'] = $(td[j]).html();
                    break;
                    case 11:
                        arrayTemp['gg_download'] = $(td[j]).html();
                        break;
                    case 12:
                        arrayTemp['gg_seller'] = $(td[j]).html();
                        break;
                    case 13:
                        arrayTemp['ios_download'] = $(td[j]).html();
                        break;
                    case 14:
                        arrayTemp['ios_seller'] = $(td[j]).html();
                        break;
                }
            }
            tempData['data'] = arrayTemp;
            arr.push(tempData)
        }

        $.ajaxSetup({
            async: true
        });


        $.ajax({
            type: 'POST',
            dataType: 'json',
            data:{
                data: JSON.stringify(arr)
            },
            url:'operate/editDailyList',
            success: function(data){
                if(data.ret == 0){
                    window.location.reload()
                    $('#commitBtn').attr('disabled', true);
                }else{
                    msgTip.messager().error(data.msg);
                }
            }
        });
    });
</script>