<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <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" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
    <style>
        html{background-color: #fff;padding-bottom: 50px;}
        .layui-form-select dl{
            max-height:200px;
            width: 80%;
        }
    </style>
</head>
<body>

<div class="layui-form">
    <div class="layui-card mt-10">
        <c:if test="${not empty apply.columns.id}">
            <div class="ideaOpe">
                备注：${apply.columns.content}
            </div>
        </c:if>

        <div class="layui-col-xs12 mb-15 pr-30">
            <input name="id" value="${apply.columns.id}" hidden>
            <label class="layui-form-label w-130"><i class="red">*</i>代理商名称：</label>
            <div class="layui-input-block">
                <select name="traderId" id="traderName" lay-filter="traderName" lay-verify="required" lay-search>
                    <option value="">请选择</option>
                    <c:forEach var="trader" items="${traders}">
                        <option value="${trader.columns.id}" data-value="${trader.columns.contacts}" data-anim="${trader.columns.mobile}"
                                data-method="${trader.columns.bond_amount_limit}"
                                data-type="${trader.columns.traderAddress}" <c:if test="${apply.columns.trader_id eq trader.columns.id}"> selected</c:if>>${trader.columns.name}</option>
                    </c:forEach>
                </select>
            </div>
        </div>

        <div class="layui-col-xs12 mb-10 pr-30">
            <div class="layui-inline layui-col-xs6">
                <label class="layui-form-label w-130">联系人：</label>
                <div class="layui-input-block ">
                    <input type="text" class="layui-input layui-bg-gray" value="${apply.columns.contacts}" id="contacts" disabled>
                </div>
            </div>
            <div class="layui-inline layui-col-xs6">
                <label class="layui-form-label w-130">联系电话：</label>
                <div class="layui-input-block w-200" >
                    <input type="text" class="layui-input layui-bg-gray" value="${apply.columns.mobile}" id="mobile" disabled>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 mb-10 pr-30">
            <label class="layui-form-label w-130">代理商地址：</label>
            <div class="layui-input-block">
                <input type="text"  class="layui-input layui-bg-gray" value="${apply.columns.traderAddress}" disabled id="traderAddress" >
            </div>
        </div>

        <div class="layui-col-xs12 mb-10 pr-30">
            <div class="layui-inline layui-col-xs6">
                <label class="layui-form-label" style="width: 125px"><i class="red">*</i>申请保证金额度：</label>
                <div class="layui-input-block"  style="margin-left: 125px">
                    <input type="text" class="layui-input" name="amount" lay-verify="required" value="${apply.columns.amount}" oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')">
                </div>
            </div>
            <div class="layui-inline layui-col-xs6">
                <label class="layui-form-label">现保证金额度：</label>
                <div class="layui-input-block" >
                    <input type="text" class="layui-input layui-bg-gray" name="oldAmount" id="oldAmount" disabled  value="${apply.columns.oldAmount}">
                </div>
            </div>
        </div>


        <div class="layui-col-xs12 mb-15 pr-30 mt-10">
            <label class="layui-form-label w-130">备注：</label>
            <div class="layui-input-block">
                <input type="text" name="remarks" autocomplete="off" placeholder="" class="layui-input" value="${apply.columns.remarks}">
            </div>
        </div>

        <input type="hidden" name="voucher" id="imgs" value="${apply.columns.voucher}">
        <div class="layui-col-xs12 mb-20 pr-30 mt-20">
        </div>
    </div>
    <div class="operate-footer">
        <c:if test="${empty apply.columns.id}">
            <input type="button" lay-submit lay-filter="confirm" id="confirm" class="layui-btn " value="提交">
        </c:if>
        <c:if test="${not empty apply.columns.id}">
            <input type="button" lay-submit lay-filter="confirm" id="confirm" class="layui-btn " value="重新提交">
        </c:if>
        <input type="button"   value="取消" class="layui-btn layui-btn-primary " onclick="closeDiv();" >
    </div>
</div>

<div id="lookImg" class="hide pos-r">
    <div style="position:relative;width:90%;height:450px;">
        <div class="w-500 h-450 lookImg">
            <img src="" width="80%" id="image">
        </div>
    </div>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/javascript">
    //初始数据
    var $form;
    var form;
    var upload;
    var $;
    var isNum=/^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;  //校验金额
    layui.use(['form', 'table', 'upload', 'jquery'], function () {
        $ = layui.jquery;
        form = layui.form;
        upload = layui.upload;
        $form = $('form');


        form.on('select(traderName)', function(data){
            var contacts=$(data.elem).find("option:selected").attr("data-value");
            var mobile=$(data.elem).find("option:selected").attr("data-anim");
            var traderAddress=$(data.elem).find("option:selected").attr("data-type");
            var bondAmountLimit=$(data.elem).find("option:selected").attr("data-method");

            $("#contacts").val(contacts);
            $("#mobile").val(mobile);
            $("#traderAddress").val(traderAddress);
            $("#oldAmount").val(bondAmountLimit);
        });


        form.on('submit(confirm)', function(data){
            console.log(JSON.stringify(data.field));
            $("#confirm").attr("disabled","true");
            var amount=$("input[name='amount']").val();
            if(!isNum.test($.trim(amount))) {
                layer.msg("金额格式有误，请重新输入！", {time: 2000});
                $("#confirm").removeAttr("disabled");
                return false;
            }
            $.ajax({
                url:'${ctx}/apply/bondLimitApply/saveBondLimitApply',
                method:'post',
                contentType : "application/json;charsetset=UTF-8",
                data:JSON.stringify(data.field),
                success:function(res){
                    if(res.code=="200"){
                        parent.layer.msg("保存成功",{time:2000});
                        closeDiv();
                        parent.table.reload('test');
                    } else{
                        layer.msg(res.errMsg,{time:2000});
                        $("#confirm").removeAttr("disabled");
                    }
                },
                error:function (data) {
                }
            }) ;
        });

    })

    function  closeDiv() {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
    }

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

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



