<#assign base=request.contextPath />
<#import "../common/defaultLayout.ftl" as defaultLayout>
<@defaultLayout.layout>
    <link rel="stylesheet" href="../assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="../assets/css/amazeui.switch.css"/>

    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">配置管理</strong> /
                    <small>项目利润率配置</small></div>
            </div>
            <form method="post" class="am-form" id="tmpForm" action="${base}/sys/config/save">
                <!--选项卡（tabs）begin-->
                <div class="am-tabs am-margin" data-am-tabs>
                    <ul class="am-tabs-nav am-nav am-nav-tabs">
                        <li class="am-active">

                        </li>
                    </ul>
                    <div class="am-tabs-bd">
                        <div class="am-tab-panel am-fade am-in am-active" id="tab1">
                            <input name="tId" id="tId" type="hidden" value="${tId!}"/>
                            <!--验证表单元素（validate) begin-->
                            <!--input begin-->

                            <div class="am-g am-form-group am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                    <span style="color: red;">*</span>项目贡献利润率阀值：
                                </div>
                                <div class="am-u-sm-6 am-u-md-6">
                                    <input name="projectContributionProfitRateThreshold" class="js-ajax-validate"
                                           data-validate-async data-validation-message="请输入项目贡献利润率阀值"
                                           type="number" id="projectContributionProfitRateThreshold" value="${projectContributionProfitRateThreshold!}"
                                           minlength="1" step="0.01"
                                           <#--oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,6})?).*$/g, '$1')"-->
                                           maxlength="10" placeholder="请输入项目贡献利润率阀值" required/>
                                </div>%   注：请注意保留小数点后两位
                                <div class="am-u-sm-2 am-u-md-4 input-msg"></div>
                            </div>

                            <div class="am-g am-form-group am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                    <span style="color: red;">*</span>设置项目年利率：
                                </div>
                                <div class="am-u-sm-6 am-u-md-6">
                                    <input name="underwrittenTaxRate" class="js-ajax-validate"
                                           data-validate-async data-validation-message="请输入项目年利率"
                                           type="number" id="underwrittenTaxRate" value="${underwrittenTaxRate!}"
                                           minlength="1" step="0.01"
                                           <#--oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,6})?).*$/g, '$1')"-->
                                           maxlength="10" placeholder="请输入项目年利率" required/>
                                </div>%   注：请注意保留小数点后两位
                                <div class="am-u-sm-2 am-u-md-4 input-msg"></div>
                            </div>
                        </div>
                    </div>
                </div>

                <!--选项卡（tabs）end-->
                <div class="am-margin">
                    <button type="button" class="am-btn am-btn-primary am-btn-xs" onclick="submit_function()">提交保存</button>
                    <#--<button type="button" class="am-btn am-btn-warning am-btn-xs"
                            onclick="javascript:history.go(-1);">返回上一级
                    </button>-->
                </div>
            </form>
        </div>
    </div>

</@defaultLayout.layout>
<script src="../assets/js/amazeui.switch.js"></script>
<script type="text/javascript">
    var urlBase = "${base}";
    var url;

    var submit_function = function () {
        var projectContributionProfitRateThreshold = $("#projectContributionProfitRateThreshold").val();
        var underwrittenTaxRate = $("#underwrittenTaxRate").val();
        var params = {
            projectContributionProfitRateThreshold: projectContributionProfitRateThreshold,
            underwrittenTaxRate: underwrittenTaxRate
        };
        $.ajax({
            url: '${base}/sys/config/save',
            data: JSON.stringify(params),
            dataType: "json",
            contentType: "application/json",
            type: 'post',
            async: false,
            success: function (data) {
                if (data.status == 0) {
                    layer.alert("配置成功");
                    window.location.href = window.location.href;
                } else if (data.status == 1) {
                    layer.alert(data.msg);
                }
            }
        });
    }

    $(function () {
        /*表单验证：begin*/
        //自定义规则，用法：验证元素上加class="js-pattern-sort"
        if ($.AMUI && $.AMUI.validator) {
            $.AMUI.validator.patterns.sort = /^([0-9]+)$/;
        }
        $("#tmpForm").validator({
            // 域通过验证时回调
            onValid: function (validity) {
                $(validity.field).closest('.am-form-group').find('.am-alert').hide();
            },
            // 域验证通过时添加的操作，通过该接口可定义各种验证提示
            markValid: function (validity) {
                // this is Validator instance
                var $field = $(validity.field);
                //add by zxl，只对有required属性的字段进行验证
                if (typeof ($field.attr("required")) != "undefined") {
                    var options = this.options;
                    var $parent = $field.closest('.am-form-group');
                    $field.addClass(options.validClass).removeClass(options.inValidClass);

                    $parent.addClass('am-form-success').removeClass('am-form-error');

                    options.onValid.call(this, validity);
                }
            },
            // 验证出错时的回调， validity 对象包含相关信息，格式通 H5 表单元素的 validity 属性
            onInValid: function (validity) {
                var $field = $(validity.field);
                var $group = $field.closest('.am-form-group');
                var $alert = $group.find('.am-alert');
                // 使用自定义的提示信息 或 插件内置的提示信息
                var msg = $field.data('validationMessage') || this.getValidationMessage(validity);

                if (!$alert.length) {
                    $alert = $("<div class='am-alert am-alert-danger'></div>").hide().appendTo($group.find(".input-msg"));
                }
                console.log("onInValid : " + $field.val());
                $alert.html(msg).show();
            }
        });
        /*表单验证：end*/
    });


</script>
<style type="text/css">
    /*验证：提示信息样式 begin*/
    .am-alert-danger {
        background-color: transparent;
        border-color: transparent;
        color: red;
    }

    .am-alert {
        margin-bottom: 1em;
        padding: .625em;
        background: transparent;
        border: none;
        border-radius: 0;
    }

    /*验证：提示信息样式 end*/
</style>













