<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="renderer" content="webkit">
    <!-- 移动设备 viewport -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <jsp:include page="../../common.jsp" />
    <style>
        .layui-form-item{
            margin-top: 10px;
        }
        .layui-form{
            width: 70%;
            margin-left: 10%;
        }
    </style>
</head>
<body>
<form class="layui-form" action="">
    <input name="id" value="${entity.id}" hidden/>
    <div class="layui-form-item">
        <label class="layui-form-label">等级名称</label>
        <div class="layui-input-block">
            <input name="levelName" value="${entity.levelName}" autocomplete="off" maxlength="10"  placeholder="等级名称" class="layui-input" lay-verify="required"/>
        </div>
    </div>
     <div class="layui-form-item">
        <label class="layui-form-label">等级Code</label>
        <div class="layui-input-block">
            <input name="levelCode" value="${entity.levelCode}" autocomplete="off" maxlength="20" placeholder="请输入等级Code" class="layui-input" lay-verify="required" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" >所属角色</label>
        <div class="layui-input-block">
            <select class="layui-select" name="roleCode" autocomplete="off" lay-filter="roleCode" lay-verify="required">
                <option value="">请选择</option>
                <c:forEach items="${roleList}" var="role">
                    <option value="${role.roleCode}" ${role.roleCode == entity.roleCode ? 'selected' : ''}>${role.roleName}</option>
                </c:forEach>
            </select>
        </div>
    </div>
    <div class="layui-form-item  ${empty entity or entity.roleCode eq 'ZY_BST' ? 'layui-hide' : ''  } SV2 dynamic">
        <label class="layui-form-label" >结算费率</label>
        <div class="layui-input-block">
            <input name="rate" type="number" value="${entity.rate}" autocomplete="off"  placeholder="结算费率，32表示万分之32" class="layui-input" />
        </div>
    </div>

    <div class="layui-form-item ${empty entity or entity.roleCode eq 'ZY_BST' ? 'layui-hide' : ''  } SV2 dynamic">
        <label class="layui-form-label" >升级额度</label>
        <div class="layui-input-block">
            <input name="quota" type="number" value="${entity.quota}" autocomplete="off" maxlength="15" placeholder="请输入升级额度" class="layui-input" />
        </div>
    </div>

    <div class="layui-form-item ${empty entity or entity.roleCode eq 'SV2' ? 'layui-hide' : ''  } ZY_BST dynamic">
        <label class="layui-form-label" >直推收益</label>
        <div class="layui-input-block">
            <input name="directRate" type="number" value="${entity.directRate}" autocomplete="off" maxlength="15" placeholder="如万6,则输入6,最多1位小数" class="layui-input" />
        </div>
    </div>

    <div class="layui-form-item ${empty entity or entity.roleCode eq 'SV2' ? 'layui-hide' : ''  } ZY_BST dynamic">
        <label class="layui-form-label" >间推收益</label>
        <div class="layui-input-block">
            <input name="indirectRate" type="number" value="${entity.indirectRate}" autocomplete="off" maxlength="15" placeholder="如万3,则输入3,最多1位小数" class="layui-input" />
        </div>
    </div>

    <div class="layui-form-item ${empty entity or entity.roleCode eq 'SV2' ? 'layui-hide' : ''  } ZY_BST dynamic">
        <label class="layui-form-label" >T2收益</label>
        <div class="layui-input-block">
            <input name="t2Scale" type="number" value="${entity.t2Scale}" autocomplete="off" maxlength="15" placeholder="T2收益，输入0.3则表示30%" class="layui-input" />
        </div>
    </div>

    <div class="layui-form-item ${empty entity or entity.roleCode eq 'SV2' ? 'layui-hide' : ''  } ZY_BST dynamic">
        <label class="layui-form-label" >T3收益</label>
        <div class="layui-input-block">
            <input name="t3Scale" type="number" value="${entity.t3Scale}" autocomplete="off" maxlength="15" placeholder="T3收益，输入0.2则表示20%" class="layui-input" />
        </div>
    </div>

    <div class="layui-form-item ${empty entity or entity.roleCode eq 'SV2' ? 'layui-hide' : ''  } ZY_BST dynamic">
        <label class="layui-form-label" >分红收益(%)</label>
        <div class="layui-input-block">
            <input name="dividScale" type="number" value="${entity.dividScale}" autocomplete="off" maxlength="15" placeholder="分红收益，输入0.2则表示20%" class="layui-input" />
        </div>
    </div>

    <div class="layui-form-item ${empty entity or entity.roleCode eq 'SV2' ? 'layui-hide' : ''  } ZY_BST dynamic">
        <label class="layui-form-label" >区域收益(%)</label>
        <div class="layui-input-block">
            <input name="areaScale" type="number" value="${entity.areaScale}" autocomplete="off" maxlength="15" placeholder="区域收益，输入0.2则表示20%" class="layui-input" />
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="button" id="close" class="layui-btn layui-btn-primary">关闭</button>
        </div>
    </div>
</form>

<script>
    layui.use(['form','layer'], function(){
        var form = layui.form;
        var layer = layui.layer;
        $('#close').click(function() {
            parent.layer.closeAll();
        });
            //监听提交
        form.on('submit(formDemo)', function(data){
            var index = layer.load(1,{shade: [0.1,'#000'] });
            $.ajax({
                url: '${ctx}/userLevel/save',
                method: 'post',
                data: JSON.stringify(data.field),
                dataType: 'JSON',
                contentType:"application/json",
                success: function(res) {
                    layer.close(index);
                    if(res.code == 200) {
                        layer.msg(res.message, { icon: 1, time: 1000 }, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layui.table.reload('userRole');
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(res.message, {
                            icon: 2
                        });
                    }
                }
            })
            return false;
        });

        form.on('select(roleCode)', function(data){
            let value = data.value;
            $(".dynamic").each(function (){
                $(this).addClass("layui-hide");
            })
            $("."+value).removeClass("layui-hide");
            if(value == "SV2"){
                operaSv2Required("add");
                operaBstRequired("remove")
            }else if(value == "ZY_BST"){
                operaBstRequired("add");
                operaSv2Required("remove");
            }
        })
        function operaBstRequired(type){
            if(type == "add"){
                $("input[name='directRate']").attr("lay-verify","required");
                $("input[name='indirectRate']").attr("lay-verify","required");
            }else{
                $("input[name='directRate']").removeAttr("lay-verify");
                $("input[name='indirectRate']").removeAttr("lay-verify");
            }
        }
        function operaSv2Required(type){
            if(type == "add"){
                $("input[name='rate']").attr("lay-verify","required");
            }else{
                $("input[name='rate']").removeAttr("lay-verify");
            }
        }
    });
</script>
</body>
</html>
