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


    <div id="myMsg" CLASS="layui-col-xs12">
        <form class="layui-form" action="{{ url()->full() }}" id="submitForm" name="submitForm" method="post"
              eventType=eventAjaxForm  enctype="multipart/form-data">
            {!! csrf_field() !!}

            <div class="layui-form-item">
                <label class="layui-form-label">红包文件</label>
                <div class="layui-input-block">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-normal" id="test8">选择文件</button>
                        <button type="button" class="layui-btn" id="test9">开始上传</button>
                    </div>
                    <input type="hidden" name="path" id="path" value="">
                    <!--<button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件</button>-->
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">红包理由</label>
                <div class="layui-input-block">
                    <input type="text" name="reason_info"  lay-verify="required" placeholder="请输入红包理由" autocomplete="off"
                           class="layui-input" value="">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">红包类型</label>
                <div class="layui-input-block">
                    <select name="type">
                        @foreach($type as $k=>$v)
                            <option value="{{$k}}">{{$v}}</option>
                        @endforeach
                    </select>
                </div>
            </div>

            {{--<div class="layui-form-item">--}}
            {{--<label class="layui-form-label">红包规则</label>--}}
            {{--<div class="layui-input-block">--}}
            {{--<input type="text" name="rule"  placeholder="请输入红包理由" autocomplete="off"--}}
            {{--class="layui-input" value="">--}}
            {{--</div>--}}
            {{--</div>--}}

            <div class="layui-form-item">
                <label class="layui-form-label">二级密码</label>
                <div class="layui-input-inline" >
                    <input type="password" name="password" lay-verify="" autocomplete="off" class="layui-input" value="">
                </div>
            </div>

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

    <script>
        //Demo
        layui.use(['form', 'laydate','upload'], function () {
            var form = layui.form
                , layer = layui.layer
                ,upload = layui.upload
                , laydate = layui.laydate;
            //文件上传渲染
            var uploadInst = upload.render({
                elem: '#test8' //绑定元素
                ,method:'post'
                ,field:'file'
                ,exts:'csv'
                ,auto:false
                ,bindAction:'#test9'
                ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                    layer.load(); //上传loading
                }
               // ,data:{reason_info:reason_info,password:password}
                ,url: '/admin/redbag/upload' //上传接口
                ,done: function(data){
                    console.log(data);
                    //上传完毕回调
                    layer.closeAll('loading'); //关闭loading
                    var html='<span class="layui-btn layui-btn-fluid">文件：'+data.data.name+'已上传成功<span>';
                    $('.layui-upload').html(html);
                    $('#path').val(data.data.path);
                    layer.msg(data.msg);
                }
                ,error: function(){
                    //请求异常回调
                    layer.closeAll('loading'); //关闭loading
                    layer.msg('接口异常');
                }
            });
            form.verify({
            });
            //监听提交
            form.on('submit(submitForm)', function (data) {
                return true;
            });


        });
        //返回数据处理
        function cbFormSuccess(data) {
            console.log(data);
            var val=data.data;
            var str='';
//            if(val==''||val==undefined||val==null){
//                layer.alert('成功',{},function () {
//                    window.history.go(-1);
//                });
//                return ;
//            }
            str+='<div class=" layui-elem-field" style="font-size: 20px;">';
            str+='<p>操作条数：'+val.total+';</p><p>成功条数:'+val.success+'</p><p>失败条数:'+val.fail+'</p>';
            if(val.fail>0){
                str+='<p>失败信息如下:</p>';
                var array=val.error;
                $(array).each(function (i,n) {
                    str+='<p>'+n+'</p>';
                });
            }
            str+='</div>';
            $('#myMsg').html(str);
//            layer.open({
//                type: 1
//                ,title: false //不显示标题栏
//                ,area: '300px;'
//                ,shade: 0.8
//                ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
//                ,btnAlign: 'c'
//                ,btn: ['确认']
//                ,moveType: 1 //拖拽模式，0或者1
//                ,content: str
//                ,yes: function(){
//                    layer.closeAll();
//                    window.location.reload()
//                }
//            });
        }

    </script>
@endsection
