<style type="text/css">
  .canedit{
    color: red;
    font-size: 5px;
  }
</style>
<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">
                                    <button type="button" class="btn btn-primary" data-toggle="modal" data-target=".addadvertiser">添加广告商</button>
                                    <button type="button" class="btn btn-success" data-toggle="modal" data-target=".adddailydata">添加每日广告数据</button>
                                </div>
                            </div>
                        </div>
                    </section>
                    
                    <!-- <section style="margin-top: 10px;">
                      <div class="container-fluid">
                        <div class="row">
                          <div class="col-sm-12">
                            <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
                          </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">
                  <form class="form-inline" role="form" method="POST" action="#advertiser/index" name="adinfo">
                      <div class="form-group">
                              <label>开始时间</label>
                              <input type="text" class="form-control datetimepicker" value="<?php echo $stime;?>" placeholder="开始时间" name="ad_start_time" />
                      </div>
                      <span class="gap"></span>
                      <div class="form-group">
                              <label>结束时间</label>
                              <input type="text" class="form-control datetimepicker" value="<?php echo $etime;?>" placeholder="结束时间" name="ad_end_time" />
                      </div>
                      <span class="gap"></span>
                      <div class="form-group">
                          <label>广告商</label>
                          <span class="gap"></span>
                          <?php foreach($adList as $adinfo){?>
                            <label class="checkbox-inline">
                              <input <?php if(in_array($adinfo['id'], $click_adList) ){ echo "checked";}?> type="checkbox" name="adname[]" value="<?php echo $adinfo['id'];?>"><?php echo $adinfo['ad_name'];?>
                            </label>
                          <?php } ?>
                      </div>
                      <span class="gap"></span>
                      <button type="submit" class="btn btn-primary">查询</button>
                  </form>
                </div>
              </section>
            </aside>
          </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <section>
                        <div class="table-responsive">
                          <table class="table table-striped table-bordered table-hover">
                            <thead>
                              <tr>
                                <th>广告商</th>
                                <th>平台</th>
                                <th>安装量<span class="canedit">(双击可编辑)</span></th>
                                <th>收入<span class="canedit">(双击可编辑)</th>
                                <th>花费<span class="canedit">(双击可编辑)</th>
                                <th>当日ROI</th>
                                <th>7日ROI</th>
                                <th>CPI</th>
                                <th>留存<span class="canedit">(双击可编辑)</th>
                                <th>自然新增留存<span class="canedit">(双击可编辑)</th>
                                <th>时间</th>
                                <th>操作</th>
                              </tr>
                            </thead>
                            <tbody>
                              <?php foreach ($adInfoList as $val) {?>
                              <tr colid='<?php echo $val['id'];?>'>
                                <td><?php echo $val['ad_name'];?></td>
                                <td><?php echo $platform[$val['ad_platform']];?></td>
                                <td class="changeinput" colname='ad_num'><?php echo $val['ad_num'];?></td>
                                <td class="changeinput" colname='ad_income'><?php echo $val['ad_income'];?></td>
                                <td class="changeinput" colname='ad_money'><?php echo $val['ad_money'];?></td>
                                <td><?php echo round(($val['ad_income']-$val['ad_money'])/$val['ad_money'], 4);?></td>
                                <td><?php echo $val['roi7day'];?></td>
                                <td><?php echo round($val['ad_money']/$val['ad_num'], 4);?></td>
                                <td class="changeinput" colname='ad_install_lc'><?php echo $val['ad_install_lc'];?></td>
                                <td class="changeinput" colname='ad_zr_lc'><?php echo $val['ad_zr_lc'];?></td>
                                <td><?php echo date('Y-m-d H:i:s', $val['ad_time']);?></td>
                                <td><button adid="<?php echo $val['id'];?>" type="button" class="btn btn-danger delad">删除</button></td>
                              </tr>
                              <?php } ?>
                              <tr>
                                <td><b>汇总:</b></td>
                                <td><b>广告安装:</b></td>
                                <td><?php echo $adInstall;?></td>
                                <td><b>广告花费:</b></td>
                                <td colspan="8"><?php echo $adMoney;?></td>
                              </tr>
                            </tbody>
                          </table> 
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>

</div>

<div class="modal fade addadvertiser" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">添加广告商</h4>
      </div>
    <form action="<?php echo base_url('advertiser/addadver');?>" method="post" class="form-horizontal" data-sendingText="提交中">
      <div class="modal-body">
          <div class="form-group">
            <label for="message-text" class="col-sm-3 control-label">广告商名称:</label>
            <div class="col-sm-9">
                <label class="input-inline">
                    <input type="text" class="form-control" name="adname">
                </label>
            </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 J_ajaxSubmitBtn">提交</button>
      </div>
    </form>
    </div>
  </div>
</div>

<div class="modal fade adddailydata" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">添加广告商数据</h4>
      </div>
    <form action="<?php echo base_url('advertiser/addInfo');?>" method="post" class="form-horizontal" data-sendingText="提交中">
      <div class="modal-body">
          <div class="form-group">
            <label for="message-text" class="col-sm-3 control-label">广告商名称:</label>
            <div class="col-sm-9">
                <label class="select-inline">
                    <select class="form-control" name="ad_id">
                    <?php foreach($adList as $adinfo){?>
                      <option value="<?php echo $adinfo['id'];?>"><?php echo $adinfo['ad_name'];?></option>
                    <?php } ?>
                    </select>
                </label>
            </div>
          </div>
          <div class="form-group">
            <label for="message-text" class="col-sm-3 control-label">安装量:</label>
            <div class="col-sm-9">
                <label class="input-inline">
                    <input type="text" class="form-control" name="ad_num">
                </label>
            </div>
          </div>
          <div class="form-group">
            <label for="message-text" class="col-sm-3 control-label">收入:</label>
            <div class="col-sm-9">
                <label class="input-inline">
                    <input type="text" class="form-control" name="ad_income">
                </label>
            </div>
          </div>
          <div class="form-group">
            <label for="message-text" class="col-sm-3 control-label">花费:</label>
            <div class="col-sm-9">
                <label class="input-inline">
                    <input type="text" class="form-control" name="ad_money">
                </label>
            </div>
          </div>
          <div class="form-group">
            <label for="message-text" class="col-sm-3 control-label">留存:</label>
            <div class="col-sm-9">
                <label class="input-inline">
                    <input type="text" class="form-control" name="ad_install_lc">
                </label>
            </div>
          </div>
          <div class="form-group">
            <label for="message-text" class="col-sm-3 control-label">自然新增留存:</label>
            <div class="col-sm-9">
                <label class="input-inline">
                    <input type="text" class="form-control" name="ad_zr_lc">
                </label>
            </div>
          </div>
          <div class="form-group">
            <label for="message-text" class="col-sm-3 control-label">投放平台:</label>
            <div class="col-sm-9">
                <label class="input-inline">
                    <select class="form-control" name="ad_platform">
                    <?php foreach($platform as $k => $v){?>
                      <option value="<?php echo $k;?>"><?php echo $v;?></option>
                    <?php } ?>
                    </select>
                </label>
            </div>
          </div>
          <div class="form-group">
            <label for="message-text" class="col-sm-3 control-label">时间:</label>
            <div class="col-sm-5">
                <input type="text" class="form-control datetimepicker" value="" placeholder="记录时间" name="ad_time" />
            </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 J_ajaxSubmitBtn">提交</button>
      </div>
    </form>
    </div>
  </div>
</div>
<script>
    //选择日期
    $('.datetimepicker').datepicker({
        language:'zh-CN',
        format:'yyyy-mm-dd',
        zIndexOffset:906  //控制z-index
    });

    //变input框
    $('.changeinput').dblclick(function(){
      var colId = $(this).parent().attr('colid');
      var colName = $(this).attr('colname');

      var td = $(this);
      var tbVal = td.text();
      var txt = $("<input type='text'>").val(tbVal);
      txt.blur(function(){
          var newText = $(this).val();
          $.post(
            "<?php echo base_url('advertiser/ajaxEdit');?>",
            {adid:colId, colname:colName, val:newText}
          );
          // 移除文本框,显示新值
          $(this).remove();
          td.text(newText);
      });
      td.text("");
      td.append(txt);

    });

    //删除操作
    $('.delad').click(function(){
      if (confirm('确定删除吗?') == true) {
       var adId = $(this).attr('adid');
       $.post(
            "<?php echo base_url('advertiser/delAd');?>",
            {adid:adId},
          );
       alert('删除成功');
       $(this).parent().parent().remove();
       //window.location.reload();
      }
    });
</script>