@extends('vip.layouts')
@section('seo_title',$title)
@php
    if(!isset($data['sign_type'])){
    $data['sign_type']='MD5';
    }
@endphp
@section('content')
    <link href={{ asset("baidu/themes/default/css/umeditor.css") }} type="text/css" rel="stylesheet">
    <form class="layui-form"
          action="/payment/gatewayHandler?id={{$_GET['id']??''}}"
          id="submitForm" name="submitForm" method="post" eventType="eventAjaxForm">
        {!! csrf_field() !!}
        <div class="layui-form-item">
            <label class="layui-form-label" for="gateway_name">{{trans('pay_gateway.gateway_name')}}</label>
            <div class="layui-input-inline">
                <input type="text" name="gateway_name" id="gateway_name" required
                       lay-verify="required"
                       autocomplete="off"
                       class="layui-input"
                       value="{{isset($data['gateway_name'])?$data['gateway_name']:''}}"/>
            </div>
            <div class="layui-form-mid layui-word-aux">网关名称描述</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" for="status">{{trans('pay_gateway.status')}}</label>
            <div class="layui-input-block">
                <input type="checkbox" name="status" id="status"
                       class="layui-form-checkbox" {{isset($data['status'])&&$data['status']==1?'checked':''}}
                       value="1">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" for="gateway_identifier">{{trans('pay_gateway.gateway_identifier')}}</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="gateway_identifier" id="gateway_identifier" required
                       lay-verify="required"
                       placeholder="请联系平台方获取，确保填写无误"
                       value="{{$data['gateway_identifier']??''}}"/>
            </div>
            <label class="layui-form-mid layui-word-aux" for="gateway_identifier">接口标识描述(接口类名，不带Payment后缀)</label>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{{trans('pay_gateway.gateway_type_id')}}</label>
            <div class="layui-input-inline">
                <select name="gateway_type_id" class="layui-select">
                    @foreach($gateway_type as $k=>$v)
                        <option value="{{$v->id}}"
                                @if(isset($data['gateway_type_id']) && $data['gateway_type_id']==$v->id) selected @endif>{{$v->typename}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" for="gateway_code">{{trans('pay_gateway.gateway_code')}}</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="gateway_code" id="gateway_code" required
                       lay-verify="required"
                       value="{{$data['gateway_code']??''}}"/>
            </div>
            <label class="layui-form-mid layui-word-aux" for="gateway_code">网关标识名称</label>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" for="order_prefix">{{trans('pay_gateway.order_prefix')}}</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="order_prefix" id="order_prefix"
                       value="{{$data['order_prefix']??''}}"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" for="merchant_id">{{trans('pay_gateway.merchant_id')}}</label>
            <div class="layui-input-block">
                <input type="text" name="merchant_id" id="merchant_id" required lay-verify="required"
                       class="layui-input"
                       value="{{isset($data['merchant_id'])?$data['merchant_id']:''}}">
            </div>

        </div>
        <div class="layui-form-item single">
            <label class="layui-form-label">{{trans('pay_gateway.term_no')}}</label>
            <div class="layui-input-block">
                <input type="text" name="term_no" id="term_no" autocomplete="off"
                       class="layui-input"
                       value="{{isset($data['term_no'])?$data['term_no']:''}}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{{trans('pay_gateway.sign_type')}}</label>
            <div class="layui-input-inline">
                <select class="layui-select" name="sign_type" id="sign_type">
                    <option></option>
                    <option value="MD5" @if('MD5'==$data['sign_type'])selected @endif >MD5</option>
                    <option value="RSA" @if('RSA'==$data['sign_type'])selected @endif >RSA</option>
                </select>
            </div>

        </div>
        <div class="layui-form-item single">
            <label class="layui-form-label"
                   for="merchant_md5_secret">{{trans('pay_gateway.merchant_md5_secret')}}</label>
            <div class="layui-input-block">
                <input type="text" name="merchant_md5_secret" id="merchant_md5_secret"
                       autocomplete="off"
                       class="layui-input"
                       value="{{isset($data['merchant_md5_secret'])?$data['merchant_md5_secret']:''}}">
            </div>
        </div>
        <div class="layui-form-item single">
            <label class="layui-form-label" for="server_pub_key">{{trans('pay_gateway.server_pub_key')}}</label>
            <div class="layui-input-block">
                <textarea name="server_pub_key" id="server_pub_key"
                          class="layui-textarea">{{isset($data['server_pub_key'])?$data['server_pub_key']:''}}</textarea>
            </div>
        </div>
        <div class="layui-form-item single">
            <label class="layui-form-label">{{trans('pay_gateway.merchant_pub_key')}}</label>
            <div class="layui-input-block">
                <textarea name="merchant_pub_key" id="merchant_pub_key"
                          class="layui-textarea">{{isset($data['merchant_pub_key'])?$data['merchant_pub_key']:''}}</textarea>
            </div>
        </div>
        <div class="layui-form-item single">
            <label class="layui-form-label" for="merchant_pri_key">{{trans('pay_gateway.merchant_pri_key')}}</label>
            <div class="layui-input-block">
                <textarea name="merchant_pri_key" id="merchant_pri_key"
                          class="layui-textarea">{{isset($data['merchant_pri_key'])?$data['merchant_pri_key']:''}}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" for="en_jump">{{trans('pay_gateway.en_jump')}}</label>
            <div class="layui-input-block">
                <input type="checkbox" name="en_jump" id="en_jump" autocomplete="off"
                       class="layui-form-checkbox" {{isset($data['en_jump'])&&$data['en_jump']==1?'checked':''}}
                       value="1" lay-filter="en_jump">
            </div>
        </div>
        <div class="layui-form-item single" id="jurl_model" style="display: {{isset($data['en_jump'])&&$data['en_jump']==1?'block':'none'}}">
            <label class="layui-form-label">{{trans('pay_gateway.jump_url')}}</label>
            <div class="layui-input-block">
                <input type="text" name="jump_url" id="jump_url" autocomplete="off"
                       class="layui-input"
                       placeholder="请输入正确的地址，如https://www.baidu.com"
                       value="{{isset($data['jump_url'])?$data['jump_url']:''}}">
            </div>
        </div>
        <div class="layui-form-item single">
            <label class="layui-form-label" for="callback_url">{{trans('pay_gateway.callback_url')}}</label>
            <div class="layui-input-block">
                <input type="text" name="callback_url" autocomplete="off"
                       class="layui-input"
                       placeholder="如无特殊设定不用填写，如有填写请确保写入的地址外网可访问！"
                       value="{{isset($data['callback_url'])?$data['callback_url']:''}}">
            </div>
        </div>
        <div class="layui-form-item single">
            <label class="layui-form-label" for="notify_url">{{trans('pay_gateway.notify_url')}}</label>
            <div class="layui-input-inline">
                <input type="text" name="notify_url" id="notify_url" autocomplete="off"
                       class="layui-input"
                       placeholder="如无特殊设定不用填写，如有填写请确保写入的地址外网可访问！"
                       value="{{isset($data['notify_url'])?$data['notify_url']:''}}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" for="rand_price">{{trans('pay_gateway.rand_price')}}</label>
            <div class="layui-input-block">
                <input type="checkbox" name="rand_price" id="rand_price" autocomplete="off"
                       class="layui-form-checkbox" {{isset($data['rand_price'])&&$data['rand_price']==1?'checked':''}}
                       value="1">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" for="price_list">{{trans('pay_gateway.price_list')}}</label>
            <div class="layui-input-inline">
                <input type="text" name="price_list" id="price_list" autocomplete="off"
                       class="layui-input"
                       value="{{isset($data['price_list'])?$data['price_list']:''}}">
            </div>
            <div class="layui-form-mid layui-word-aux">备注：多个金额用'||'隔开</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" for="min_price">{{trans('pay_gateway.min_price')}}</label>
            <div class="layui-input-inline">
                <input type="text" name="min_price" id="min_price" autocomplete="off"
                       class="layui-input"
                       value="{{isset($data['min_price'])?$data['min_price']:0}}">
            </div>
            <div class="layui-form-mid layui-word-aux">备注：0为不限制</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" for="max_price">{{trans('pay_gateway.max_price')}}</label>
            <div class="layui-input-inline">
                <input type="text" name="max_price" id="max_price" autocomplete="off"
                       class="layui-input"
                       value="{{isset($data['max_price'])?$data['max_price']:0}}">
            </div>
            <div class="layui-form-mid layui-word-aux">备注：0为不限制</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" for="comment_fields">{{trans('pay_gateway.comment_fields')}}</label>
            <div class="layui-input-inline">
                <input type="text" name="comment_fields" id="comment_fields" autocomplete="off"
                       class="layui-input"
                       placeholder="填写格式：参数名||参数说明,多个参数请用逗号分隔,如:remark,||备注,remake1||备注1"
                       value="{{isset($data['comment_fields'])?$data['comment_fields']:''}}">
            </div>
            <div class="layui-form-mid layui-word-aux">填写格式：参数名||参数说明,多个参数请用逗号分隔,如:remark,||备注,remake1||备注1</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', 'layer'], function () {
            var form = layui.form, layer = layui.layer;

            form.verify({
                gateway_name: function (value) {
                    if (value.length < 5) {
                        return '标题至少得5个字符啊';
                    }
                },
            });
            form.on('checkbox(en_jump)', function(obj){
                var check = obj.elem.checked;
                if(check){
                    $("#jurl_model").css('display','block');
                }else{
                    $("#jurl_model").css('display','none');
                }
            });

            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) {
                // alert($('#sign_type'));
                if ($('#en_jump').is(':checked') == 1) {
                    if ($('#jump_url').val() == '') {
                        layer.msg('请输入跳转地址');
                        $('#jump_url').focus();
                        return false;
                    }
                }
                if ($('#sign_type').val() === 'MD5' && $('#merchant_md5_secret').val() === '') {
                    layer.msg('MD5密钥不能为空');
                    $('#merchant_md5_secret').focus();
                    return false;
                }
                var min_price = parseFloat($("#min_price").val());
                var max_price = parseFloat($("#max_price").val());
                if(min_price >0 && max_price > 0 && (min_price > max_price || min_price == max_price)){
                    layer.msg('最大付款金额必须大于最小付款金额');
                    $('#max_price').focus();
                    return false;
                }
                return true;
            });


        })
        ;

        //创建一个编辑器
        function cbFormSuccess(data) {
            layer.msg(data.msg);
            window.location.href='/payment/gateways';
        }
    </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>