@extends('vip.layouts')
@section('content')
<form class="layui-form" action="/Admin/{{$data['dgame']}}Res/Edit?identity={{ $data['id']}}&info_no={{ $data['info_no'] }}" id="submitForm" name="submitForm" method="post" eventType=eventAjaxForm>
{!! csrf_field() !!}

	 <div class="layui-form-item">
		{{$data['gname']}}修改开奖结果
	</div>
	
	 <div class="layui-form-item">
		<label class="layui-form-label">{{ trans('sixlottery.name') }}</label>
		<div class="layui-input-block">
		<input type="text"  lay-verify="" placeholder="" autocomplete="off" value="{{ $data['gname'] }}" class="layui-input" disabled="disabled">
    <input type="hidden" name="game"   id="game"  required  lay-verify="" placeholder="" autocomplete="off" value="@isset($data){{ $data['game'] }}@endisset" class="layui-input">
		</div>
	</div>
	 <div class="layui-form-item">
		<label class="layui-form-label">{{ trans('sixlottery.info_no') }}:</label>
		<div class="layui-input-block">
		<input type="text" name="info_no"   id="info_no"  required  lay-verify="" placeholder="" autocomplete="off" value="@isset($data){{ $data['info_no'] }}@endisset" class="layui-input" disabled="disabled">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">{{ trans('sixlottery.prizes_code') }}:</label>
			<div class="layui-input-inline" style="width: 60px;margin-bottom: 10px">
			  <input type="text" name="open_code1" min="0" lay-verify="" autocomplete="off" class="layui-input" value="@isset($data) {{ $data['code'][0] }} @endisset" placeholder="0"  style="height:25px;">
			</div>
			<div class="layui-input-inline" style="width: 60px;margin-bottom: 10px">
			  <input type="text" name="open_code2" min="0" lay-verify="" autocomplete="off" class="layui-input" value="@isset($data) {{ $data['code'][1] }} @endisset" placeholder="0" style="height:25px;">
			</div>
			<div class="layui-input-inline" style="width: 60px;margin-bottom: 10px">
			  <input type="text" name="open_code3" min="0" lay-verify="" autocomplete="off" class="layui-input" value="@isset($data) {{ $data['code'][2] }} @endisset" placeholder="0" style="height:25px;">
			</div>
			<div class="layui-input-inline" style="width: 60px;margin-bottom: 10px">
			  <input type="text" name="open_code4" min="0" lay-verify="" autocomplete="off" class="layui-input" value="@isset($data) {{ $data['code'][3] }} @endisset" placeholder="0" style="height:25px;">
			</div>
			<div class="layui-input-inline" style="width: 60px;margin-bottom: 10px">
			  <input type="text" name="open_code5" min="0" lay-verify="" autocomplete="off" class="layui-input" value="@isset($data) {{ $data['code'][4] }} @endisset" placeholder="0" style="height:25px;">
			</div>
			<div class="layui-input-inline" style="width: 60px;margin-bottom: 10px">
			  <input type="text" name="open_code6" min="0" lay-verify="" autocomplete="off" class="layui-input" value="@isset($data) {{ $data['code'][5] }} @endisset" placeholder="0" style="height:25px;">
			</div>
			<div class="layui-input-inline" style="width: 60px;margin-bottom: 10px">
			  <input type="text" name="open_code7" min="0" lay-verify="" autocomplete="off" class="layui-input" value="@isset($data) {{ $data['code'][6] }} @endisset" placeholder="0" style="height:25px;">
			</div>
		<div style="color:red;">数字只支持1到49，若输入其他号码开奖错误则无人中奖。</div>
	</div>
						
	 <div class="layui-form-item">
		<label class="layui-form-label">{{ trans('sixlottery.rpassword') }}:</label>
		<div class="layui-input-block">
			<input type="password" name="rpassword" class="layui-input" lay-verify="username" id="form_rpassword" placeholder="请输入二次密码">
		</div>
	</div>
	<input type="hidden" name="isfirst" id="isfirst" value="1">
	<input type="hidden" name="identity" id="identity" value="{{ $data['id']}}">
	<input type="hidden" name="info_no" value="{{ $data['info_no']}}">

@if(S('ACTION')!='view')
  <div class="layui-form-item">
    <div class="layui-input-block">
      		<button class="layui-btn updateres" lay-submit lay-filter="submitForm">修改结果</button>
      <button type="" class="layui-btn layui-btn-primary returnpage">返回</button>
    </div>
  </div>
@endif
</form>
<br>
<div id="parper" class="hide" style="display: none;text-align: center;line-height: 150px;">已完成<span class="percent">0</span>%</div>
<script>
//Demo
$('.returnpage').on('click',function(){
	window.history.go(-1);
});
var index = 0;
var game = $('#game').val();
$(".goprize").mouseup(function(){
	/*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']});
  	$("#pstatus").val(3);
});

$(".updateres").mouseup(function(){
	  index = layer.load(1, {shade: [0.71,'#eee']});
	/*layer.open({
          type: 1,
          title: '开奖进度',
          closeBtn: 0,
          area: ['200px','200px'],
          skin: 'layui-layer-demo', //没有背景色
          shadeClose: true,
          content: $('#parper')
      });*/
});

//解锁
/*$('.unlock').on('click',function(){
	var infono = $('#info_no').val();
	$.ajax({
		url:"/Admin/SixlotteryRes/UnlockBuyinfo",
		type:"get",  
        dataType:"json",  
        data:{  
            infono:infono  
        },  
        success:function(data){  
        	if(data.status==1){ 
        		$('.updateres').show();
        		$('.unlock').hide();
        		return 'data.msg';
        	}else{
        		return 'data.msg';
        	}
        },  
	})
});*/

layui.use(['form'], function(){
  var form = layui.form;

    form.verify({
        password:function(value,item){

            if(value==null||value==''||value==undefined){
                $('.updateres').show();
                return '密码不能为空';
            }
		}
    });

  //监听提交
  form.on('submit(submitForm)', function(data){
      $('.updateres').hide();
    return true;
  });
});

function cbFormSuccess(data){
	var info_no = $('#info_no').val();
    //layer.close(index);
    if(data.status==1){
        layer.alert('正在开奖，请等待2～3分钟');
        prize(info_no,1);
    }else{
        layer.alert(data.msg);
        setTimeout(function(){
          window.location.href = '/admin/SixlotteryRes/OpenList?no=' + info_no + '&game=' + game;
        },2500);
    }
	/*if(data.data>0){
		layer.msg(data.msg);
		$('#pstatus').val('1')
		$('.updateres').show();
    	$('.unlock').hide();
    	$('.goprize').hide();
	}else{
		$('#isfirst').val('2');
		prize(info_no,1);
	}*/
}
 
function prize(info_no,ispwcheck){
  var url = '/admin/SfsixlotteryRes/Edit';
  if(game=='sixlottery'){
    url = '/admin/SixlotteryRes/Edit';
  }
	$('.updateres').hide();
  var isfirst = $('#isfirst').val();
  $('#isfirst').val('2');
	$.ajax({
		url:url,
		type:"post",  
        dataType:"json",  
        data:$('form').serialize(),  
        success:function(data){
            //layer.close(index);
            if(data.status==1 && isfirst==1){
                layer.msg('正在开奖，请等待2～3分钟');
                setTimeout(function(){
                  prize(info_no,1);
                },5000);
      			}else if(data.status==2){
                layer.alert('成功',function(){
                  window.location.href='/admin/SixlotteryRes/OpenList?no=' + info_no + '&game=' + game;
                });
            }else if(data.status<0){
                layer.alert(data.msg,function(){
                  window.location.reload();
                });
      			}else{
                setTimeout(function(){
                  prize(info_no,1);
                },5000);
            }
        	/*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);
				//$('.updateres').show();
        		layer.msg('成功');
				setTimeout(function(){
					window.location.href='/admin/SixlotteryRes/OpenList?no=' + info_no;
					window.history.go(-1);//返回上一页
				},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(info_no,2);
        	}else{
        		$('.updateres').html('继续开奖');
        		layer.alert(data.msg);
        	}*/
        },  
	})
}

function  cbFormFail(data) {
  if(data.status==2){
    var info_no = $('#info_no').val();
    layer.alert(data.msg);
    setTimeout(function(){
      window.location.href = '/admin/SixlotteryRes/OpenList?no=' + info_no + '&game=sixlottery';
    },2500);
  }else{
    parent.layer.msg(data.msg); 
    setTimeout(function(){
        window.location.reload();
      },2500);
  }  
    //$('.updateres').show();
}

</script>
@endsection
