@extends('vip.layouts')
@section('content')
<style type="text/css">
  .loss-input {
    /* display: block; */
    width: 100%;
    padding-left: 10px;
}
.loss-input {
    height: 38px;
    line-height: 1.3;
    line-height: 38px\9;
    border-width: 1px;
    border-style: solid;
    background-color: #fff;
    border-radius: 2px;
}
</style>
<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">{{ trans('lottery_money.type') }}</label>
            <div class="layui-input-block">
              @if(isset($data['type']))
                <input type="hidden" name="type" id="type" value="{{ $data['type'] }}"  required  lay-verify="" placeholder="" autocomplete="off"  eventType=event-query class="layui-input">
                <input type="text" required disabled="disabled" lay-verify="" placeholder="" autocomplete="off" value="{{  $data['type_name'] }}" class="layui-input">
              @else
              <select name="type" id="type" class="Selects" lay-filter="testSelect" lay-verify="" autocomplete="off" class="layui-input" eventType=event-query>
                    @foreach(trans('lottery_money.money_C') as $k=>$v)
                      <option @if(isset($data['type'])&& $k == $data['type'])  selected @endif value="{{$k}}">{{$v}}</option>
                    @endforeach

              </select>
              @endif
              </div>
            </div>

            <div class="layui-form-item">
            <label class="layui-form-label">{{ trans('lottery_money.give_type') }}</label>
            <div class="layui-input-block">
              <select name="give_type" id="type" lay-verify="" autocomplete="off" class="layui-input" eventType=event-query>
                    <option value="pre" @if(isset($give_type)&&$give_type=='pre')selected @endif>比例</option>
                    <option value="num" @if(isset($give_type)&&$give_type=='num')selected @endif >赠送金额</option>
              </select>
              </div>
            </div>

            <div class="layui-form-item single" style="display: none;">
            <label class="layui-form-label">{{ trans('lottery_money.game') }}</label>
            
            <div class="layui-input-block">
              <select name="game" id="game" lay-verify="" autocomplete="off" class="layui-input" eventType=event-query>
                    <option value="" selected="selected">请选择</option>
                    @foreach($dataed as $k=>$v)
                      <option value="{{$v['gameCode']}}">{{ $v['name'] }}</option>
                    @endforeach
              </select>
              </div>
            </div>

            <div class="layui-form-item sub_type loss_money"  @if(isset($data['type'])&& $data['type']!='loss_money') style="display: none;" @endif>
              <label class="layui-form-label">{{ trans('lottery_money.sub_type.name') }}</label>
              
              <div class="layui-input-block">
                <select name="sub_type" id="sub_type" lay-verify="" autocomplete="off" class="layui-input" eventType=event-query>
                      @if(!isset($data['sub_type']) || $data['sub_type']=='')
                        <option value="" selected="selected">请选择</option>
                      @endif
                      @foreach(trans('lottery_money.sub_type.loss_money') as $k=>$v)
                        <option value="{{$k}}" @if(isset($data['sub_type']) && $data['sub_type']==$k) selected="selected" @endif>{{ $v }}</option>
                      @endforeach
                </select>
              </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">{{ trans('lottery_money.proportion') }}:</label>
                <div class="layui-input-block">
                <input type="text" name="proportion" id="proportion"  required  lay-verify="" placeholder="" autocomplete="off" value="@isset($datas) {{ $datas }} @endisset" class="layui-input">
                &nbsp;&nbsp;{{ trans('lottery_money.proportione') }}
                </div>
            </div>

            <div class="layui-form-item">
            <label class="layui-form-label">{{ trans('lottery_money.grade') }}</label>
            <div class="layui-input-block">
              <select name="grade" id="grade" lay-verify="" autocomplete="off" class="layui-input" eventType=event-query>
                  <option value="-1" selected="selected">无等级要求</option>
                  @foreach(trans('lottery_money.user_grade') as $k=>$v)
                    <option @if(isset($data['grade'])&&$k == $data['grade']) selected @endif value="{{$k}}">{{$v}}</option>
                 @endforeach
              </select>
              </div>
            </div>

            {{--<div class="layui-form-item">
                <label class="layui-form-label">{{ trans('lottery_money.grade') }}:</label>
                <div class="layui-input-block">
                <input type="text" name="grade" id="grade"  required  lay-verify="" placeholder="" autocomplete="off" value="@isset($data) {{ $data['grade'] }} @endisset" class="layui-input">
                </div>
            </div>--}}


            <div class="layui-form-item">
                <label class="layui-form-label">{{ trans('lottery_money.name') }}:</label>
                <div class="layui-input-block">
                <input type="text" name="name"   id="name"  required  lay-verify="" placeholder="" autocomplete="off" value="@isset($data) {{ $data['name'] }} @endisset" class="layui-input">
                </div>
            </div>

            

            <div class="layui-form-item adroot">
                <label class="layui-form-label">{{ trans('lottery_money.sort') }}:</label>
                <div class="layui-input-block">
                <input type="text" name="sort"   id="sort"  required  lay-verify="" placeholder="" autocomplete="off" value="@isset($data) {{ $data['sort'] }} @endisset" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item extrcon" @if(isset($data['type'])&& ($data['type']=='lucky_money' || $data['type']=='loss_money')) data-type="{{$data['type']}}" @else style="display: none;" @endif>
              <div class="layui-input-block">
                <label class="layui-form-label">扩展条件: </label>
              </div>
            </div>
            @if(isset($data['type'])&& $data['type']=='loss_money')
            @foreach($data['condi'] as $k=>$v)
              <div class="layui-form-item condi loss_money"  @if(isset($data['type'])&& $data['type']!='loss_money') style="display: none;" @endif>
                <label class="layui-form-label">{{ trans('lottery_money.condi.loss_money.cd1') }}</label>
                
                <div class="layui-input-block">
                  <input type="text" name="cd1-{{$k}}" id="cd1-{{$k}}" required  lay-verify="" placeholder="" autocomplete="off" value="@isset($v['cd1']) {{ $v['cd1'] }} @endisset" class="loss-input" style="width: 200px;">&nbsp;&nbsp;{{ trans('lottery_money.condi.loss_money.cd1e') }}
                </div>
              </div>

              <div class="layui-form-item condi loss_money"  @if(isset($data['type'])&& $data['type']!='loss_money') style="display: none;" @endif>
                <label class="layui-form-label">{{ trans('lottery_money.condi.loss_money.cd2') }}</label>
                
                <div class="layui-input-block">
                  <input type="text" name="cd2-{{$k}}" id="cd2-{{$k}}" required  lay-verify="" placeholder="" autocomplete="off" value="@isset($v['cd2']) {{ $v['cd2'] }} @endisset" class="loss-input" style="width: 200px;">&nbsp;&nbsp;{{ trans('lottery_money.condi.loss_money.cd2e') }}
                </div>
              </div>
              
              <div class="layui-form-item condi loss_money"  @if(isset($data['type'])&& $data['type']!='loss_money') style="display: none;" @endif>
                <label class="layui-form-label">{{ trans('lottery_money.condi.loss_money.cd3') }}</label>
                
                <div class="layui-input-block">
                  <input type="text" name="cd3-{{$k}}" id="cd3-{{$k}}" required  lay-verify="" placeholder="" autocomplete="off" value="@isset($v['cd3']) {{ $v['cd3'] }} @endisset" class="loss-input" style="width: 200px;">&nbsp;&nbsp;{{ trans('lottery_money.condi.loss_money.cd3e') }}
                </div>
              </div>
              <div class="layui-form-item condi loss_money"  @if(isset($data['type'])&& $data['type']!='loss_money') style="display: none;" @endif>
                <label class="layui-form-label">{{ trans('lottery_money.condi.loss_money.cd4') }}</label>
                
                <div class="layui-input-block">
                  <input type="text" name="cd4-{{$k}}" id="cd4-{{$k}}" required  lay-verify="" placeholder="" autocomplete="off" value="@isset($v['cd4']) {{ $v['cd4'] }} @endisset" class="loss-input" style="width: 200px;">&nbsp;&nbsp;{{ trans('lottery_money.condi.loss_money.cd4e') }}
                </div>
              </div>
            @endforeach
            @endif

            @if(isset($data['type'])&& $data['type']=='lucky_money')
            @foreach($data['condi'] as $k=>$v)
              <div class="layui-form-item condi lucky_money"  @if(isset($data['type'])&& $data['type']!='lucky_money') style="display: none;" @endif>
                <label class="layui-form-label">{{ trans('lottery_money.condi.lucky_money.cd1') }}</label>
                
                <div class="layui-input-block">
                  <input type="text" name="cd1-{{$k}}" id="cd1-{{$k}}" required  lay-verify="" placeholder="" autocomplete="off" value="@isset($v['cd1']) {{ $v['cd1'] }} @endisset" class="loss-input" style="width: 200px;">&nbsp;&nbsp;{{ trans('lottery_money.condi.lucky_money.cd1e') }}
                </div>
              </div>

              <div class="layui-form-item condi lucky_money"  @if(isset($data['type'])&& $data['type']!='lucky_money') style="display: none;" @endif>
                <label class="layui-form-label">{{ trans('lottery_money.condi.lucky_money.cd2') }}</label>
                
                <div class="layui-input-block">
                  <input type="text" name="cd2-{{$k}}" id="cd2-{{$k}}" required  lay-verify="" placeholder="" autocomplete="off" value="@isset($v['cd2']) {{ $v['cd2'] }} @endisset" class="loss-input" style="width: 200px;">&nbsp;&nbsp;{{ trans('lottery_money.condi.lucky_money.cd2e') }}
                </div>
              </div>
              
              <div class="layui-form-item condi lucky_money"  @if(isset($data['type'])&& $data['type']!='lucky_money') style="display: none;" @endif>
                <label class="layui-form-label">{{ trans('lottery_money.condi.lucky_money.cd3') }}</label>
                
                <div class="layui-input-block">
                  <input type="text" name="cd3-{{$k}}" id="cd3-{{$k}}" required  lay-verify="" placeholder="" autocomplete="off" value="@isset($v['cd3']) {{ $v['cd3'] }} @endisset" class="loss-input" style="width: 200px;">&nbsp;&nbsp;{{ trans('lottery_money.condi.lucky_money.cd3e') }}
                </div>
              </div>
            @endforeach
            @endif

            <div class='loscon' style="display:none;">
              <div class="layui-form-item condiloss_money"><label class="layui-form-label">{{ trans('lottery_money.condi.loss_money.cd1') }}</label><div class="layui-input-block">
                    <input type="text" name="cd1-0" id="cd1-0" required  lay-verify="" placeholder="" autocomplete="off" value="" class="loss-input" style="width: 200px;">&nbsp;&nbsp;{{ trans('lottery_money.condi.loss_money.cd1e') }}
              </div></div>

              <div class="layui-form-item condiloss_money"><label class="layui-form-label">{{ trans('lottery_money.condi.loss_money.cd2') }}</label><div class="layui-input-block">
                    <input type="text" name="cd2-0" id="cd2-0" required  lay-verify="" placeholder="" autocomplete="off" value="" class="loss-input" style="width: 200px;">&nbsp;&nbsp;{{ trans('lottery_money.condi.loss_money.cd2e') }}
              </div></div>

              <div class="layui-form-item condiloss_money"><label class="layui-form-label">{{ trans('lottery_money.condi.loss_money.cd3') }}</label><div class="layui-input-block">
                    <input type="text" name="cd3-0" id="cd3-0" required  lay-verify="" placeholder="" autocomplete="off" value="" class="loss-input" style="width: 200px;">&nbsp;&nbsp;{{ trans('lottery_money.condi.loss_money.cd3e') }}
              </div></div>

              <div class="layui-form-item condiloss_money"><label class="layui-form-label">{{ trans('lottery_money.condi.loss_money.cd4') }}</label><div class="layui-input-block">
                    <input type="text" name="cd4-0" id="cd4-0" required  lay-verify="" placeholder="" autocomplete="off" value="" class="loss-input" style="width: 200px;">&nbsp;&nbsp;{{ trans('lottery_money.condi.loss_money.cd4e') }}
              </div></div>
            </div>

            <div class="luccon" style="display:none;">
              <div class="layui-form-item condilucky_money"><label class="layui-form-label">{{ trans('lottery_money.condi.lucky_money.cd1') }}</label><div class="layui-input-block">
                    <input type="text" name="cd1-0" id="cd1-0" required  lay-verify="" placeholder="" autocomplete="off" value="" class="loss-input" style="width: 200px;">&nbsp;&nbsp;{{ trans('lottery_money.condi.lucky_money.cd1e') }}
              </div></div>

              <div class="layui-form-item condilucky_money"><label class="layui-form-label">{{ trans('lottery_money.condi.lucky_money.cd2') }}</label><div class="layui-input-block">
                    <input type="text" name="cd2-0" id="cd2-0" required  lay-verify="" placeholder="" autocomplete="off" value="" class="loss-input" style="width: 200px;">&nbsp;&nbsp;{{ trans('lottery_money.condi.lucky_money.cd2e') }}
              </div></div>

              <div class="layui-form-item condilucky_money"><label class="layui-form-label">{{ trans('lottery_money.condi.lucky_money.cd3') }}</label><div class="layui-input-block">
                    <input type="text" name="cd3-0" id="cd3-0" required  lay-verify="" placeholder="" autocomplete="off" value="" class="loss-input" style="width: 200px;">&nbsp;&nbsp;{{ trans('lottery_money.condi.lucky_money.cd3e') }}
              </div></div>
            </div>
            <div class="layui-form-item addbut"  @if(isset($data['type'])&& ($data['type']=='lucky_money' || $data['type']=='loss_money')) data-type="{{$data['type']}}" @else style="display: none;" @endif>
              <div class="layui-input-block">
                <label class="layui-form-label addcondi" @if(isset($data['type'])&& ($data['type']=='lucky_money' || $data['type']=='loss_money')) data-type="{{$data['type']}}"@endif data-id="{{isset($data['kid'])?$data['kid']:1}}" onclick="addcondi()">添加条件+</label>
                &nbsp;&nbsp;
                <label class="layui-form-label delcondi" data-id="{{isset($data['kid'])?$data['kid']:1}}" onclick="delcondi()">删除条件-</label>
              </div>
            </div>


    <div class="layui-form-item condi sign_money"  @if(!isset($data['type']) || $data['type']!='sign_money') style="display: none;" @endif>
        <label class="layui-form-label">{{ trans('lottery_money.condi.sign_money.min_money') }}</label>
        <div class="layui-input-block">
            <input type="text" name="cd[min_money]" id="cd1-min_money" lay-verify="" placeholder="" autocomplete="off"
                   value="" class="loss-input" style="width: 200px;">
        </div>
        <label class="layui-form-label">{{ trans('lottery_money.condi.sign_money.max_money') }}</label>
        <div class="layui-input-block">
            <input type="text" name="cd[max_money]" id="cd1-max_money" lay-verify="" placeholder="" autocomplete="off"
                   value="" class="loss-input" style="width: 200px;">
        </div>
    </div>

    <div class="layui-form-item condi night_join"  @if(!isset($data['type']) || $data['type']!='night_join') style="display: none;" @endif>
        <label class="layui-form-label">{{ trans('lottery_money.condi.night_join.cd1') }}</label>
        <div class="layui-input-block">
            <input type="text" name="night_join[star_time]" id="cd1-star_time"  @if(isset($data['type']) && $data['type']=='night_join') required @endif lay-verify="" placeholder="" autocomplete="off"
                   value="@isset($data['condi']['star_time']) {{ $data['condi']['star_time'] }} @endisset" class="loss-input" style="width: 200px;">
        </div>
        <label class="layui-form-label">{{ trans('lottery_money.condi.night_join.cd2') }}</label>
        <div class="layui-input-block">
            <input type="text" name="night_join[end_time]" id="cd1-end_time" @if(isset($data['type']) && $data['type']=='night_join') required @endif lay-verify="" placeholder="" autocomplete="off"
                   value="@isset($data['condi']['end_time']) {{ $data['condi']['end_time'] }} @endisset" class="loss-input" style="width: 200px;">&nbsp;&nbsp;{{ trans('lottery_money.condi.night_join.cd2e') }}
        </div>
    </div>


@if(S('ACTION')!='view')
  <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-green">重置</button>
    </div>
  </div>
@endif
</form>

<script>
//Demo

  var condiloss_money = $('.loscon').html();
  var condilucky_money = $('.luccon').html();
var dt = '';

//添加条件
function addcondi(){
  var did = $('.addcondi').attr('data-id');
  if(did>=10){
    layer.msg('最多添加十项条件');
    return false;
  }
  var mat = parseInt(did)-1;
  var ac = $('.addcondi').attr('data-type');
  if(dt==''){
    if(ac=='loss_money'){
      condiloss_moneyt = condiloss_money.replace(/-0/g, "-"+did);
      $('.addbut').before(condiloss_moneyt);
    }else if(ac=='lucky_money'){
      condilucky_moneyt = condilucky_money.replace(/-0/g, "-"+did);
      $('.addbut').before(condilucky_moneyt);
    }
  }else if(dt=='loss_money'){
      condiloss_moneyt = condiloss_money.replace(/-0/g, "-"+did);
    $('.addbut').before(condiloss_moneyt);
  }else if(dt=='lucky_money'){
      condilucky_moneyt = condilucky_money.replace(/-0/g, "-"+did);
    $('.addbut').before(condilucky_moneyt);
  }
  $('.addcondi').attr('data-id',parseInt(did)+1);
}

//删除条件
function delcondi(){
  var did = $('.addcondi').attr('data-id');
  if(did<=1){
    layer.msg('至少包含一项条件');
    return false;
  }
  var mat = parseInt(did)-1;
  var dstr = '-'+mat;
  $("input[id$='"+dstr+"']").parent().parent().remove();
  
  $('.addcondi').attr('data-id',mat);
  $('.delcondi').attr('data-id',mat);
}

layui.use(['form'], function(){
  var form = layui.form;
  $('.loscon').remove();
  $('.luccon').remove();
  var codistr = '';
  form.on('select(testSelect)', function(data){
     console.log(data.value);
     dt = data.value;
     if (data.value=='join' || data.value=='month_join' || data.value=='week_join' || data.value=='loss_money'|| data.value=='day_join') {
          $('.single').show();
          // $('#labels').hide();
     }else{
         $('.single').hide();
         // $('#labels').show();
     }
     if(data.value=='sign_money'){
         $('.sign_money').show();
     }else{
         $('.sign_money').hide();
     }
     if(data.value=='night_join'){
        $('.night_join').show();
     }else{
        $('.night_join').hide();
     }
     
     if (data.value=='loss_money') {
          $('.loss_money').show();
          $('.extrcon').after(condiloss_money);
     }else{
         $('.condiloss_money').remove();
         $('.loss_money').hide();
     }
     if (data.value=='lucky_money') {
          $('.lucky_money').show();
          $('.extrcon').after(condilucky_money);
     }else{
          $('.condilucky_money').remove();
         $('.lucky_money').hide();
     }
     if (data.value=='lucky_money' || data.value=='loss_money') {
          $('.addcondi').show();
          $('.addbut').show();
          $('.extrcon').show();
     }else{
          $('.extrcon').hide();
          $('.addbut').hide();
         $('.addcondi').hide();
     }
  });

  //监听提交
  form.on('submit(submitForm)', function(data){
    return true;
  });
});
layui.use('laydate', function(){
  var laydate = layui.laydate;
  
  //时间选择器
  laydate.render({
    elem: '#cd1-star_time'
    ,type: 'time'
  });

  //时间选择器
  laydate.render({
    elem: '#cd1-end_time'
    ,type: 'time'
  });
});

lay('.test-item').each(function(){
    laydate.render({
        elem: this
        ,type: 'datetime'
        ,trigger: 'click'
    });
});
</script>
@endsection
