<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css" />
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/lib/font/iconfont.css" />
    <style>
        html{
            background-color: #fff;
        }
        .layui-form-select dl {
            max-height: 200px;
        }
        .cycleInput {
            width: 50px
        }
        .cycleSelect {
            width: 70px
        }
        .layui-input-cycle {
            position: relative;
            margin-left: 60px;
        }
        .cycleSpan {
            position: absolute;
            left: 100px;
            top: 3px;
        }
    </style>
</head>
<body>
<div class="layui-form mb-0 pr-30" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin">
    <input type="hidden" name="id" value="${setRecord.columns.id}">
    <div id="textDiv" class="layui-card-body">
        <div class="layui-col-xs6 mb-12">
            <label class="layui-form-label"><i class="mark">*</i>验收类型：</label>
            <div class="layui-input-block">
                <input type="text" value="巡检验收" class="layui-input layui-bg-gray" readonly>
            </div>
        </div>
        <div class="layui-col-xs12 mb-10 pd-10" style="display: flex; align-items: center;flex-wrap: wrap-reverse;">
            <label class="layui-form-label"><i class="mark">*</i>生成方式：</label>
            <i>每</i>
            <div style="display: flex; align-items: center;flex-wrap: wrap-reverse;">
                <input type="text" name="cycle" value="${setRecord.columns.cycle}" class="layui-input cycleInput ml-10" lay-verify="required"
                       onkeyup="this.value=this.value.replace(/\D/g,'').replace(/^0+/,'')" >
                <span class="ml-10">个月或满足</span>
                <input type="text" name="houseNum" value="${setRecord.columns.houseNum}" class="layui-input cycleInput ml-10" lay-verify="required"
                       onkeyup="this.value=this.value.replace(/\D/g,'').replace(/^0+/,'')" >
                <span class="ml-10">户,生成巡检单。</span>
            </div>
        </div>


        <div class="layui-col-xs4 mb-10 pd-10">
            <label class="layui-form-label"><i class="mark">*</i>抽检比例：</label>
            <div class="layui-input-cycle">
                <input type="text" name="ratio" value="${setRecord.columns.ratio}" class="layui-input cycleInput" lay-verify="required"
                       onkeyup="this.value=this.value.replace(/^0+(?=\d)/,'')" >
                <span class="cycleSpan">%</span>
            </div>
        </div>

        <div class="layui-col-xs12 mb-10 pd-10" style="display: flex; align-items: center;flex-wrap: wrap-reverse;">
            <label class="layui-form-label"><i class="mark">*</i>比例浮动：</label>
            <i>完工一次通过率:</i>
            <div style="display: flex; align-items: center;flex-wrap: wrap-reverse;">
                <div class="cycleSelect ml-10">
                    <select name="just" lay-verify="required">
                        <option value="1" <c:if test="${setRecord.columns.just eq '1' }">selected</c:if>>低于</option>
                        <option value="2" <c:if test="${setRecord.columns.just eq '2' }">selected</c:if>>高于</option>
                    </select>
                </div>
                <input type="text" name="propFloatWg" value="${setRecord.columns.propFloatWg}" class="layui-input cycleInput ml-10" lay-verify="required"
                       onkeyup="this.value=this.value.replace(/^0+(?=\d)/,'')" >
                <span class="ml-10">%,抽检比例</span>
                <div class="cycleSelect ml-10">
                <select name="floating" lay-verify="required">
                    <option value="1" <c:if test="${setRecord.columns.floating eq '1' }">selected</c:if> >下浮</option>
                    <option value="2" <c:if test="${setRecord.columns.floating eq '2' }">selected</c:if>>上浮</option>
                </select>
                </div>
                <input type="text" name="propFloatCj" value="${setRecord.columns.propFloatCj}" class="layui-input cycleInput ml-10" lay-verify="required"
                       onkeyup="this.value=this.value.replace(/^0+(?=\d)/,'')" >
                <span class="ml-10">%</span>
            </div>
        </div>
    </div>
    <div class="layui-form-item text-c operate-footer" >
        <button class="layui-btn " lay-submit lay-filter="component-form-element">保存</button>
        <button class="layui-btn layui-btn-primary" onclick="cancel()">取消</button>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/font/iconfont.js"></script>
<script>
    layui.use(['form','jquery','layedit'], function () {
        $ = layui.$,
            form = layui.form,
            layer = layui.layer;

        var fg=false;
        form.on('submit(component-form-element)',function(data){
            if(fg){
                return;
            }
            var field = data.field; //获取提交的字段

            if(field.ratio<=0 || field.ratio>100){
                layer.msg("抽成比例只允许输入0.01-100的数字!", {time: 3000});
                return;
            }
            if(field.propFloatWg<=0 || field.propFloatWg>100){
                layer.msg("比例浮动只允许输入0.01-100的数字!", {time: 3000});
                return;
            }
            if(field.propFloatCj<=0 || field.propFloatCj>100){
                layer.msg("比例浮动只允许输入0.01-100的数字!", {time: 3000});
                return;
            }

            if(field.floating == '1' &&field.ratio-field.propFloatCj<20){
                layer.msg("最低抽检比例不能低于20%!", {time: 3000});
                return;
            }else {
                if(field.ratio<20){
                    layer.msg("最低抽检比例不能低于20%!", {time: 3000});
                    return;
                }
            }


            fg=true;
            $.ajax({
                url: '${ctx}/qualityRatioSet/editInspectionSet',
                type: 'post',
                data: {
                    id: field.id,
                    cycle: field.cycle,
                    houseNum: field.houseNum,
                    ratio:field.ratio,
                    just:field.just,
                    floating:field.floating,
                    propFloatWg:field.propFloatWg,
                    propFloatCj:field.propFloatCj
                },
                success: function(data) {
                    if(data.code === "200"){
                        layer.msg('操作成功！', {icon:1,time:2000},function(){
                            parent.window.reload(); //刷新父页面
                        })
                    }else{
                        layer.msg("修改失败！"+data.errMsg,{icon:5,anim:6});
                    }
                },
                complete:function(){
                    fg=false;
                }
            });
        })

    });

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }
    function cancel(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
    function hasLeadingZero(str) {
        return /^\d*0\d+$/.test(str);
    }

</script>
</body>
</html>

