@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;
        }

        .inputs {
            float: left;
            display: block;
            width: 13%;
            margin-right: 1%;
            margin-bottom: 10px;
        }
    </style>
    <form class="layui-form" action={{$action}} id="submitForm" name="submitForm" method="post" eventType=eventAjaxForm>
        {!! csrf_field() !!}
        <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>

        <input type="hidden" name="type" value="first_save"/>
        <div class="layui-form-item">
            <label class="layui-form-label">{{ trans('lottery_money.give_type') }}：</label>
            <div class="layui-input-block">
                <input type="radio" name="setup" value="1" checked="true" title="手动申请" checked>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-block">
                <select name="fr_type" id="fr_type" lay-verify="" autocomplete="off" class="layui-input" eventType=event-query>
                    <option value="week" @if(isset($data['fr_type'])&&$data['fr_type']=='week')selected @endif>本周首充</option>
                    <option value="month" @if(isset($data['fr_type'])&&$data['fr_type']=='month')selected @endif>本月首充</option>
                    <option value="first" @if(isset($data['fr_type'])&&$data['fr_type']=='first')selected @endif>开户首充</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <button class="layui-btn" id="addinput" data-type="batchdel">添加</button>
            <label class="layui-form-label">首充范围:</label>
            <div class="layui-input-block addinput" style="margin-bottom: 15px;">
                <div style="margin-top: 5px;">
                    <div class="inputs"><label>优惠等级</label></div>
                    <div class="inputs"><label>最小充值</label></div>
                    <div class="inputs"><label>最大充值</label></div>
                    <div class="inputs"><label>赠送比例(%)</label></div>
                    <div class="inputs"><label>最高上限</label></div>
                    <div class="inputs"><label>流水倍率</label></div>
                    {{--<div class="inputs"><label>截止充值时间</label></div>--}}
                    <div class="inputs"><label>操作</label></div>
                </div>
                @foreach($ranges as $k=>$v)
                    <div class="del{{$k}}">
                        <div class="inputs">
                            <input type="text" name="proportion[{{$k}}][5]" lay-verify="" placeholder="" autocomplete="off"
                                   value="@isset($v[5]){{$v[5]}}@endisset" class="layui-input del-button">
                        </div>
                        <div class="inputs">
                            <input type="number" name="proportion[{{$k}}][0]" lay-verify="" placeholder="" autocomplete="off"
                                   value="@isset($v[0]){{$v[0]}}@endisset" class="layui-input del-button">
                        </div>
                        <div class="inputs">
                            <input type="number" name="proportion[{{$k}}][1]" required lay-verify="" placeholder=""
                                   autocomplete="off"
                                   value="@isset($v[1]){{$v[1]}}@endisset" class="layui-input del-button">
                        </div>

                        <div class="inputs">
                            <input type="number" name="proportion[{{$k}}][2]" required lay-verify="" placeholder=""
                                   autocomplete="off"
                                   value="@isset($v[2]){{$v[2]}}@endisset" class="layui-input del-button">

                        </div>
                        <div class="inputs">
                            <input type="number" name="proportion[{{$k}}][3]" required lay-verify="" placeholder=""
                                   autocomplete="off"
                                   value="@isset($v[3]){{$v[3]}}@endisset" class="layui-input del-button">
                        </div>
                        <div class="inputs">
                            <input type="number" name="proportion[{{$k}}][4]" required lay-verify="" placeholder=""
                                   autocomplete="off"
                                   value="@isset($v[4]){{$v[4]}}@endisset" class="layui-input del-button">
                        </div>

                        <div class="inputs">
                            <button style="background-color: red" class="layui-btn click_del" lay-event="del" onclick="del({{$k}})">删除</button>
                        </div>
                    </div>
                @endforeach
            </div>
            <input type="hidden" name="sort" value="1"/>


        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">申请有效期(小时)：</label>
            <div class="layui-input-block">
                <input type="number" name="fr_time" required lay-verify="" placeholder="" autocomplete="off" class="layui-input" value=@isset($data['fr_time'])
                    {{$data['fr_time']}} @endisset />
            </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>

        function del(id) {
            console.log('del', id);
            $(".del" + id).remove();
        }

        $(function () {
            var i = @php  echo isset($ranges)?count($ranges):0; @endphp;
            $("#addinput").click(function () {
                var j = i++;
                var html = '';
                html = '<div class="del' + j + '">' +
                    "                    <div class=\"inputs\">\n" +

                    "                    <input type=\"text\" name=\"proportion[" + j + "][5]\" lay-verify=\"\" placeholder=\"请输入优惠等级\" " +
                    "autocomplete=\"off\"\n" +
                    "                           value=\"\" class=\"layui-input\" >\n" +
                    "                        </div>\n" +
                    "                <div class=\"inputs\">\n" +

                    "                    <input type=\"number\" name=\"proportion[" + j + "][0]\"  required lay-verify=\"\" placeholder=\"\"\n" +
                    "                           autocomplete=\"off\"\n" +
                    "                           value=\"\" class=\"layui-input\" >\n" +
                    "                </div>\n" +
                    "\n" +
                    "                <div class=\"inputs\">\n" +

                    "                <input type=\"number\" name=\"proportion[" + j + "][1]\"  required lay-verify=\"\" placeholder=\"\"\n" +
                    "                       autocomplete=\"off\"\n" +
                    "                       value=\"\" class=\"layui-input\" >\n" +
                    "\n" +
                    "                </div>\n"
                    + "      <div class=\"inputs\">\n" +
                    "                            <input type=\"number\" name=\"proportion[" + j + "][2]\" required lay-verify=\"\" placeholder=\"\"\n" +
                    "                                   autocomplete=\"off\"\n" +
                    "                                   value=\"\" class=\"layui-input del-button\">\n" +
                    "                        </div>" + "      <div class=\"inputs\">\n" +
                    "                            <input type=\"number\" name=\"proportion[" + j + "][3]\" required lay-verify=\"\" placeholder=\"\"\n" +
                    "                                   autocomplete=\"off\"\n" +
                    "                                   value=\"\" class=\"layui-input del-button\">\n" +
                    "                        </div>" +
                    "                <div class=\"inputs\">\n" +

                    "                <input type=\"text\" name=\"proportion[" + j + "][4]\"  required lay-verify=\"\" placeholder=\"\"\n" +
                    "                       autocomplete=\"off\"\n" +

                    "                       value=\"\" class=\"layui-input\" >\n" +
                    "                </div>" +
                    "<div class=\"inputs\">\n" +
                    "                            <button style=\"background-color: red\" class=\"layui-btn click_del\" lay-event=\"del\" onclick=\"del(" + j + ")" +
                    "\">删除</button>\n" +
                    "</div>" +
                    "                        </div>";

                $(".addinput").append(html);
            });
            if (i == 0) {
                $("#addinput").click();
            }
        })

    </script>
@endsection
