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

         .layui-table-body {
             position: relative;
             overflow: auto;
             margin-right: -1px;
         }

        /*.text{*/
            /*width: 88%;*/
        /*}*/
    </style>

    @push('dataTableJS')

        //获取表头
        var tit=function (game){
            var header=[];
            $.ajax({
                type: 'post',
                url: '/admin/Sixlottery/index?data=1&game='+ game,
                data: {},
                dataType: 'json',
                async: false,
                success: function (json) {
                header=json.data.dataCols
                }
            });
            return header;
        }

var active = {
    reload: function(){
      //执行重载
      table.reload('{{ $dataId }}', {
        page: {
          curr: 1 //重新从第 1 页开始
        }
        ,where: {
            game_no:$('#game_no').val(),
            star_time:$('#star_time').val(),
            end_time:$('#end_time').val(),
        }
      });
    }
  };
$('.lay-btn-diy').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });

  //重置表单
  $('.reset').on('click',function(){
	  $('input').val('');
	  $('#trade_type').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 type="text/html" id="open_act">
        <!-- 这里的 checked 的状态只是演示 -->
		@{{#if(d.status=='未开奖'){ }}
			<a href="javascript:deleteList(@{{d.id}})" class="layui-btn layui-btn-sm">{{trans('sixlottery.delete')}}</a>
      <a href="javascript:opengame(@{{d.id}})" id="isfirst" data-id="1"  class="layui-btn layui-btn-sm site-demo-active">{{trans('sixlottery.opengame')}}</a>
    @{{#}else{ }}
      <a href="/Admin/{{$dgame}}Res/Edit?identity=@{{d.id}}&game={{$game}}" id="isfirst" data-id="1"  class="layui-btn layui-btn-sm">{{trans('sixlottery.update_res')}}</a>
		@{{#} }}
    </script>
    <script type="text/html" id="write_time">
		@{{d.time}}
    </script>
    <script type="text/html" id="prizes_code">
		@{{d.codes}}
    </script>
    <div id="parper" data-id="1" class="hide" style="display: none;text-align: center;line-height: 150px;">已完成<span class="percent">0</span>%</div>

    <div id="settimes" data-id="1" class="hide" style="display: none;text-align: center;line-height: 150px;">
        <form>
          <label>单次开奖条数设置</label>
          <input type="number" name="ptimes" id="ptimes" value="{{$times}}" />
          <input type="hidden" id="infono" value="{{$no}}" />
          <input type="hidden" id="game" value="{{$game}}" />
          <input type="button" id="sureset" value="确定"/>
        </form>
    </div>
 
    <div class="layui-inline">
        <a class="layui-btn layui-btn-sm lay-btn-diy" onClick="setPrizetimes()" style="opacity: 1; pointer-events: auto;">设置单次开奖条数</a>
    </div><br>
   @include('vip.datatable')
<script> 
//Demo
layui.use(['form'], function(){
  var form = layui.form;
  
  //监听提交
  form.on('submit(submitForm)', function(data){
    return true;
  });
});

function cbFormSuccess(data){
	layer.msg(data.msg);
	setTimeout(function(){
		parent.window.location.reload();
	},2500);
}

function deleteList(id){
  var game = $('#game').val();
  var url = '/admin/SixlotteryRes/DeleteOpenList?identity='+id + '&game=' + game;
  $.ajax({
     type: "GET",
     url: url,
     dataType: "json",
     success: function(data){
       layer.msg(data.msg);
      setTimeout(function(){
        window.location.reload();
      },2500);
     }
   });
}
    var index = 0;
    var sindex = 0;
    //设置开奖次数
    function setPrizetimes(){
        sindex = layer.open({
            type: 1,
            title: '单次开奖条数',
            closeBtn: 1,
            area: ['400px','400px'],
            skin: 'layui-layer-demo', //没有背景色
            shadeClose: false,
            content: $('#settimes')
        });

    }

    $('#sureset').click(function(){
        var stimes = $('#ptimes').val();
        var no = $('#infono').val();
        var game = $('#game').val();
        $.ajax({
            url:'/admin/SixlotteryRes/SetPtimes',
            type:"post",  
            dataType:"json",  
            data:{stimes:stimes,game:game},  
            success:function(data){ 
                if(data.status==1){
                    layer.msg(data.msg,function(){
                        layer.close(sindex);
                    });
                }else{
                    layer.alert(data.msg);
                }
                
            },  
        });
    });

    function opengame(id){
        $('.parper').show();
        $('.percent').text(0);
        layer.prompt({
          title: '二级密码',
          formType: 1,
        },function(value, index, elem){
              var ispwcheck = $('#parper').attr('data-id');
              $('.layui-layer-btn0').attr('disable','true');
              $('.layui-layer-btn0').css('background-color','#dedede');
              /*layer.open({
                  type: 1,
                  title: '开奖进度',
                  closeBtn: 0,
                  area: ['200px','200px'],
                  skin: 'layui-layer-demo', //没有背景色
                  shadeClose: true,
                  content: $('#parper')
              });*/
              index = layer.load(1, {shade: [0.71,'#eee']});
              prize(id,value,ispwcheck);
        })

    }

    function prize(id,value,ispwcheck){
      var game = $('#game').val();
      var url = '/admin/SfsixlotteryRes/OpenPrize';
      if(game=='sixlottery'){
        url = '/admin/SixlotteryRes/OpenPrize';
      }
      var isfirst = $('#isfirst').attr('data-id');
      $('#isfirst').attr('data-id','2');
      $.ajax({
          url:url + '?identity='+id + '&game=' + game,
          type:"post",  
          dataType:"json",  
          data:{password:value,isfirst:isfirst},  
          success:function(data){
              layer.close(index);
              if(data.status==2){
                layer.alert('开奖成功',function(){
                    window.location.reload();
                });
              }else if(data.status==1 && isfirst==1){
                  layer.alert('系统正在开奖，请等待2～3分钟');
                  setTimeout(function(){
                    prize(id,value,2);
                  },5000);
              }else if(data.status==1){
                  setTimeout(function(){
                    prize(id,value,2);
                  },5000);
              }else{
                  layer.alert(data.msg,function(){
                    window.location.reload();
                  });
              }
            /*if(data.status==2){
              if(ispwcheck==1){
                    layer.close(index);
                    layer.open({
                        type: 1,
                        title: '开奖进度',
                        closeBtn: 0,
                        area: ['200px','200px'],
                        skin: 'layui-layer-demo', //没有背景色
                        shadeClose: false,
                        content: $('#parper')
                    });
                }
                $('#parper .percent').text(100);
                layer.msg('成功');
                setTimeout(function(){
                  window.location.reload();
                },2500);
            }else if(data.status==1){
                if(ispwcheck==1){
                    layer.close(index);
                    layer.open({
                        type: 1,
                        title: '开奖进度',
                        closeBtn: 0,
                        area: ['200px','200px'],
                        skin: 'layui-layer-demo', //没有背景色
                        shadeClose: false,
                        content: $('#parper')
                    });
                }
                console.log(data.data.percent);
                $('#parper .percent').text(data.data.percent);
                prize(id,value,2);
            }else{
                layer.alert(data.msg);
            }*/
          },  
      })
    }
</script>

@endsection
