<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/css/bootstrap-datepicker.standalone.min.css">
<link rel="stylesheet" href="<?php echo base_url();?>public/plugins/datatables/jquery.dataTables.min.css">
<link rel="stylesheet" href="<?php echo base_url();?>public/plugins/datatables/extensions/Responsive/css/dataTables.responsive.css">
<div class="content_wrapper">

    <style>
        .change {
            background: lightgoldenrodyellow;
        }
        .td-nowrap {
            white-space: nowrap;
        }
    </style>

    <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="#statistics/report/" role="button">表格</a>
                            <a style="margin:5px;" class="btn btn-primary " href="#statistics/report/1" role="button">曲线图</a>
                        </div>
                    </div>
                </div>
            </section>
        </aside>
        <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="#" >
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>开始时间</label>
                                            <input type="text" class="form-control datetimepicker" value="" placeholder="开始时间" name="stime" />
                                        </div
                                        <span class="gap"></span>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>结束时间</label>
                                            <input type="text" class="form-control datetimepicker" value="" placeholder="结束时间" name="etime" />
                                        </div>
                                        <span class="gap"></span>
                                        <button type="button" class="btn btn-primary" id="searchBtn">查询</button>
                                        <a href="<?php echo site_url().'/statistics/reportExport'?>" target="_blank" class="btn btn-default pull-right" >导出报表</a>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </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></th>
                                                <th>序号</th>
                                                <th>日期</th>
                                                <th>DAU</th>
                                                <th>新增</th>
                                                <th>广告安装(android)</th>
                                                <th>广告花费(android)</th>
                                                <th>CPI (android)</th>
                                                <th>广告安装(IOS)</th>
                                                <th>广告花费(IOS)</th>
                                                <th>CPI (IOS)</th>
<!--                                                <th>安装(自己)</th>-->
<!--                                                <th>广告花费(自己)</th>-->
<!--                                                <th>CPI (自己)</th>-->
                                                <th>支付人数</th>
                                                <th>收入</th>
                                                <th>付费率</th>
                                                <th>ARPU</th>
                                                <th>ARPPU</th>
<!--                                                <th>ROI (日)</th>-->
<!--                                                <th>ROI (周)</th>-->
<!--                                                <th>ROI (月)</th>-->
                                                <th>自然新增</th>
                                                <th>自然新增率</th>
                                                <th>次日新增留存</th>
                                                <th>次日活跃留存</th>
                                                <th>广告申请次数</th>
                                                <th>广告展示次数</th>
                                                <th>广告成功次数</th>
                                                <th>观看广告人数</th>
                                                <th>人均观看时长</th>
                                                <th>广告展示率</th>
                                                <th>观看成功率</th>
                                                <th>广告观看率</th>
                                                <th>千次广告收入</th>
                                                <th>估算广告收入</th>
                                                <th>单用户花费</th>
                                                <th>人均在线时长</th>
<!--                                                <th>破产率</th>-->
<!--                                                <th>主页赞</th>-->
<!--                                                <th>主页赞花费</th>-->
<!--                                                <th>排名(android)</th>-->
<!--                                                <th>排名(IOS)</th>-->
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>

                                            </tbody>
                                        </table>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>

</div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content" style="min-width:800px;">
            <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>
            <div id="msg-tip"></div>

            <form class="form-horizontal" role="form" method="post" action="#" id="reportForm">
                <input type="hidden" value="" id="reportId" name="id"/>
                <div class="modal-body" style="overflow:auto;">
                    <div class="col-sm-6">

                        <input type="hidden"  name="new_player" >

                        <div class="form-group">
                            <label class="col-sm-3 control-label">广告安装(Android):</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control cpi_android ad_install" placeholder="广告安装(Android)" name="ad_android" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">广告花费(Android):</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control cpi_android ad_expend" placeholder="广告花费(Android)" name="adexpend_android">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">广告安装(IOS):</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control cpi_ios ad_install" placeholder="广告安装(IOS)" name="ad_ios" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">广告花费(IOS):</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control cpi_ios ad_expend" placeholder="广告花费(IOS)" name="adexpend_ios">
                            </div>
                        </div>

<!--                        <div class="form-group">-->
<!--                            <label class="col-sm-3 control-label">自己安装:</label>-->
<!--                            <div class="col-sm-9">-->
<!--                                <input type="text" class="form-control cpi ad_install" placeholder="自己安装" name="install" >-->
<!--                            </div>-->
<!--                        </div>-->
<!--                        <div class="form-group">-->
<!--                            <label class="col-sm-3 control-label">自己广告花费:</label>-->
<!--                            <div class="col-sm-9">-->
<!--                                <input type="text" class="form-control cpi ad_expend" placeholder="自己广告花费" name="expend">-->
<!--                            </div>-->
<!--                        </div>-->

                        <div class="form-group">
                            <label class="col-sm-3 control-label">广告请求次数:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control cpi ad_count" name="ad_apply_count" >
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">广告展示次数:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control cpi ad_count" name="ad_count" >
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">广告完成次数:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="ad_success_count">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">观看广告人数:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control cpi ad_user_num" name="ad_user_num">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">千次广告收入:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control cpi ad_income" name="ad_income">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">估算广告收入:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control cpi ad_estimate_income" name="ad_estimate_income">
                            </div>
                        </div>


<!--                        <div class="form-group">-->
<!--                            <label class="col-sm-3 control-label">主页赞:</label>-->
<!--                            <div class="col-sm-9">-->
<!--                                <input type="text" class="form-control" placeholder="主页赞" name="like_num">-->
<!--                            </div>-->
<!--                        </div>-->
<!--                        <div class="form-group">-->
<!--                            <label class="col-sm-3 control-label">主页花费:</label>-->
<!--                            <div class="col-sm-9">-->
<!--                                <input type="text" class="form-control ad_expend" placeholder="主页花费" name="like_expend">-->
<!--                            </div>-->
<!--                        </div>-->
<!--                        <div class="form-group">-->
<!--                            <label class="col-sm-3 control-label">安卓排名:</label>-->
<!--                            <div class="col-sm-9">-->
<!--                                <input type="text" class="form-control" placeholder="安卓排名" name="rank_android">-->
<!--                            </div>-->
<!--                        </div>-->
<!--                        <div class="form-group">-->
<!--                            <label class="col-sm-3 control-label">苹果排名:</label>-->
<!--                            <div class="col-sm-9">-->
<!--                                <input type="text" class="form-control" placeholder="苹果排名" name="rank_ios">-->
<!--                            </div>-->
<!--                        </div>-->
                    </div>
                    <div class="col-sm-6">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">CPI(Android):</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" readonly placeholder="CPI(Android)" name="cpi_android">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">CPI(IOS):</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" readonly placeholder="CPI(IOS)" name="cpi_ios">
                            </div>
                        </div>
<!--                        <div class="form-group">-->
<!--                            <label class="col-sm-3 control-label">自己CPI:</label>-->
<!--                            <div class="col-sm-9">-->
<!--                                <input type="text" class="form-control" readonly placeholder="自己CPI" name="cpi">-->
<!--                            </div>-->
<!--                        </div>-->
                        <div class="form-group">
                            <label class="col-sm-3 control-label">付费率:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" readonly placeholder="付费率" name="pay_rate">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">ARPU:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" readonly name="arpu">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">ARPPU:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" readonly name="arppu">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">广告展示率:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control cpi ad_success_pro" readonly name="ad_apply_rate">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">广告观看成功率:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control cpi ad_success_pro" readonly name="ad_success_pro">
                            </div>
                        </div>
<!--                        <div class="form-group">-->
<!--                            <label class="col-sm-3 control-label">ROI日:</label>-->
<!--                            <div class="col-sm-9">-->
<!--                                <input type="text" class="form-control" readonly name="roi_day">-->
<!--                            </div>-->
<!--                        </div>-->
<!--                        <div class="form-group">-->
<!--                            <label class="col-sm-3 control-label">ROI周:</label>-->
<!--                            <div class="col-sm-9">-->
<!--                                <input type="text" class="form-control" readonly name="roi_week">-->
<!--                            </div>-->
<!--                        </div>-->
<!--                        <div class="form-group">-->
<!--                            <label class="col-sm-3 control-label">ROI月:</label>-->
<!--                            <div class="col-sm-9">-->
<!--                                <input type="text" class="form-control" readonly name="roi_month">-->
<!--                            </div>-->
<!--                        </div>-->
                        <div class="form-group">
                            <label class="col-sm-3 control-label">自然新增:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" readonly name="net_new_player">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">自然新增率:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" readonly name="net_new_player_rate">
                            </div>
                        </div>
                    </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="submitBtn">提交</button>
                </div>
            </form>

        </div>
    </div>
</div>

<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>
<script src="<?php echo base_url();?>public/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="<?php echo base_url();?>public/plugins/datatables/extensions/Responsive/js/dataTables.responsive.min.js"></script>
<script src="<?php echo base_url();?>public/js/common.js?version=1"></script>
<!--<script src="--><?php //echo base_url();?><!--public/js/statistics/report.js?version=1"></script>-->
<script type="text/javascript">
    //选择日期
    $('.datetimepicker').datepicker({
        language:'zh-CN',
        format:'yyyy-mm-dd',
        zIndexOffset:906  //控制z-index
    });

    $(function () {
        //查询
        //jquery data table 初始化
        var reportTable = $("#reportTable").DataTable({
            "paging": true,
            "select": true,
            "processing": true,
            "serverSide": true,
            "language": {
                'lengthMenu': '每页显示 _MENU_ 记录',
                'zeroRecords': '没有数据',
                'info': ' 第_PAGE_ 页/ _PAGES_页，共 _TOTAL_ 条',
                'infoEmpty': '没有符合条件的记录',
                'search': '查找',
                'infoFiltered': '(从  _MAX_ 条记录中过滤)',
                'paginate': { "first":  "首页 ", "last": "末页", "next": "下一页","previous": "上一页"}

            },
            "ajax": {
                url: rootPath + "statistics/reportData",
                type:"post",
                //增加参数查询参数
                data:function(data){
                    data.stime = $('input[name="stime"]').val();
                    data.etime = $('input[name="etime"]').val();
                }
            },
            "lengthChange": true,
            "searching": false,
            "ordering": false,
            "info": true,
            "autoWidth": false,
            "columns": [
                {"data": "id", class:"hide"},
                {"data": "index", class:"hide"},
                {"data": "date", class:"td-nowrap"},
                {"data": "dau"},
                {"data": "new_player"},
                {"data": "ad_android", class:"ad_android"},
                {"data": "adexpend_android", class:"adexpend_android"},
                {"data": "cpi_android", class:"cpi_android"},
                {"data": "ad_ios",class:"ad_ios"},
                {"data": "adexpend_ios", class:"adexpend_ios"},
                {"data": "cpi_ios", class:"cpi_ios"},
                // {"data": "install", class:"install"},
                // {"data": "expend", class:"expend"},
                // {"data": "cpi", class:"cpi"},
                {"data": "pay_num"},
                {"data": "revenue"},
                {"data": "pay_rate", render:function (data) {
                        return data + '%';
                    }},
                {"data": "arpu"},
                {"data": "arppu"},
                // {"data": "roi_day", render:function (data) {
                //         return data + '%';
                // }},
                // {"data": "roi_week", render:function (data) {
                //         return data + '%';
                // }},
                // {"data": "roi_month", render:function (data) {
                //         return data + '%';
                // }},
                {"data": "net_new_player"},
                {"data": "net_new_player_rate", render:function (data) {
                        return data + '%';
                    }},
                {"data": "remain_new_last", render:function (data) {
                        return data + '%';
                    }},
                {"data": "remain_live_last", render:function (data) {
                        return data + '%';
                    }},
                {"data": "ad_apply_count"},
                {"data": "ad_count"},
                {"data": "ad_success_count"},
                {"data": "ad_user_num"},
                {"data": "ad_user_time"},
                {"data": "ad_apply_rate", render:function (data) {
                        return data + '%';
                }},
                {"data": "ad_success_pro", render:function (data) {
                        return data + '%';
                }},
                {"data": "ad_see_pro", render:function (data) {
                        return data + '%';
                    }},
                {"data": "ad_income"},
                {"data": "ad_estimate_income"},
                {"data": "ad_user_price"},
                {"data": "user_time"},
                // {"data": "broke_rate", render:function (data) {
                //     return data + '%';
                // }},
                // {"data": "like_num", class:"like_num hide"},
                // {"data": "like_expend", class:"like_expend hide"},
                // {"data": "rank_android", class:"rank_android"},
                // {"data": "rank_ios", class:"rank_ios"},
                {"data": "id", render:function (data) {
                        return '<button class="btn btn-primary btn-sm editBtn" data-value="'+data+'">编辑</button>';
                    }}
            ]
        });

        //当点击search按钮时按条件重新加载数据
        $("#searchBtn").click(function(){
            reportTable.ajax.reload();
        });

        //全局变量
        var dau, revenue, payNum, new_player, date;

        $('#reportTable').on('click','.editBtn', function () {
            var parentElement = $(this).parent().parent().children(),
                ad_android = parseInt(parentElement.eq(5).text()),//安卓安装
                adexpend_android = parseFloat(parentElement.eq(6).text()),//安卓广告花费
                ad_ios = parseInt(parentElement.eq(8).text()),//ios安装
                adexpend_ios = parseFloat(parentElement.eq(9).text());//ios广告花费
                // install = parseInt(parentElement.eq(11).text()),//自己安装
                // expend = parseFloat(parentElement.eq(12).text()),//自己安装广告花费
                // like_num = parseInt(parentElement.eq(26).text()),//点赞数
                // like_expend = parseFloat(parentElement.eq(27).text()),//点赞花费
                // rank_android = parseInt(parentElement.eq(28).text()),//安卓排名
                // rank_ios = parseInt(parentElement.eq(29).text());//ios排名
            //全局变量赋值

            date = parentElement.eq(2).text();//日期
            dau = parseInt(parentElement.eq(3).text());//DAU
            new_player = parseInt(parentElement.eq(4).text());//新增
            var pay_rate            = parentElement.eq(13).text();//arpu
            var arpu                = parseFloat(parentElement.eq(14).text());//arpu
            var arppu               = parseFloat(parentElement.eq(15).text())//arppu
            var net_new_player      = parentElement.eq(16).text();
            var net_new_player_rate = parentElement.eq(17).text();
            var ad_apply_count      = parentElement.eq(20).text(); // 广告申请次数
            var ad_count            = parentElement.eq(21).text(); // 广告展示次数
            var ad_success_count    = parentElement.eq(22).text(); // 广告展示次数
            var ad_user_num         = parentElement.eq(23).text(); // 观看广告人数
            var ad_apply_rate       = parentElement.eq(25).text();  // 广告展示率
            var ad_success_pro      = parentElement.eq(26).text(); // 观看成功率
            var ad_income           = parentElement.eq(28).text(); // 观看成功率
            var ad_estimate_income  = parentElement.eq(29).text(); // 观看成功率


            $("#reportId").val($(this).attr('data-value'));//id
            $("input[name='ad_android']").val(ad_android);
            $("input[name='adexpend_android']").val(adexpend_android);
            $("input[name='cpi_android']").val(parentElement.eq(7).text());
            $("input[name='ad_ios']").val(ad_ios);
            $("input[name='adexpend_ios']").val(adexpend_ios);
            $("input[name='cpi_ios']").val(parentElement.eq(10).text());
            $("input[name='pay_rate']").val(pay_rate);
            $("input[name='arpu']").val(arpu);
            $("input[name='arppu']").val(arppu);
            $("input[name='ad_count']").val(ad_count);
            $("input[name='ad_user_num']").val(ad_user_num);
            $("input[name='ad_success_pro']").val(parseInt(ad_success_pro));
            $("input[name='ad_income']").val(parseInt(ad_income));
            $("input[name='ad_estimate_income']").val(parseInt(ad_estimate_income));
            $("input[name='net_new_player']").val(parseInt(net_new_player));
            $("input[name='net_new_player_rate']").val(parseInt(net_new_player_rate));
            $("input[name='ad_apply_count']").val(parseInt(ad_apply_count));
            $("input[name='ad_apply_rate']").val(parseInt(ad_apply_rate));
            $("input[name='new_player']").val(parseInt(new_player));
            $("input[name='ad_success_count']").val(parseInt(ad_success_count));
            // $("input[name='install']").val(install);
            // $("input[name='expend']").val(expend);
            // $("input[name='cpi']").val(parentElement.eq(13).text());
            // $("input[name='like_num']").val(like_num);
            // $("input[name='like_expend']").val(like_expend);
            // $("input[name='rank_android']").val(rank_android);
            // $("input[name='rank_ios']").val(rank_ios);
            //arppu
            //投资回报率计算
            // roiDay();
            //自然新增
            // netNewPlayer();
            cpi_android();
            cpi_ios();
            cpi();

            $('#myModal').modal();
        });


        //当修改cpi_android时
        $('.cpi_android').change(function () {
            cpi_android();
        });
        //当修改cpi_ios时
        $('.cpi_ios').change(function () {
            cpi_ios();
        });
        //当修改cpi_android时
        $('.cpi').change(function () {
            cpi();
        });

        //当修改广告花费时
        $('.ad_expend').change(function () {
            roiDay();
        });

        //当修改安装数时
        $('.ad_install').change(function () {
            netNewPlayer();
        });
		
		//当修改ad_estimate_income 估算广告收入
        $('.ad_estimate_income').change(function () {
            var total = $(this).val();
            var number = $('input[name="ad_count"]').val();
            console.log(total);
            console.log(number);
            if(number != '' && number > 0){
            	
            	$('input[name="ad_income"]').val( (total / (number / 1000)).toFixed(2) );
            }
        });

        //投资回报率
        function roiDay() {
            var adexpend_android = parseFloat($("input[name='adexpend_android']").val()),
                adexpend_ios = parseFloat($("input[name='adexpend_ios']").val()),
                expend = parseFloat($("input[name='expend']").val()),
                like_expend = parseFloat($("input[name='like_expend']").val());
            // console.log("andr:"+adexpend_android+"  ios:"+adexpend_ios+" exp:"+expend+" like:"+like_expend+"  rev:"+revenue);
            var expendTotal = parseFloat(adexpend_android + adexpend_ios + expend + like_expend);
            var roiDay = (expendTotal != 0) ? ((revenue - expendTotal) / expendTotal) * 100 : 0;
            $("input[name='roi_day']").val(roiDay.toFixed(2) + '%');
            if(isWeekEnd(date)) {//如果是周日
                roiWeekMonth(date, revenue, expendTotal, 1);
            }
            if(isMonthEnd(date)) {
                roiWeekMonth(date, revenue, expendTotal, 2);
            }

        }

        //获取周、月数据 flag = 1 是周  flag = 2 是月
        function roiWeekMonth(date, revenue, expendTotal, flag) {
            var re = getReportSumAD(date, flag),
                expendWeek,
                roiWeek,
                revenueWeek;
            if(re['status'] == true) {
                expendWeek = parseFloat(re['expend']) + parseFloat(expendTotal);
                revenueWeek = parseFloat(re['revenue']) + revenue;
                // console.log('weekex:' + expendWeek+" reweek:"+revenueWeek);
                roiWeek = (expendWeek != 0) ? ((revenueWeek - expendWeek) / expendWeek) * 100 : 0;
// console.log("roiweek:"+roiWeek);
                roiWeek = isNaN(roiWeek) ? 0 : roiWeek;
                flag == 2 ? $("input[name='roi_month']").val(roiWeek.toFixed(2) + '%') : $("input[name='roi_week']").val(roiWeek.toFixed(2) + '%');
            }else {
                var msg = flag == 1 ? '周' : '月';
                msgTip.messager().error('获取'+ msg +'数据失败');
            }
        }


//获取这周或者这个月的总额 flag = 1 是周 flag = 2 是月
        function getReportSumAD(date, flag) {
            var result  = [];
            result['status'] = false;
            $.ajax({
                type: 'POST',
                url: rootPath + 'statistics/reportADSumAjax',
                dataType: 'json',
                async: false,
                data: {
                    date: date,
                    flag: flag
                },
                success: function (data) {
                    if(data.ret == 0) {
                        result['status'] = true;
                        result['expend'] = data.data.expend;
                        result['revenue'] = data.data.revenue;
                    }else {
                        result['total'] = 0;
                    }
                },
                error: function () {
                    result['total'] = 0;
                }
            });
            return result;
        }

        //自然新增
        function netNewPlayer() {
            var ad_android = parseInt($("input[name='ad_android']").val()),
                ad_ios = parseInt($("input[name='ad_ios']").val()),
                install = parseInt($("input[name='install']").val());
            var netPlayer = new_player - ad_android - ad_ios - install;
            var netPlayerRate = (netPlayer * 100 / new_player).toFixed(2);
            $("input[name='net_new_player']").val(netPlayer);
            $("input[name='net_new_player_rate']").val(netPlayerRate+'%');
        }

        //安卓的cpi
        function cpi_android() {
            var cpi_android ,
                adexpend_android = $("input[name='adexpend_android']").val(),
                ad_android = $("input[name='ad_android']").val();

            cpi_android = parseInt(ad_android) ? (parseFloat(adexpend_android) / parseInt(ad_android)).toFixed(2) : 0;
            cpi_android = isNaN(cpi_android) ? 0 : cpi_android;
            $("input[name='cpi_android']").val(cpi_android);
        }
        //ios的cpi
        function cpi_ios() {
            var cpi_ios ,
                adexpend_ios = $("input[name='adexpend_ios']").val(),
                ad_ios = $("input[name='ad_ios']").val();
            cpi_ios = parseInt(ad_ios) ? (parseFloat(adexpend_ios) / parseInt(ad_ios)).toFixed(2) : 0;
            cpi_ios = isNaN(cpi_ios) ? 0 : cpi_ios;
            $("input[name='cpi_ios']").val(cpi_ios);
        }
        //自己安装的cpi
        function cpi() {
            var cpi ,
                expend = $("input[name='expend']").val(),
                install = $("input[name='install']").val();
            cpi = parseInt(install) ? (parseFloat(expend) / parseInt(install)).toFixed(2) : 0;
            cpi = isNaN(cpi) ? 0 : cpi;
            $("input[name='cpi']").val(cpi);
        }

        var msgTip = $('#msg-tip');
        $('#submitBtn').click(function () {
            //ajax将修改后的数据提交到后台
            var data = $('#reportForm').serialize();
            $.ajax({
                type: 'POST',
                url: rootPath + 'statistics/editReportAjax',
                dataType: 'json',
                data: data,
                success: function (data) {
                    if(data.ret == 0) {
                        window.location.reload();
                    }else {
                        msgTip.messager().error(data.msg);
                    }
                },
                error: function () {
                    msgTip.messager().error('网络错误，请刷新后重试');
                }
            });
        });

        /**
         //点击表格编辑
         $('#reportTable').on("dblclick","td", function(){
        var _this = $(this),//保存td
            msgTip = $('#msg-tip'),
            tdText = _this.text(),
            cellIndex =  _this[0].cellIndex,
            parentTD,
            editArr = [5,6,7,8,9,10,11,12,13,16,25,26,27,28];

        if($.inArray(cellIndex, editArr) < 0) { //点击这些列不可编辑
            return false;
        }
        //可编辑的列表框设置背景色
        parentTD = $(this).parent();
        $.each(editArr, function (key, value) {
            parentTD.children().eq(value).css('background-color', 'lightgoldenrodyellow');
        });
        // if(parentTD){
        //     parentTD.children().eq(5).css('background','lightgoldenrodyellow');
        // }

        if(!_this.is('.input')){
            var paramName = _this.attr('class');
            _this.addClass('input').html('<input type="text" value="'+ tdText +'" />').find('input').focus().blur(function(){
                var thisid = $(this).parent().siblings("td:eq(0)").text();
                var thisvalue = $(this).val();
                var _input = $(this); //保存input对象

                if(tdText == thisvalue) {
                    _input.parent().removeClass('input').html(tdText || 0);
                    //可编辑的列表框清除背景色
                    // $.each(editArr, function (key, value) {
                    //     parentTD.children().eq(value).css('background-color', '');
                    // });
                    return ;
                }

                //ajax将修改后的数据提交到后台
                $.ajax({
                    type: 'POST',
                    url: rootPath + 'statistics/editReportAjax',
                    dataType: 'json',
                    data: {
                        "id": thisid,
                        "paramName": paramName ,
                        "value": thisvalue
                    },
                    success: function (data) {
                        if(data.ret == 0) {
                            _this.removeClass('text-red');
                            _input.parent().removeClass('input').html(thisvalue || 0);
                            //可编辑的列表框清除背景色
                            // $.each(editArr, function (key, value) {
                            //     parentTD.children().eq(value).css('background-color', '');
                            // });
                            //计算自然新增
                            netNewPlayer(parentTD);
                        }else {
                            msgTip.messager().error(data.msg);
                            _this.addClass('text-red');
                        }
                    },
                    error: function () {
                        msgTip.messager().error('网络错误，请刷新后重试');
                    }
                });

            });
        }
    });


         //自然新增
         function netNewPlayer(parentTD) {
        var newPlayer = parentTD.children().eq(4).text(),//新增
            androidPlayer = parentTD.children().eq(5).text(),
            iosPlayer = parentTD.children().eq(8).text(),
            installPlayer = parentTD.children().eq(11).text(),
            total = 0;
        total = $.parseInt(newPlayer) - $.parseInt(androidPlayer) - $.parseInt(iosPlayer) - $.parseInt(installPlayer);
        parentTD.childrent().eq(21).text(total);
    }
         */



    });

</script>