@extends('vip.layouts')
@section('content')
    <style>
        .layui-laydate-range {
            width: auto;
        }

        .layui-form-switch em {
            width: auto;
        }

        .layui-form-switch {
            width: 44px;
            line-height: 23px;
        }

        .layui-form-item .checkbox {
            width: auto;
        }
    </style>
    <script type="text/html" id="agent_name">
       <a href="/admin/nagent/agentInfo?id=@{{ d.id }}&grade=@{{d.grade}}" >@{{d.agent_user}}</a><br>
       @{{#if(d.grade == null){ }}
       @{{#}else{ }}
            @{{d.grade}}
       @{{#} }}
    </script>

    <script type="text/html" id="zgwater">
       @{{d.zt_water}}<br>@{{d.group_water}}
    </script>

    <script type="text/html" id="sumchild_cash">
        @{{d.sum_child}}<br>
        @{{#if(d.money_total == null){ }}
            0
        @{{#}else{ }}
            @{{d.money_total}}
        @{{#} }}
    </script>

    <script type="text/html" id="settle_money">
       @{{d.wzt_water}}<br>@{{d.wgroup_water}}
    </script>

    <script type="text/html" id="sellte_agent">
        <a class="layui-btns" href="/admin/nagent/Settle?id=@{{ d.id }}&grade=@{{d.grade}}" >结算代理</a>
    </script>
    <script type="text/html" id="money_list">
        <a class="layui-btns" href="/admin/NagentFund/index?agent_name=@{{ d.agent_user }}" >查看</a>
    </script>
    <script type="text/html" id="child">
        <a class="" href="/admin/nagentChild/index?identity=@{{ d.agent_identity }}" >下级会员</a>
    </script>
    <script type="text/html" id="agent">
        @{{#if(d.state==1){ }}
            <div style="color:green;">启用&nbsp;&nbsp;<a href="/admin/nagent/changeStatus?id=@{{d.id}}" class="layui-btn layui-btn-xs layui-btn-danger" style="margin-bottom:5px;margin-left:0px;">禁用</a></div>
        @{{#}else{ }}
            <div style="color:red;">禁用&nbsp;&nbsp;<a href="/admin/nagent/changeStatus?id=@{{d.id}}" class="layui-btn layui-btn-xs" style="margin-bottom:5px;margin-left:0px;">启用</a></div>
        @{{#} }}
    </script>

    <script type="text/html" id="blacklist">
        @{{#if(d.blacklist==1){ }}
            <div style="color:green;">是&nbsp;&nbsp;<a href="/admin/nagent/setBlacklist?id=@{{d.id}}" class="layui-btn layui-btn-xs layui-btn-danger" style="margin-bottom:5px;margin-left:0px;">踢出</a></div>
        @{{#}else{ }}
            <div style="color:red;">否&nbsp;&nbsp;<a href="/admin/nagent/setBlacklist?id=@{{d.id}}" class="layui-btn layui-btn-xs" style="margin-bottom:5px;margin-left:0px;">加入</a></div>
        @{{#} }}
    </script>
    <!---注单管理-->
    <div class="layui-row">

        <div class="layui-col-xs12">

            <form class="layui-form rewrite" action="" eventType=eventForm>
                <div class="layui-form-item">

                    <div class="layui-inline">
                        <label class="layui-form-label">{{ trans('agent.agent_user') }}</label>
                        <div class="layui-input-inline">
                            <input type="text" name="agent_user" id="agent_user" value="{{ $agent_user }}" eventType=event-query autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline checkbox">
                            <input type="checkbox" name="sureblur" id="form_sureblur" lay-skin="switch" lay-text="精确|模糊" @if(!isset($sureblurs) || $sureblurs=='on') checked @endif  class="layui-input" eventType=event-query>

                            <input type="hidden" name="sureblurs" id="form_sureblurs" lay-verify="required" autocomplete="off" class="layui-input" eventType=event-query  value="{{ $sureblurs }}">
                        </div>
                    </div>
                    
                    <div class="layui-inline">

                        <label class="layui-form-label">{{ trans('agent.phone') }}</label>
                        <div class="layui-input-inline">
                            <input type="text" name="phone" id="phone" value="{{ $phone }}"  eventType=event-query autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <!-- <div class="layui-inline">
                        <label class="layui-form-label">{{ trans('agent.email') }}</label>
                        <div class="layui-input-inline">
                            <input type="text" name="email" id="email" value="{{ $email }}" eventType=event-query autocomplete="off" class="layui-input">
                        </div>

                    </div> -->
                    
                    <div class="layui-inline">
                        <label class="layui-form-label">{{ trans('agent.regist_startime') }}</label>
                        <div class="layui-input-inline">
                            <input type="text" name="regist_startime"  id="regist_startime" placeholder=" - "  lay-verify="" autocomplete="off" class="layui-input test-item"  value="{{$regist_startime}}" eventType=event-query>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">{{ trans('agent.regist_endtime') }}</label>
                        <div class="layui-input-inline">
                            <input type="text" name="regist_endtime"  id="regist_endtime" placeholder=" - "  lay-verify="" autocomplete="off" class="layui-input test-item" value="{{ $regist_endtime }}" eventType=event-query>
                        </div>
                    </div>

                     <div class="layui-inline">
                        <label class="layui-form-label">{{ trans('nagent.invite') }}</label>
                        <div class="layui-input-inline">
                            <input type="text" name="invite" id="invite" value="{{ $invite }}" eventType=event-query autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <a class="layui-btn layui-btn-sm lay-btn-diy" eventType=event-query-submit  data-type="reload" style="opacity: 1; pointer-events: auto;">提交</a>
                        <a  class="layui-btn   layui-btn-sm layui-btn-normal reset" data-type="reload" style="opacity: 1; pointer-events: auto;"
                        >重置</a>
                        <a class="layui-btn layui-btn-sm layui-btn-green set" data-type="reload" style="opacity: 1; pointer-events: auto;"
                        ><i class="layui-icon">ဂ</i></a>
                        <a class="layui-btn layui-btn-sm" id="tocountwater"  style="opacity: 1; pointer-events: auto;">业绩统计</a>
                    </div>

                    <div id="countwater" class="hide" style="display: none;text-align: center;line-height: 150px;padding: 20px;">
                        <div class="layui-form-item">
                            <label class="layui-form-label">{{ trans('agent.agent_user') }}：</label>
                            <div class="layui-input-block">
                                <input type="text" name="agent_users" id="form_agent_users" placeholder=" - " lay-verify=""
                                       autocomplete="off" class="layui-input" value="">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">{{ trans('gamemenu.name') }}：</label>
                            <div class="layui-input-block">
                                <select name="gamec" id="form_games" lay-verify="" autocomplete="off" class="layui-input">
                                    <option value="">{{ trans('gamemenu.select_game') }}</option>
                                    @foreach($gameList as $k=>$v):
                                        <option value="{{$v['gameCode']}}">{{$v['name']}}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">{{ trans('gamemenu.game_no') }}：</label>
                            <div class="layui-input-block">
                                <input type="text" name="game_no" id="form_game_no" placeholder=" - " lay-verify="" autocomplete="off" class="layui-input" value="">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">{{ trans('agent.counttime') }}：</label>
                            <div class="layui-input-block">
                                <input type="text" name="counttime" id="form_counttime" placeholder=" - " lay-verify=""
                                       autocomplete="off" class="layui-input" value="{{$counttime}}">
                            </div>
                        </div>

                        <div class="layui-form-item" style="padding-top: 10px;color:red;">
                            <label class="layui-form-label" style="text-align: left;">{{ trans('agent.starcount') }}</label>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block" style="width: 180px;height: 20px;">
                                <span class="layui-btn gocount" lay-submit>业绩统计</span>
                                <span type="" class="layui-btn layui-btn-primary closecheck">返回</span>
                            </div>
                        </div>
                    </div>

                <!--  &nbsp;&nbsp;&nbsp;&nbsp;<div class="layui-inline"><a href="javascript:openWin('/admin/system/addMenu','{{ trans("menu.menu_add")}}','600px','800px','')"
                     class="layui-btn layui-btn-sm">添加</a></div>
                    <div class="layui-inline"><a href="/admin/menu/add"
                                                 class="layui-btn layui-btn-sm  layui-btn-danger">删除</a></div> -->

                </div>
            </form>
            <div id="countper" class="hide" style="display: none;text-align: center;line-height: 150px;">共<span class="alldata">0</span>条数据待统计,已统计<span class="dataed">0</span>条</div>
            <div id="countgame" class="hide" style="display: none;text-align: center;line-height: 150px;">共<span class="alldatas">0</span>个游戏待统计,已统计<span class="dataeds">1</span>个</div>
        </div>
    </div>
@push('dataTableJS')
/*var active = {
    reload: function(){
      //执行重载
      table.reload('{{ $dataId }}', {
        page: {
          curr: 1 //重新从第 1 页开始
        }
        ,where: {
            agent_user:$("#agent_user").val(),
            grade:$('#grade').val(),
            phone:$('#phone').val(),
            email:$('#email').val(),
            type:$('#type').val(),
            status:$('#status').val(),
            regist_startime:$('#regist_startime').val(),
            regist_endtime:$('#regist_endtime').val(),
			sureblur:$('.layui-form-switch').text(),
        }
      });
    }
  };
$('.lay-btn-diy').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });*/

  //重置表单
  $('.reset').on('click',function(){
	  $('input').val('');
	  $('#grade').val('');
	  $('#type').val('');
	  $('#status').val('');
//	  var type = $(this).data('type');
///	  active[type] ? active[type].call(this) : '';
  });

    //刷新表单
//    $('.set').on('click',function(){
//    var type = $(this).data('type');
//    active[type] ? active[type].call(this) : '';
//    });
@endpush
<script>
    $(function () {
        $('body').on('click','#form_sureblur~.layui-form-switch',function(){
            var sus = $('#form_sureblur').next().text();
            if(sus=='精确'){
                $('#form_sureblurs').val('on');
            }else{
                $('#form_sureblurs').val('off');
            }
        })
    })
    function Vertity(url) {
        layer.confirm('是否确认操作？', {
            btn: ['确认', '取消'] //按钮
        }, function() {
            $.getJSON(url, function(data, textStatus) {
                if (data.status == '1') {
                    layer.msg('操作成功');
                    reloadDataTable();
                } else {
                    layer.msg(data.msg);
                }
            });
        }, function() {
        });
    }

    //代理业绩统计
    $("#tocountwater").on('click',function(){
        index = layer.open({
              type: 1,
              title: '代理业绩统计',
              closeBtn: 1,
              area: ['400px','400px'],
              skin: 'layui-layer-demo', //没有背景色
              shadeClose: true,
              content: $('#countwater')
          });
    });
    var indexs = 0;
    var oindex = 0;

    //开始统计
    $(".gocount").on('click',function(){
        var agent_user = $('#form_agent_users').val();
        var game = $('#form_games').val();
        var no = $('#form_game_no').val();
        var time = $('#form_counttime').val();
        if((game=='' || game==undefined) && (time=='' || time==undefined)){
            layer.msg('游戏和时间至少选择一项');
            return false;
        }else if((no=='' || no==undefined) && (time=='' || time==undefined)){
            layer.msg('游戏必须对应固定期号');
        }else{
            indexs = layer.load(1, {shade: [0.71,'#eee']});
            $.ajax({
                url:"/admin/nagent/countAgentwater?agent_users=" + agent_user + "&game=" + game + "&no=" + no + "&counttime=" + time,
                type:"post",  
                dataType:"json",  
                success:function(data){
                    layer.close(index);
                    if(data.status<0){
                        layer.msg(data.msg);
                    }else if(data.status==2){
                        var coner = 'countper';
                        if(data.data.allgame > data.data.gdinwei){
                            coner = 'countgame';
                        }
                        oindex = layer.open({
                          type: 1,
                          title: '统计进度',
                          closeBtn: 0,
                          area: ['250px','200px'],
                          skin: 'layui-layer-demo', //没有背景色
                          shadeClose: false,
                          content: $('#' + coner)
                        });
                        $('#countgame .dataed').text(0);
                        $('#countgame .dataeds').text(0);
                        if(data.data.allgame > data.data.gdinwei){
                            $('#countgame .alldatas').text(data.data.allgame);
                        }else{
                            $('#countper .alldata').text(data.data.cnum);
                        }
                        
                        countWater(2,time,data.data.bdinfo);
                    }else{
                        layer.close(indexs);
                        layer.msg('统计成功');
                    }
                },  
            });
        }
    });

    function countWater(subs,time,bdinfo){
        $.ajax({
            url:"/admin/nagent/countAgentwater?subs=" + subs + "&counttime=" + time,
            type:"post", 
            data:{bdinfo:bdinfo},
            dataType:"json",  
            success:function(data){
                layer.close(index);
                if(data.status<0){
                    layer.msg(data.msg);
                }else if(data.status == 2){
                    var coner = 'countper';
                    if(data.data.allgame > data.data.gdinwei){
                        var dv = $('#countgame .dataeds').text();
                        dv = parseInt(dv) + 1;
                        $('#countgame .dataeds').text(dv);
                    }else if(data.data.allgame == data.data.gdinwei){
                        layer.close(oindex);
                        oindex = layer.open({
                          type: 1,
                          title: '统计进度',
                          closeBtn: 0,
                          area: ['250px','200px'],
                          skin: 'layui-layer-demo', //没有背景色
                          shadeClose: false,
                          content: $('#countper')
                        });
                        $('#countper .alldata').text(data.data.cnum);
                        $('#countgame .dataed').text(0);
                        $('#countgame .dataeds').text(0);
                    }else{
                        var dv = $('#countper .dataed').text();
                        dv = parseInt(dv) + data.data.cnum;
                        $('#countper .dataed').text(dv);
                    }
                        
                    countWater(2,time,data.data.bdinfo);
                }else{
                    layer.close(indexs);
                    layer.close(oindex);
                    layer.msg('统计成功');
                }
            },  
        });
    }


    layui.use('laydate', function(){
      var laydate = layui.laydate;
      
      //时间选择器
      laydate.render({
        elem: '#form_counttime'
        ,type: 'date'
      });
    });

</script>
    @include('vip.datatable')
@endsection
