<%@ 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" 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: #FFF}

        .layui-input-block {
            margin-left: 148px;
        }

        .layui-form-label {
            width: 148px;
        }
        .title1 {
            border-left: 4px solid #1b6073;
            padding-left: 20px;
            font-size: 14px;
            margin: 10px auto;
            font-weight: 600;
            height: 34px;
            line-height: 34px;
            background-color: #f4f6f9;
            color: #666666;
        }
        .clearfix{*zoom:1;}
        .clearfix:before,.clearfix:after{display:table; line-height:0; content:"";}
        .clearfix:after{clear:both;}

        .operate-footer{
            z-index: 1;
        }
        .layui-elem-quote{
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
<div class="aaa">
    <div class="layui-form " id="detailSet">
        <div class="layui-card-body  pt-20 h-350" action="" >
            <form class="clearfix" id="form5">
                <blockquote class="layui-elem-quote">保险信息</blockquote>
                <input type="text" name="id" class="hide" value="${insurance.id}">
                <div class="layui-col-xs12 mb-5 pr-30">
                    <input type="text" name="insuranceType" class="hide" value="1">
                    <%--<div class="layui-inline layui-col-xs4">
                        <label class="layui-form-label">保险类型：</label>
                        <div class="layui-input-block">
                            <select name="insuranceType" >
                                <option value="">请选择</option>
                                <option value="1" <c:if test="${insurance.insuranceType eq '1'}" > selected</c:if>>财产险</option>
                                <option value="2" <c:if test="${insurance.insuranceType eq '2'}" > selected</c:if>>商业险</option>
                                <option value="3" <c:if test="${insurance.insuranceType eq '3'}" > selected</c:if>>交强险</option>
                                <option value="4" <c:if test="${insurance.insuranceType eq '4'}" > selected</c:if>>其他</option>
                            </select>
                        </div>
                    </div>--%>
                    <div class="layui-inline layui-col-xs4">
                        <label class="layui-form-label"><i class="red">*</i>保险开始日期：</label>
                        <div class="layui-input-block" >
                            <input name="insuranceDateFrom" id="insuranceDateFrom" lay-verify="required"  class="layui-input" placeholder="年月日" value="${insurance.insuranceDateFrom}">
                        </div>
                    </div>
                    <div class="layui-inline layui-col-xs4">
                        <label class="layui-form-label"><i class="red">*</i>保险结束日期：</label>
                        <div class="layui-input-block" >
                            <input   name="insuranceDateTo"  id="insuranceDateTo" lay-verify="required"  class="layui-input" placeholder="年月日" value="${insurance.insuranceDateTo}">
                        </div>
                    </div>
                </div>

                <div class="layui-col-xs12 mb-5 pr-30 ">
                    <div class="layui-inline layui-col-xs4">
                        <label class="layui-form-label"><i class="red">*</i>保险公司：</label>
                        <div class="layui-input-block">
                            <input type="text" name="insuranceCompany" class="layui-input" value="${insurance.insuranceCompany}">
                        </div>
                    </div>
                    <div class="layui-inline layui-col-xs4">
                        <label class="layui-form-label"><i class="red">*</i>保险编号：</label>
                        <div class="layui-input-block">
                            <input type="text" name="insuranceNumber" class="layui-input" value="${insurance.insuranceNumber}">
                        </div>
                    </div>
                    <div class="layui-inline layui-col-xs4">
                        <label class="layui-form-label"><i class="red">*</i>投保金额：</label>
                        <div class="layui-input-block">
                            <input type="text" name="insuranceAmount" class="layui-input"
                                   onkeyup="!/^(\d+\.?)?\d{0,2}$/.test(this.value)?(this.value=this.value.substring(0, this.value.length-1)): ''"
                                   value="${insurance.insuranceAmount}">
                            <span class="pos-a h-32 lh-32 layui-span-unit">元</span>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs12 mb-5 pr-30 ">
                    <div class="layui-inline layui-col-xs6">
                        <label class="layui-form-label"><i class="red">*</i>第一受益人：</label>
                        <div class="layui-input-block">
                            <input type="text" name="firstBeneficiary" class="layui-input layui-bg-gray" readonly value="广州越秀融资租赁有限公司">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs12 mb-5 pr-30">
                    <div class="layui-inline layui-col-xs4">
                        <label class="layui-form-label"><i class="red">*</i>保险单：</label>
                        <div class="layui-input-block" style="display:flex;">
                            <div id="imgsDiv3">
                                <c:if test="${not empty insurance.insurancePolicy}">
                                    <div class="bj-img imgSpan"><span class="layui-icon-close layui-icon" onclick="delImg(this,'uploaderone3')"></span>
                                        <img src="${commonStaticImgPath}${insurance.insurancePolicy}" height="700" width="1200"/>
                                        <input type="hidden" class="roof_photo_one" name="insurancePolicy" value="${insurance.insurancePolicy}"/>
                                    </div>
                                </c:if>

                            </div>
                            <div class="upload-container  <c:if test="${not empty insurance.insurancePolicy}">hide</c:if>" id="uploaderone3">
                                <img src="" alt="img placeholder" id="imgsAdd3">
                            </div>

                        </div>
                    </div>
                    <div class="layui-inline layui-col-xs4">
                        <label class="layui-form-label"><i class="red">*</i>并网调试报告：</label>
                        <div class="layui-input-block" style="display:flex;">
                            <div id="imgsDiv4">
                                <c:if test="${not empty insurance.bwtsFile}">
                                    <div class="bj-img imgSpan"><span class="layui-icon-close layui-icon" onclick="delImg(this,'uploaderone4')"></span>
                                        <img src="${commonStaticImgPath}${insurance.bwtsFile}" height="700" width="1200"/>
                                        <input type="hidden" class="roof_photo_one" name="bwtsFile" value="${insurance.bwtsFile}"/>
                                    </div>
                                </c:if>

                            </div>
                            <div class="upload-container  <c:if test="${not empty insurance.bwtsFile}">hide</c:if>" id="uploaderone4">
                                <img src="" alt="img placeholder" id="imgsAdd4">
                            </div>

                        </div>
                    </div>
                   <%-- <div class="layui-inline layui-col-xs4">
                        <label class="layui-form-label">备案证：</label>
                        <div class="layui-input-block" style="display:flex;">
                            <div id="imgsDiv5">
                                <c:if test="${not empty insurance.filingCardFile}">
                                    <div class="bj-img imgSpan"><span class="layui-icon-close layui-icon" onclick="delImg(this,'uploaderone5')"></span>
                                        <img src="${commonStaticImgPath}${insurance.filingCardFile}" height="700" width="1200"/>
                                        <input type="hidden" class="roof_photo_one" name="filingCardFile" value="${insurance.filingCardFile}"/>
                                    </div>
                                </c:if>

                            </div>
                            <div class="upload-container  <c:if test="${not empty insurance.filingCardFile}">hide</c:if>" id="uploaderone5">
                                <img src="" alt="img placeholder" id="imgsAdd5">
                            </div>

                        </div>
                    </div>--%>
                </div>
            </form>
        </div>
        <div style="height: 70px;"></div>
        <div class="layui-form-item operate-footer" style="text-align: center;">
            <input type="button" lay-filter="temp" id="temp" class="layui-btn" value="暂存">
            <input type="button" lay-submit lay-filter="confirm" id="confirm" class="layui-btn " value="提交">
            <input type="button"   value="取消" class="layui-btn layui-btn-primary " lay onclick="closeDiv();" >
        </div>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script>
    var entryId='${entryId}';

    var idCordReq = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    //初始数据
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['form', 'table', 'upload', 'jquery','laydate','upload'], function () {
        $ = layui.$
        ,form = layui.form
        ,laydate = layui.laydate;
        var  upload = layui.upload;

        upload.render({
            elem: '#uploaderone3' //绑定元素
            , url: '${ctx}/common/uploadFile2' //上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                });
            }
            , done: function (res) {
                //上传完毕回调
                addImg(res.path,"uploaderone3","imgsDiv3","insurancePolicy");
            }
            , error: function () {
                //请求异常回调
            }
        });

        upload.render({
            elem: '#uploaderone4' //绑定元素
            , url: '${ctx}/common/uploadFile2' //上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                });
            }
            , done: function (res) {
                //上传完毕回调
                addImg(res.path,"uploaderone4","imgsDiv4","bwtsFile");
            }
            , error: function () {
                //请求异常回调
            }
        });

        upload.render({
            elem: '#uploaderone5' //绑定元素
            , url: '${ctx}/common/uploadFile2' //上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                });
            }
            , done: function (res) {
                //上传完毕回调
                addImg(res.path,"uploaderone5","imgsDiv5","filingCardFile");
            }
            , error: function () {
                //请求异常回调
            }
        });

        function addImg(data,id,imgsDiv,classimg){
            $("#"+id).hide();
            var html = '<div class="bj-img imgSpan"><span class="layui-icon-close layui-icon" onclick="delImg(this,\''+id+'\')"></span>';
            html += '<img src="${commonStaticImgPath}'+data+'" height="700" width="1200"/>';
            html += '<input type="hidden" class="'+classimg+'" name="'+classimg+'" value="'+data+'"/> </div>';
            $("#"+imgsDiv).append(html);
           /* //图片查看效果
            viewer.update();*/
        }

        laydate.render({
            elem: '#insuranceDateFrom'
            ,trigger: 'click'
            ,format:"yyyyMMdd"
        });

        laydate.render({
            elem: '#insuranceDateTo'
            ,trigger: 'click'
            ,format:"yyyyMMdd"
        });

        var saveFlag=false;
        form.on('submit(confirm)', function(data){
            if(saveFlag){
                return false;
            }
            var date5={};
            $($("#form5").serializeArray()).each(function(){
                date5[this.name] = this.value;
            });

            var date={
                entryId:entryId,
                resultType:1,
                insurance:date5,
            }
            console.log(date);

            saveFlag=true;

            $.ajax({
                url:'${ctx}/customerEntryExtra/addIncomingApplicationSec',
                method:'post',
                contentType : "application/json;charsetset=UTF-8",
                data:JSON.stringify(date),
                success:function(res){
                    console.log(res);
                    if(res.code=="200"){
                        parent.layer.msg("保存成功",{time:1000});
                        closeDiv();
                        parent.table.reload('test');
                    }else if(res.code=="501"){
                        layer.confirm('当前电站未签约《农户合同》，请在签约后再推送并网信息!', {
                            title:'未签约',
                            btn:['确定'] //按钮
                        }, function(){
                            closeDiv();
                        });
                    }else{
                        layer.msg(res.errMsg,{time:1000},function(){
                            saveFlag=false;
                        });
                    }
                },
                complete:function (data) {
                }
            }) ;
        });

        var saveFlag1=false;
        $("#temp").click(function(){
            if(saveFlag1){
                return false;
            }
            var date5={};
            $($("#form5").serializeArray()).each(function(){
                date5[this.name] = this.value;
            });

            var date={
                entryId:entryId,
                resultType:0,
                insurance:date5,
            }
            console.log(date);
            saveFlag1=true;
            $.ajax({
                url:'${ctx}/customerEntryExtra/addIncomingApplicationSec',
                method:'post',
                contentType : "application/json;charsetset=UTF-8",
                data:JSON.stringify(date),
                success:function(res){
                    console.log(res);
                    if(res.code=="200"){
                        parent.layer.msg("保存成功",{time:1000});
                        closeDiv();
                        parent.table.reload('test');
                    }else{
                        layer.msg(res.errMsg,{time:1000},function(){
                            saveFlag1=false;
                        });
                    }
                },
                complete: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;
    }


    function delImg(that,id){
        $("#"+id).show();
        $(that).parent().remove();
    }

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

