<extend name="Public/head-foot-new" />
<block name="body">
	<link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />
	<script type="text/javascript" src="__JS__/select2.min.js"></script>

	<!--内容start-->
	<div class="page-search normal_list query-register-search jssearch">
		<div class="trunk-title">
			<div class="location">
				<div class="location-container">当前位置:<span>数据汇总</span></div>
			</div>
			<img src="__IMG__/icon_normal_ARPU.png">
			<span class="title_main">数据汇总</span>
      <span style="font-size:13px;font-weight: normal;margin-left: 10px">说明:默认展示当前商务专员下所有一级渠道的全部数据</span>
		</div>

		<div class="trunk-content article">
			<div class="trunk-search clearfix">
				 <!--  <form action="{:U('Query/summary')}" method="get" enctype="multipart/form-data" class="normal_form"> -->
              <div class="form-group normal_space fr">
                <input type="submit" class="submit" id='submit'  url="{:U('Buydetail/summary','model='.$model['name'],false)}" value="查询">
              </div>

              <div class="form-group normal_space fr">
                <div class="select-time">
                  <input type="text" id="sdate" class="txt" name="begtime" placeholder="开始时间" value="{:I('begtime')}" >
                </div>
                <label class="form-title select-title zhi_color">&nbsp;—&nbsp;</label>
                <div class="select-time">
                  <input type="text" id="edate" class="txt" name="endtime" placeholder="结束时间" value="{:I('endtime')}">
                </div>
              </div>

           
               <div class="form-group normal_space fr">
                    <select id="promote_account" name="promote_account" class="reselect select_gallery" style="min-width:130px;">
                         <option  value="" >请选择推广员账号</option>
	                    <volist name=":get_map_promote_list($uid)" id="vo">
	                        <option value="{$vo.id}" <if condition="I('promote_account') eq $vo['id']" > selected="true" </if> > {$vo.account}</option>
	                    </volist>
                    </select>
              </div>
                <div class="form-group normal_space fr">
                    <select id="promote_id" name="promote_id" class="reselect select_gallery" style="min-width:130px;">
                       <option  value="" >请选择推广员ID</option>
	                    <volist name=":get_map_promote_list($uid)" id="vo">
	                        <option value="{$vo.id}" <if condition="I('promote_id') eq $vo['id']" > selected="true" </if> > {$vo.id}</option>
	                    </volist>
                    </select>
              </div>
               <div class="form-group normal_space fr">
                   <select id="game_level" name="game_level" class=" reselect select_gallery" >
                  <empty name="game_list">
                        <option value="" id="game_data" selected="true">暂无游戏等级</option>
                      <else/>
                           <option value="" selected="true">请选择游戏等级</option>
                    </empty>
                  </select>
              </div>
               <div class="form-group normal_space fr">
                   <select id="server_name" name="server_name" class=" reselect select_gallery" >
                      <empty name="game_list">
                         <option value="" id="game_data" selected="true">暂无游戏区服</option>
                      <else/>
                            <option value="" selected="true">请选择游戏区服</option>
                      </empty>
                  </select>
              </div>
                <div class="form-group normal_space fr">
                    <select id="game_id" name="game_id" class="reselect select_gallery">
                        <option game-id="0" value="">请选择游戏</option>
                      <volist name="game_list" id="vo">
                          <option value="{$vo.relation_game_id}" <if condition="I('game_id') eq $vo['relation_game_id']" > selected="true" </if> > {$vo.relation_game_name}</option>
                      </volist>
                    </select>
              </div>
              <!-- <input type="hidden" name="version" value="{:I('version',1)}"> -->
           <!--  </form> -->
			</div>
		</div>
		
		<div class="page-list query-register-list">
			<div class="trunk-content article">
				<div class="trunk-list list_normal" style="min-height: 56vh;">
					<table class="detailtb normal_table">
						<tr class="num1">
							<td>推广员ID</td>
							<td>一级推广员帐号</td>
							<td>注册用户</td>
							<td>注册IP数</td>
							<td>达标用户</td>
				            <td>达标游戏</td>
				            <td>移动端充值</td>
				            <td>安卓充值</td>
				            <td>苹果充值</td>
						</tr>
						<empty name="list_data">
							<tr>
								<td class="num2" colspan="7">暂无数据~</td>
							</tr>
							<else/>
							<volist name="list_data" id="data">
								<tr class="num2">
									<td>{$data['id']}</td>
									<td>{$data['account']}</td>
									<td>{:IsNull($data['register_user'])}</td>
									<td>{:IsNull($data['register_ip'])}</td>
									<td>{:IsNull($data['dabiao_user'])}</td>
                  <if condition="IsNull($data['dabiao_game']) eq 0">
                  <td>0</td>
                  <else/>
                  <td><a class="dabiao_game" href="javascript:;" url="{:U('Buydetail/dabiao_game',array('begtime'=>I('begtime'),'endtime'=>I('endtime'),'promote_id'=>$data['id'],'game_id'=>I('game_id'),'server_name'=>I('server_name'),'game_level'=>I('game_level')))}" style="color: blue">{:IsNull($data['dabiao_game'])}</a></td>
                  </if>
                  <td>{:IsNull($data['spend'])}</td>
                  <td>{:null_to_0($data['and_spend'])}</td>
                  <td>{:null_to_0($data['ios_spend'])}</td>
					           </tr>
							</volist>
							 <tr class="num2">
					            <td>汇总</td>
					            <td>{:count($list_data)}</td>
					            <td>{$all_data['register_user']}</td>
					            <td>{:IsNull($all_data['register_ip'])}</td>
					            <td>{:IsNull($all_data['dabiao_user'])}</td>
					            <td>{:IsNull($all_data['dabiao_game'])}</td>
					            <td>{:IsNull($all_data['spend'])}</td>
					            <td>{:null_to_0($all_data['and_spend'])}</td>
					            <td>{:null_to_0($all_data['ios_spend'])}</td>
					          </tr>
						</empty>
					</table>
					<div class="import fr">
						<span class="btn"><a href="{:U('Buydetail/exportSummary',array('begtime'=>I('begtime'),'endtime'=>I('endtime'),'promote_id'=>I('promote_id'),'promote_account'=>I('promote_account'),'game_id'=>I('game_id'),'server_name'=>I('server_name'),'game_level'=>I('game_level'),'p'=>I('p')))}" >导出数据(excel)</a></span>
					</div>
				</div>
				
				<div class="pagenation clearfix">{$_page}</div>

			</div>
		</div>

		
	</div>
	<!--内容end-->
</block>

<block name="script">
<link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">	
<link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
	<script type="text/javascript">
$(document).ready(function(){
	var promote_id = $("#promote_id option").length; 
	if(promote_id == 1){
		$("#promote_id option:last").remove(); 
		$("#promote_id").append("<option value='' selected='true'>暂无推广员</option>"); 
	}
	$(".select_gallery").select2();	
})
//回车自动提交
$('.rightcontainer-summary').find('input').keyup(function(event){
    if(event.keyCode===13){
        $("#search").click();
    }
});
var date="{$setdate}";
	$('#sdate').datetimepicker({
    format: 'yyyy-mm-dd',
        language:"zh-CN",
        minView:2,
        autoclose:true,
        scrollMonth:false,
        scrollTime:false,
        scrollInput:false,
        endDate:date
  });
  
  $('#edate').datetimepicker({
   format: 'yyyy-mm-dd',
        language:"zh-CN",
        minView:2,
        autoclose:true,
        pickerPosition:'bottom-left',
        scrollMonth:false,
        scrollTime:false,
        scrollInput:false,
        endDate:date
  });

  $('#submit').click(function(){
    var sdate =$('#sdate').val();
    var edate =$('#edate').val();
    var pid = $('#promote_id').val();
    var pac = $('#promote_account').val();
    if(pid !='' && pac != '' && pid != pac){
        layer.msg("渠道ID与渠道账号不匹配");
      return false;
    }
    // if(sdate =='' || edate==''){
    //   layer.msg('请完整时间搜索框');
    //   return false;
    // }
    if(Date.parse(sdate) > Date.parse(edate)){
      layer.msg('开始时间必须小于等于结束时间');
      return false;
    }
    var url = $(this).attr('url');
      console.log(url);
      var query = $('.jssearch').find('input').serialize();
      query += "&" + $('.jssearch').find('select').serialize();
      query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
      query = query.replace(/^&/g, '');
      if(url.indexOf('?') > 0) {
        url += '&' + query;
      } else {
        url += '?' + query;
      }
      window.location.href = url;

  });
	//退出登录
	$('.loginout').click(function(){
    	     $.ajax({
              type:"POST",
              url:"{:U('Index/logout')}",
              success:function(res){
              		if(res.status == 3){
              			layer.msg('退出成功', {icon: 1,});
              			  setTimeout(function(){
                         window.location.href="{:U('Index/index')}";
                        },1500);
              		}
              },
              error:function(){
              	layer.msg('服务器异常');
              }
            })
        });	

	    $("#game_id").change(function(){
         $.ajax({
             url:"{:U('getServer')}",
             type:"post",
             data:{game_id:$("#game_id option:selected").val()},
             dataType:'json',
             success:function(data){
                 str1 = "<option value=''>请选择区服</option>";
                 str2 = "<option value=''>请选择等级</option>";
                 for (var i in data.data.server_name){
                     str1 += "<option value='"+data.data.server_name[i]+"'>"+data.data.server_name[i]+"</option>"
                     
                 }
                 if(data.data.game_level.first_level_name){
                 str2 +="<option value='"+data.data.game_level.first_level_name+"'>"+data.data.game_level.first_level_name+"</option>";
                  str2 +="<option value='"+data.data.game_level.second_level_name+"'>"+data.data.game_level.second_level_name+"</option>";
                  str2 +="<option value='"+data.data.game_level.third_level_name+"'>"+data.data.game_level.third_level_name+"</option>";
                }
                 $("#server_name").empty();
                 $("#server_name").append(str1);
                 $("#server_name").select2();
                 $("#game_level").empty();
                 $("#game_level").append(str2);
                 $("#game_level").select2();

             }
         })
        })
       var game_id = $("#game_id").val();
   var game_server = "{:I('server_name')}";
    var game_level = "{:I('game_level')}";
   if(game_id>0){
     $.ajax({
             url:"{:U('getServer')}",
             type:"post",
             data:{game_id:$("#game_id option:selected").val()},
             dataType:'json',
             success:function(data){
               str1 = "<option value=''>请选择区服</option>";
               str2 = "<option value=''>请选择等级</option>";
              var server_name = data.data.server_name;
              var levle = data.data.game_level;
                 for (var i in server_name){
                   str1 += "<option value='"+data.data.server_name[i]+"'  "+(game_server && server_name[i] == game_server?'selected':'')+" >"+data.data.server_name[i]+"</option>"
                     
                 }
                 str2 +="<option value='"+data.data.game_level.first_level_name+"'  "+(game_level && levle.first_level_name == game_level?'selected':'') +">"+data.data.game_level.first_level_name+"</option>";
                str2 +="<option value='"+data.data.game_level.second_level_name+"'  "+(game_level && levle.second_level_name == game_level?'selected':'') +">"+data.data.game_level.second_level_name+"</option>";
                str2 +="<option value='"+data.data.game_level.third_level_name+"' "+(game_level && levle.third_level_name == game_level?'selected':'') +">"+data.data.game_level.third_level_name+"</option>";
                 $("#server_name").empty();
                 $("#server_name").append(str1);
                 $("#server_name").select2();
                 $("#game_level").empty();
                 $("#game_level").append(str2);
                 $("#game_level").select2();

             }
         })
   }
      $(".dabiao_game").click(function(){
         var href = $(this).attr('url');
          layer.open({
                  type: 2, 
                  title: "达标游戏", 
                  shadeClose: true, 
                  shade: 0.8, 
                  area: ['71%', '80%'],
                  content: href,
                });
           return false;
      })
</script>
</block>