@extends('vip.layouts')
@section('content')
    @php
        if(!isset($data))$data=[];
        if(!isset($_GET['id']))$_GET['id']='';
    @endphp
    {{--@php--}}
    {{--dd($gateway_type);--}}
    {{--@endphp--}}
    <link href={{ asset("baidu/themes/default/css/umeditor.css") }} type="text/css" rel="stylesheet">
    <form class="layui-form"
          action="/payment/channelHandler?id={{$_GET['id']}}"
          id="submitForm" name="submitForm" method="post" eventType=eventAjaxForm>
        {!! csrf_field()!!}
        @isset($data['id'])<input type="hidden" name="id" value="{{$data['id']}}"/>@endisset
        <div class="layui-form-item">
            <label class="layui-form-label">{{trans('pay_channels.channel_name')}}</label>
            <div class="layui-input-inline">
                <input type="text" name="channel_name" required lay-verify="required" autocomplete="off"
                       class="layui-input"
                       {{--@isset($data['channel_name']) disabled @endisset--}}
                       value="{{isset($data['channel_name'])?$data['channel_name']:''}}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{{trans('pay_channels.channel_type')}}</label>
            <div class="layui-input-block">
                <select class="layui-form-select" name="channel_type" id="channel_type">
                    <option value="1"
                            @isset($data['channel_type'])@if($data['channel_type']==1) selected @endif @endisset>PC通道
                    </option>
                    <option value="2"
                            @isset($data['channel_type'])@if($data['channel_type']==2) selected @endif @endisset>WAP通道
                    </option>
                    <option value="3"
                            @isset($data['channel_type'])@if($data['channel_type']==3) selected @endif @endisset>网银通道
                    </option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{{trans('pay_channels.typename')}}</label>
            <div class="layui-input-inline">
                <select name="channel_type_id" class="layui-select">
                    @foreach($channel_type_list as $k=>$v)
                        <option value="{{$v->id}}"
                                @if(isset($data['channel_type_id']) && $data['channel_type_id']==$v->id) selected @endif>{{$v->typename}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{{trans('pay_channels.gateway_name')}}</label>
            <div class="layui-input-inline">
                <select class="layui-select" id="gateway_id" name="gateway_id">
                    @foreach($gateway_list as $k=>$v)
                        <option value="{{$v->id}}"
                                @if(isset($data['gateway_id'])&&$data['gateway_id']==$v->id) selected @endif>{{$v->id}}:{{$v->gateway_name}}</option>
                    @endforeach
                </select>
            </div>
            <div class="layui-input-inline">
                <input type="text" id="search_gateway_name" class="layui-input" style="width:200px;float:left;" placeholder="请输入网关名称">
                <a class="layui-btn " style="opacity:1;pointer-events:auto;float:left;" onclick="searchGatewayName()">搜索</a>
            </div>

        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">{{trans('pay_channels.channel_group')}}</label>
            @foreach($group_list as $k=>$v)
                <div class="layui-input-inline" style="width:10% !important;">
                    {{$v['group_name']}}:<input type="checkbox" name="channel_group[]"
                                                class="layui-form-checkbox"
                                                value="{{$v['id']}}" {{$v['check']==1?'checked':''}}>
                </div>
            @endforeach


        </div>

        <div class="layui-form-item single">
            <label class="layui-form-label">{{trans('pay_channels.channel_code')}}</label>
            <div class="layui-input-inline">
                <input type="text" name="channel_code" required lay-verify="required" autocomplete="off"
                       class="layui-input"
                       placeholder="请填写前端展示的通道logo标示！"
                       value="{{isset($data['channel_code'])?$data['channel_code']:''}}">
            </div>
        </div>
        <div class="layui-form-item single">
            <label class="layui-form-label">{{trans('pay_channels.banner')}}</label>
            <div class="layui-input-inline">
                <input type="text" name="banner"  lay-verify="" autocomplete="off"
                       class="layui-input"
                       placeholder="请填写前端展示的通道图片地址！"
                       value="{{isset($data['banner'])?$data['banner']:''}}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" for="gift_price_rate">{{trans('pay_channels.gift_price_rate')}}</label>
            <div class="layui-input-inline">
                <input type="text" name="gift_price_rate" id="gift_price_rate" autocomplete="off"
                       class="layui-input"
                       value="{{isset($data['gift_price_rate'])?$data['gift_price_rate']:''}}">
            </div>
            <div class="layui-form-mid layui-word-aux">填写规则：满足金额||优惠百分比，如：（100||10）</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" for="gift_black_list">{{trans('pay_channels.gift_black_list')}}</label>
            <div class="layui-input-inline">
                <input type="text" name="gift_black_list" id="gift_black_list" autocomplete="off"
                       class="layui-input"
                       value="{{isset($data['gift_black_list'])?$data['gift_black_list']:''}}">
            </div>
            <div class="layui-form-mid layui-word-aux">备注：多个优惠黑名单用'||'隔开</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" for="black_list">{{trans('pay_channels.black_list')}}</label>
            <div class="layui-input-inline">
                <input type="text" name="black_list" id="black_list" autocomplete="off"
                       class="layui-input"
                       value="{{isset($data['black_list'])?$data['black_list']:''}}">
            </div>
            <div class="layui-form-mid layui-word-aux">备注：多个支付黑名单用'||'隔开</div>
        </div>

        {{--
               <div>
                   <label class="layui-form-label"></label>
                   <div class="layui-form-mid layui-word-aux" style="display: inline-block">
                       用于前台显示图片的信息对应的控制对应图片地址不需要修改，分层注意靠这个代码，代码相同的才能设置为一个分层1，一个分层2
               </div>
               </div>
       {{--
               <div class="layui-form-item">
                   <label class="layui-form-label">通道分层</label>
                   <div class="layui-input-inline">
                       <input type="number" name="ceng" required lay-verify="required" autocomplete="off"
                              class="layui-input"
                              value="{{isset($data['ceng'])?$data['ceng']:''}}">
                   </div>

               </div>
               <div>
                   <label class="layui-form-label"></label>
                   <div class="layui-form-mid layui-word-aux" style="display: inline-block">重要：至少定义了两层及以上同个 通道代码
                       的通道才能分层，分层后按顺序控制1、2、3在这里定义即可，会员分层许程序配合控制，如果定义为0，则其他分层不可开启状态，分层控制一定要有1才能有效。！
                   </div>
               </div>
       --}}

        <div class="layui-form-item single">
            <label class="layui-form-label">{{trans('pay_channels.channel_status')}}</label>
            <div class="layui-input-block">
                <input type="checkbox" name="channel_status" id="channel_status"
                       class="layui-form-checkbox"
                       value="1" {{isset($data['channel_status']) && $data['channel_status'] ?'checked':''}}>
            </div>
        </div>
    <!-- <div class="layui-form-item single">
            <label class="layui-form-label">网银通道代码</label>
            <div class="layui-input-block">
                <input type="text" name="netbank_code" id="netback_code" required lay-verify="required"
                       autocomplete="off"
                       class="layui-input"
                       value="{{isset($data['netbank_code'])?$data['netbank_code']:''}}">
            </div>
        </div>
        <div><label class="layui-form-label"></label>
            <div class="layui-form-mid layui-word-aux">重要：注意 优先使用的是对应网关的
                支付通道代码，这里一般是银联网银类型的不同银行代码设置！每个网关接口对应的通道代码不太一样，针对不同可独立设置！
            </div>
        </div> -->
        <div class="layui-form-item single">
            <label class="layui-form-label">{{trans('pay_channels.channel_sort')}}</label>
            <div class="layui-input-block">
                <input type="number" name="channel_sort" id="channel_sort" required lay-verify="required"
                       autocomplete="off"
                       class="layui-input"
                       value="{{isset($data['channel_sort'])?$data['channel_sort']:'1'}}">
            </div>
        </div>
        <div class="layui-form-item single">
            <label class="layui-form-label" for="channel_remark">{{trans('pay_channels.channel_remark')}}</label>
            <div class="layui-input-block">
            <textarea name="channel_remark" id="channel_remark" autocomplete="off"
                      class="layui-textarea">{{isset($data['channel_remark'])?$data['channel_remark']:''}}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                @if(checkRriv('/admin/money/changeWithDrawRule'))
                    <button class="layui-btn" lay-submit lay-filter="submitForm">立即提交</button>@endif
                <button type="reset" class="layui-btn layui-btn-normal">重置</button>
            </div>
        </div>
    </form>
    <script type="text/javascript" src={{ asset("baidu/third-party/jquery.min.js") }}></script>
    <script type="text/javascript" charset="utf-8" src={{ asset("baidu/umeditor.config.js") }}></script>
    <script type="text/javascript" charset="utf-8" src={{ asset("baidu/umeditor.min.js") }}></script>
    <script type="text/javascript" src={{ asset("baidu/lang/zh-cn/zh-cn.js") }}></script>
    <script>
        //Demo
        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;
            //执行一个laydate实例
            laydate.render({
                elem: '#start_time' //指定元素
            });
            laydate.render({
                elem: '#end_time' //指定元素
            });
            //图片上传接口
            layedit.set({
                uploadImage: {
                    url: '/admin/notice/upImg' //接口url
                    , type: 'post' //默认post
                }
            });
            //var um = UM.getEditor('myEditor');
            var um = UM.getEditor('myEditor', {
                initialFrameWidth: 1000,
                initialFrameHeight: 400
            });
            /*var editIndex = layedit.build('LAY_demo_editor');*/
            form.verify({
                title: function (value) {
                    if (value.length < 5) {
                        return '标题至少得5个字符啊';
                    }
                }
                , pass: [/(.+){6,12}$/, '密码必须6到12位']
                , content: function (value) {
                    layedit.sync(editIndex);
                }
            });
            form.on('select(testSelect)', function (data) {
                if (data.value == 20) {
                    $('.single').show();
                } else {
                    $('.single').hide();
                }

                if (data.value == 3) {
                    $('.dum').show();
                } else {
                    $('.dum').hide();
                }
            });

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


        });

        //创建一个编辑器
        function cbFormSuccess(data) {
            layer.msg(data.msg);
            window.location.href='/payment/channels';
        }
    </script>
            <script>
            function searchGatewayName(){
                var keyword=$("#search_gateway_name").val();
                $.get('/payment/search_gateway_name?keyword='+keyword,function(data){
                    data = JSON.parse(data);
                    if(data){
                        var cf = '';
                        $.each(data,function(i,p){
                            cf += '<option value="'+p.id+'">'+p.id+':'+p.gateway_name+'</option>';
                        })
                        $("#gateway_id").html(cf);
                        renderForm();//表单重新渲染，要不然添加完显示不出来新的option
                        layer.close(index);
                    }
                })
            }
            //重新渲染表单
            function renderForm(){
              layui.use(['form'], function () {
               var form = layui.form;//高版本建议把括号去掉，有的低版本，需要加()
               form.render();

              });
             }

        </script>
@endsection

<style>
    label.layui-form-label {
        width: 100px;
    }

    .layui-form-item .layui-input-inline {

        width: 40% !important;
    }

    .layui-input-block {
        width: 40% !important;
        margin-left: 0 !important;
        display: inline-block;
    }
</style>
