<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 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/launchData" name="stanpform">
                                        <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>
                                        <button type="submit" class="btn btn-primary">查询</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
            
        </div>
        
        <?php
        function formatChipRound($value, $round=2)
        {
            $value = ceil($value);

            if(1 <= abs($valueB = round($value / 1000000000, $round))) {
                return  $valueB . 'B';
            }else if(1 <= abs($valueM=round($value / 1000000, $round))) {
                return $valueM . 'M';
            }else if(1 <= abs($valueK = round($value / 1000), $round)) {
                return $valueK . 'K';
            }else {
                return $value;
            }
        }
        ?>
                                            
		
        <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="btn-group" style="margin-bottom:20px;">
                                    <button type="button" class="btn btn-success" data-toggle="modal" data-target="#actionCode">新建投放数据</button>
                                </div>
                                <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 rowspan="2" style="text-align: center;vertical-align: middle;">渠道</th>
	                                            <?php 
	                                            foreach($addressList as $key => $row){
	                                            	echo '<th colspan="3" style="text-align: center;vertical-align: middle;">'.$row.'</th>';
	                                            }
	                                            ?>
	                                            
	                                            <th rowspan="2" style="text-align: center;vertical-align: middle;">操作</th>
	                                        </tr>
                                        	<tr>
                                        		<?php 
	                                            foreach($addressList as $key => $row){
	                                            	echo '<th style="text-align: center;vertical-align: middle;">投放花费</th>';
	                                            	echo '<th style="text-align: center;vertical-align: middle;">广告新增</th>';
	                                            	echo '<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 rowspan="2" style="text-align: center;white-space: nowrap"><?php echo $val['date'];?></td>
                                                	<td style="text-align: center;white-space: nowrap">Android</td>
                                                	<?php
                                                	foreach($val['data'] as $name => $row){
                                                		echo '<td style="text-align: center;white-space: nowrap">'.$row['android']['pay'].'</td>';
													    echo '<td style="text-align: center;white-space: nowrap">'.$row['android']['new'].'</td>';
													    echo '<td style="text-align: center;white-space: nowrap">'.$row['android']['install'].'</td>';
                                                	}
                                                	?>
                                                	
                                                	<td rowspan="2"><button type="button" class="btn btn-danger" onclick="deleteTask('<?php echo $val['date'];?>')">删除</button></td>
                                                </tr>
                                                <tr>
                                                	<td style="text-align: center;white-space: nowrap">IOS</td>	
                                                	
                                                	<?php
                                                	foreach($val['data'] as $name => $row){
                                                		echo '<td style="text-align: center;white-space: nowrap">'.$row['ios']['pay'].'</td>';
													    echo '<td style="text-align: center;white-space: nowrap">'.$row['ios']['new'].'</td>';
													    echo '<td style="text-align: center;white-space: nowrap">'.$row['ios']['install'].'</td>';
                                                	}
                                                	?>
                                                </tr>
                                                <?php
                                            }
                                         }
                                        ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
        
        
    </div>
</div>

<div class="modal fade" id="actionCode" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">新建投放数据</h4>
            </div>
            <form id="goodForm" class="form-horizontal" role="form" method="post" action="operate/addLaunchData" data-callBack="message" enctype="multipart/form-data">
                <div class="modal-body">
					<div class="form-group">
                        <label class="col-sm-3 control-label">日期:</label>
                        <div class="col-sm-9">
                            <input type="text" name="date"  class="form-control datetimepicker" />
                        </div>
                    </div>
                    <div id="langDiv" >
                        <?php foreach ($addressList as $k=>$v) { ?>
                        
                    		<hr >
                            <div class="form-group">
                                <label class="col-sm-3 control-label"><?php echo $v;?></label>
                                <div class="col-sm-9">
                                	<div class="form-group">
				                        <label class="col-sm-3 control-label">Android投放花费:</label>
				                        <div class="col-sm-9">
				                            <input type="text" name="content[<?php echo $k;?>][android][pay]"  class="form-control" value="0" />
				                        </div>
				                    </div>
				                    <div class="form-group">
				                        <label class="col-sm-3 control-label">Android广告新增:</label>
				                        <div class="col-sm-9"> 
				                            <input type="text" name="content[<?php echo $k;?>][android][new]"  class="form-control" value="0" />
				                        </div>
				                    </div>
				                    <div class="form-group">
				                        <label class="col-sm-3 control-label">Android应用安装:</label>
				                        <div class="col-sm-9">
				                            <input type="text" name="content[<?php echo $k;?>][android][install]"  class="form-control" value="0" />
				                        </div>
				                    </div>
				                    <div class="form-group">
				                        <label class="col-sm-3 control-label">ios投放花费:</label>
				                        <div class="col-sm-9">
				                            <input type="text" name="content[<?php echo $k;?>][ios][pay]"  class="form-control" value="0" />
				                        </div>
				                    </div>
				                    <div class="form-group">
				                        <label class="col-sm-3 control-label">ios广告新增:</label>
				                        <div class="col-sm-9"> 
				                            <input type="text" name="content[<?php echo $k;?>][ios][new]"  class="form-control" value="0" />
				                        </div>
				                    </div>
				                    <div class="form-group">
				                        <label class="col-sm-3 control-label">ios投放花费:</label>
				                        <div class="col-sm-9">
				                            <input type="text" name="content[<?php echo $k;?>][ios][install]"  class="form-control" value="0" />
				                        </div>
				                    </div>
                                </div>
                            </div>
                            
                        <?php }?>
                        
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="submit">提交</button>
                </div>
            </form>
        </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 src="<?php echo base_url();?>public/js/common.js"></script>
<script type="text/javascript">
    //选择日期
    $('.datetimepicker').datepicker({
        language:'zh-CN',
        format:'yyyy-mm-dd',
        zIndexOffset:906  //控制z-index
    });
    
    $("#submit").click(function(){
        var formData = new FormData(document.getElementById("goodForm"));
        // var file = document.getElementById("imgfile").files[0];
        // if(file == "" || file == undefined){
        //     $('#actionCode').modal('hide');
        //     msgTip = $('#msg-tip');
        //     msgTip.messager().warn('请选择图片');
        //     return false;
        // }
        // formData.append("file",file);
        $.ajax({
            type: "POST",
            url: "operate/addLaunchData",
            data: formData,
            async: true,
            processData: false, //
            contentType: false, //
            success: function(data) {
                data = JSON.parse(data);
                if(data.ret == 0){
                    $('#actionCode').modal('hide');
                    msgTip = $('#msg-tip');
                    msgTip.messager().success('操作成功');
                    setTimeout(function () {
                        window.location.reload();
                    },2000)
                }else {
                    msgTip = $('#msg-tip');
                    msgTip.messager().warn('操作失败');
                }
            }
        });
    });
    
    function deleteTask(id) {
        if(confirm('确定要删除吗')==true){
            $.post('/operate/delLaunchData',{
                id:id
            },function (data) {
            	if(data.ret == 0){
            		window.location.reload();
            	}else{
            		msgTip = $('#msg-tip');
                    msgTip.messager().warn('删除失败');
            	}
            },"json");
        }
    }
</script>