@extends('vip.layouts')
@section('content')

<form class="layui-form" action="{{ url()->full() }}" id="submitForm" name="submitForm" method="post" eventType=eventAjaxForm>
{!! csrf_field() !!}
  <div class="layui-form-item">
    <label class="layui-form-label">游戏名</label>
    <div class="layui-input-block">
      <select style="width: 100px;" id="game" lay-filter="game" name="select">
        <option value="jspk10" @if($data['game_name']=='jspk10') selected @endif>{{trans('common.jspk10')}}</option>
        <option value="threessc" @if($data['game_name']=='threessc') selected @endif>{{trans('common.threessc')}}</option>
        <option value="onepk10" @if($data['game_name']=='onepk10') selected @endif>{{trans('common.onepk10')}}</option>
        <option value="onessc" @if($data['game_name']=='onessc') selected @endif>{{trans('common.onessc')}}</option>
         <option value="onekuai3" @if($data['game_name']=='onekuai3') selected @endif>{{trans('common.onekuai3')}}</option>
        <option value="one28" @if($data['game_name']=='one28') selected @endif>{{trans('common.one28')}}</option>
        <option value="one28" @if($data['game_name']=='sfsixlottery') selected @endif>{{trans('common.sfsixlottery')}}</option>
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">期数</label>

    <div class="layui-input-inline">
      <select style="width: 100px;" id="select" lay-filter="test" name="select">
        <option value="1" @if(isset($data['info_no'])) selected @endif>自动获取</option>
        <option value="2" >手动输入</option>
      </select>
    </div>
    <div class="layui-input-inline" id="info_no">
    <input type="text" name="info_no"  readonly="readonly" lay-verify="" autocomplete="off"  placeholder="请输入开奖期数" class="layui-input" value="{{isset($data['info_no'])?$data['info_no']:''}}">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">号码</label>
    <div class="layui-input-inline" style="width: 250px;">
      <input type="text" name="codes"  lay-verify="" placeholder="请输入开奖号码" autocomplete="off" class="layui-input" value="">
    </div>
    <div class="layui-form-mid layui-word-aux"><font color="red">注意：开奖号码间用英文逗号隔开</font></div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">开奖时间</label>
    <div class="layui-input-inline">
      <input type="text" name="open_time" class="layui-input" id="form_open_time" placeholder="-" value="">
    </div>
     <div class=" layui-word-aux" style="float:left;"><span class="layui-btn" id="changeTime">调整时间</span></div>
    <div class="layui-form-mid layui-word-aux"><font color="red">注意：时间格式务必填写正确，如2014-10-10 10:10:10</font></div>
  </div>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="submitForm">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-normal">重置</button>
    </div>
  </div>
</form>

<script>
//Demo
layui.use(['form'], function(){
  var form = layui.form;

  //监听提交
  form.on('submit(submitForm)', function(data){
    return true;
  });
  //切换期号获取方式
    form.on('select(test)', function(data){
        if(data.value==1){
            var game=$('#game').val();
            $('input[name=info_no]').attr('readonly','readonly');
            getinfos(game);
        }else{
            $('input[name=info_no]').removeAttr('readonly');
            $('input[name=info_no]').val('');
        }
    });
    //切换游戏
    form.on('select(game)', function(data){
        /*if(data.value==1){
            $('#info_no').attr('disable','true');
        }else{
            $('#info_no').attr('disable','false');
        }*/
        $('#form_open_time').val("");
        if($('#select').val()==1){
            var game=data.value;
            getinfos(game);
        }
    });
    function getinfos(game) {
        $.ajax({
            url:'/admin/infos/getInfos',
            type:'post',
            data:{game:game},
            dataType:'json',
            success:function (data) {
                if(data.status>0){
                    $('input[name=info_no]').val(data.data);
                }else{
                    layer.msg('自动获取出错，请手动输入');
                }
            },
            error:function () {
                layer.msg('网络异常，请重试');
            }
        });
    }
    //调整时间
    $('#changeTime').click(function () {
        var game = $('#game option:selected').val();
        if(game == undefined || game == "")
        {
            layer.msg('获取游戏代码错误');
            return false;
        }
        $.ajax({
            url:'/admin/infos/getGameLastOpenTime',
            type:'post',
            data:{game:game},
            dataType:'json',
            success:function (data) {
                if(data.status>0){
                    $('#form_open_time').val(data.data.change_time);
                }else{
                    layer.msg(data.msg);
                }
            },
            error:function () {
                layer.msg('网络异常，请重试');
            }
        });
    });
});
//初始隐藏期号输入框
/*$(function () {
    var type=$('#select').val();
    if(type==1){
        $('#info_no').hide();
    }
});*/

 function cbFormSuccess(data) {
      var a = layer.alert(data.msg, {}, function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index); //再执行关闭
        parent.window.location.reload();
        //window.history.go(-1);
        //window.location.href='/admin/infos/index';
      });
}

layui.use('laydate', function(){
  var laydate = layui.laydate;

  //时间选择器
  laydate.render({
    elem: '#form_open_time'
    ,type: 'datetime'
  });
});
</script>
@endsection
