<%@ 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">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.css" media="all">
    <style>
        .layui-form-select dl {
            max-height: 180px;
            width: 80%;
        }

        html {
            background-color: #fff;
        }

        .layui-table td, .layui-table th {
            text-align: center;
        }

        .hx_l {
            position: relative;
        }

        .hx_l > span {
            position: absolute;
            right: 10px;
            top: 5px
        }

        .hx_del {
            font-size: 12px;
            color: #0e8ee7;
            position: relative;
            top: 4px;
            display: none
        }

        #attachFile > li {
            height: 26px
        }

        #attachFile > li:hover .hx_del {
            display: inline-block
        }

        .hx_ts {
            font-size: 12px;
            color: red;
        }

        .blank-img {
            background: url('${ctxPlugin}/static/imgs/blankImg.png') center center no-repeat;
            width: 80px;
            height: 80px;
            display: inline-block;
        }
    </style>
</head>
<body>
<div class="aaa scrollDiv" id="LAY_app">
    <div class="layui-form">
        <div class="layui-card-body ${mode eq 'view' ? 'over':''} pt-20 pb-40" action="" id="detailSet">
            <div class="layui-col-xs12 mb-10 pr-30">
                <div class="layui-inline layui-col-xs6">
                    <label class="layui-form-label w-130"><c:if test="${readOnly ne '1'}"><i class="red">*</i></c:if>方案编号：</label>
                    <div class="layui-input-block ">
                        <input type="text" ${empty plan? '':'disabled'} name="code" lay-verify="required"
                               autocomplete="off" placeholder="请输入方案编号"
                               class="layui-input ${empty plan? '': 'layui-disabled layui-bg-gray'}"
                               value="${plan.columns.code}">
                    </div>
                </div>
                <div class="layui-inline layui-col-xs6">
                    <label class="layui-form-label w-130"><c:if test="${readOnly ne '1'}"><i class="red">*</i></c:if>方案名称：</label>
                    <div class="layui-input-block w-200">
                        <input type="text" ${empty plan? '':'disabled'} name="name" lay-verify="required"
                               autocomplete="off" placeholder="请输入方案名称"
                               class="layui-input ${empty plan? '': 'layui-disabled layui-bg-gray'}"
                               value="${plan.columns.name}">
                    </div>
                </div>
            </div>
            <div class="layui-col-xs12 mb-10 pr-30">
                <c:if test="${mode eq 'view'}">
                    <div class="layui-inline layui-col-xs6">
                        <label class="layui-form-label w-130"><c:if test="${readOnly ne '1'}"><i class="red">*</i></c:if>方案类型：</label>
                        <div class="layui-input-block w-200">
                            <input type="text" class="layui-input layui-disabled layui-bg-gray" value="${plan.columns.plan_type}">
                        </div>
                    </div>
                </c:if>
                <c:if test="${mode ne 'view'}">
                    <div class="layui-inline layui-col-xs6">
                        <label class="layui-form-label w-130"><c:if test="${readOnly ne '1'}"><i class="red">*</i></c:if>方案类型：</label>
                        <div class="layui-input-block w-200">
                            <select name="planTypeId" id="planTypeId" ${empty plan? '':'disabled'}>
                                <option value="">请选择</option>
                                <c:forEach items="${insta}" var="ins">
                                    <option value="${ins.columns.id}"
                                            <c:if test="${plan.columns.plan_type_id eq ins.columns.id}">selected</c:if>>${ins.columns.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                </c:if>

                <c:if test="${mode eq 'view'}">
                    <div class="layui-col-lg3 layui-col-sm3 ">
                        <label class="layui-form-label"><c:if test="${readOnly ne '1'}"><i class="mark">*</i></c:if>参考图纸：</label>
                        <div class="layui-input-block pos-r view-attachment">
                            <c:if test="${not empty plan.columns.attach}"><a class="h-32 lh-32 ml-5 layui-span-unit"
                                                                             onclick="previewUrl('${commonStaticImgPath}${plan.columns.attach}')"
                                                                              target="_blank"
                                                                             style="color: #2890ac;">查看</a></c:if>
                        </div>
                    </div>
                </c:if>
                <c:if test="${mode ne 'view'}">
                    <div class="layui-inline layui-col-xs6">
                        <label class="layui-form-label w-130"><c:if test="${readOnly ne '1'}"><i class="red">*</i></c:if>参考图纸：</label>
                        <div class="layui-input-block w-200">
                            <div style="position: relative;top: 3px;" id="addFile">
                                <button class="layui-btn layui-btn-sm">上传</button>
                                <input type="file" id="uploadFile" single accept="application/pdf"
                                       style="position: absolute; z-index: 3; opacity: 0; left: 0; width: 44px;">
                                    <%-- <c:if test="${type eq '2'}">
                                         <span class="hx_ts">(最多传入2个附件)</span>
                                     </c:if>--%>
                            </div>

                            <ul id="attachFile">
                                <c:if test="${not empty plan.columns.attach}">
                                    <li>
                                    <span style="position: relative; top: 4px;"
                                          class="uploadFileName ${empty plan.columns.attach? 'layui-hide': ''}">${empty plan.columns.attach? '': plan.columns.attach_name}</span>
                                        <input type="hidden" name="attach" lay-verify="attach"
                                               value="${plan.columns.attach}"/>
                                        <input type="hidden" name="attachName" value="${plan.columns.attach_name}"/>
                                        <c:if test="${type eq '2' && not empty plan}">
                                            <span class="hx_del">删除</span>
                                        </c:if>

                                    </li>
                                </c:if>
                                    <%--     <c:if test="${type eq '2' && not empty plan.columns.attach2 }">
                                             <li>
                                                 <span style="position: relative; top: 4px;"
                                                       class="uploadFileName ${empty plan.columns.attach2? 'layui-hide': ''}">${empty plan.columns.attach2? '': plan.columns.attach_name2}</span>
                                                 <input type="hidden" name="attach" lay-verify="attach" value="${plan.columns.attach2}"/>
                                                 <input type="hidden" name="attachName" value="${plan.columns.attach_name2}"/>
                                                 <span class="hx_del">删除</span>
                                             </li>
                                         </c:if>--%>
                            </ul>
                        </div>
                    </div>
                </c:if>
            </div>

            <c:if test="${mode eq 'view'}">
            <div class="layui-row">
                <div class="layui-inline layui-col-xs12">
                    <label class="layui-form-label w-130"><c:if test="${readOnly ne '1'}"><i class="red">*</i></c:if>设计图纸：</label>
                    <div class="layui-input-block ">
                        <div>
                            <c:if test="${not empty entry.designDrawings}">
                                <c:forEach items="${entry.designDrawings}" var="file" varStatus="vs">
                                    <div style="margin-top: 5px">
                                            <%-- <span class="layui-icon-close layui-icon" onclick="delImg(this,'attachFilesUploader')"></span>--%>
                                        <a style="color: #0e8ee7"  href="${commonStaticImgPath}${file}" download="${file}" class="download-link">${fns:substringAfterLast(file, '/')}</a>
                                        <a style="color: #0e8ee7;margin-left: 10px" onclick="previewUrl('${commonStaticImgPath}${file}')" target="_blank"  class="download-link">查看</a>
                                        <input type="hidden" class="attachFiles" value="${file}">
                                    </div>
                                    <c:set var="attachFilesCount" value="${vs.count}"/>
                                </c:forEach>
                            </c:if>
<%--                            <c:if test="${not empty entry.designDrawings}">--%>
<%--                                <c:forEach var="imgStr" items="${fn:split(entry.designDrawings,',')}">--%>
<%--                                    <c:choose>--%>
<%--                                        <c:when test="${fns:checkIfImg(imgStr)}">--%>
<%--                                            <div class="bj-img imgSpan">--%>
<%--                                                <img src="${commonStaticImgPath}${imgStr}"--%>
<%--                                                     data-img="${commonStaticImgPath}${imgStr}" height="700"--%>
<%--                                                     width="1200"/>--%>
<%--                                                <input type="hidden" class="attachFileImg" value="${imgStr}"/>--%>
<%--                                            </div>--%>
<%--                                        </c:when>--%>
<%--                                        <c:otherwise>--%>
<%--                                            <a class="h-32 lh-32 layui-span-unit lookBtn"--%>
<%--                                               href="${commonStaticImgPath}${imgStr}" target="_blank" style="color: #2890ac;">查看</a>--%>
<%--                                            <input type="hidden" class="attachFileImg" value="${imgStr}"/>--%>
<%--                                        </c:otherwise>--%>
<%--                                    </c:choose>--%>
<%--                                </c:forEach>--%>

<%--                            </c:if>--%>
                        </div>
                    </div>
                </div>
<%--                <div class="layui-inline layui-col-xs12">--%>
<%--                    <label class="layui-form-label w-130"></label>--%>
<%--                    <div class="layui-input-block ">--%>
<%--                        <div class="layui-input-block img-box" style="margin-left: 0">--%>
<%--                            <div>--%>
<%--                                <c:if test="${not empty entry.dzImgs}">--%>
<%--                                    <c:forEach items="${entry.dzImgs}" var="img">--%>
<%--                                        <div class="bj-img imgSpan">--%>
<%--                                            <img src="${commonStaticImgPath}${img}" height="700" width="1200"/>--%>
<%--                                        </div>--%>
<%--                                    </c:forEach>--%>
<%--                                </c:if>--%>
<%--                            </div>--%>
<%--                        </div>--%>
<%--                    </div>--%>
<%--                </div>--%>

            </div>

            <c:if test="${info2.columns.zjpb_img_03.status eq '1'}">
                <div class="layui-row">
                    <div class="layui-inline layui-col-xs12">
                        <label class="layui-form-label w-130"><c:if test="${readOnly ne '1'}"><i class="red">*</i></c:if>组件排布图：</label>
                        <div class="layui-input-block ">
                            <div>
                                <c:if test="${not empty entry.zjpbImg}">
                                    <c:forEach items="${entry.zjpbImg}" var="file" varStatus="vs">
                                        <div style="margin-top: 5px">
                                                <%-- <span class="layui-icon-close layui-icon" onclick="delImg(this,'attachFilesUploader')"></span>--%>
                                            <a style="color: #0e8ee7"  href="${commonStaticImgPath}${file}" download="${file}" class="download-link">${fns:substringAfterLast(file, '/')}</a>
                                            <a style="color: #0e8ee7;margin-left: 10px" onclick="previewUrl('${commonStaticImgPath}${file}')" target="_blank"  class="download-link">查看</a>
                                            <input type="hidden" class="attachFiles" value="${file}">
                                        </div>
                                        <c:set var="attachFilesCount" value="${vs.count}"/>
                                    </c:forEach>
                                </c:if>
                            </div>
                        </div>
                    </div>
                </div>
            </c:if>

            <c:if test="${info2.columns.zjzx_img_03.status eq '1'}">
                <div class="layui-row">
                    <div class="layui-inline layui-col-xs12">
                        <label class="layui-form-label w-130"><c:if test="${readOnly ne '1'}"><i class="red">*</i></c:if>组串接线图：</label>
                        <div class="layui-input-block ">
                            <div>
                                <c:if test="${not empty entry.zjzxImg}">
                                    <c:forEach items="${entry.zjzxImg}" var="file" varStatus="vs">
                                        <div style="margin-top: 5px">
                                                <%-- <span class="layui-icon-close layui-icon" onclick="delImg(this,'attachFilesUploader')"></span>--%>
                                            <a style="color: #0e8ee7"  href="${commonStaticImgPath}${file}" download="${file}" class="download-link">${fns:substringAfterLast(file, '/')}</a>
                                            <a style="color: #0e8ee7;margin-left: 10px" onclick="previewUrl('${commonStaticImgPath}${file}')" target="_blank"  class="download-link">查看</a>
                                            <input type="hidden" class="attachFiles" value="${file}">
                                        </div>
                                        <c:set var="attachFilesCount" value="${vs.count}"/>
                                    </c:forEach>
                                </c:if>
                            </div>
                        </div>
                    </div>
                </div>
            </c:if>

            <c:if test="${info2.columns.zjcs_img_03.status eq '1'}">
                <div class="layui-row">
                    <div class="layui-inline layui-col-xs12">
                        <label class="layui-form-label w-130"><c:if test="${readOnly ne '1'}"><i class="red">*</i></c:if>组件支架图：</label>
                        <div class="layui-input-block ">
                            <div>
                                <c:if test="${not empty entry.zjcsImg}">
                                    <c:forEach items="${entry.zjcsImg}" var="file" varStatus="vs">
                                        <div style="margin-top: 5px">
                                                <%-- <span class="layui-icon-close layui-icon" onclick="delImg(this,'attachFilesUploader')"></span>--%>
                                            <a style="color: #0e8ee7"  href="${commonStaticImgPath}${file}" download="${file}" class="download-link">${fns:substringAfterLast(file, '/')}</a>
                                            <a style="color: #0e8ee7;margin-left: 10px" onclick="previewUrl('${commonStaticImgPath}${file}')" target="_blank"  class="download-link">查看</a>
                                            <input type="hidden" class="attachFiles" value="${file}">
                                        </div>
                                        <c:set var="attachFilesCount" value="${vs.count}"/>
                                    </c:forEach>
                                </c:if>
                            </div>
                        </div>
                    </div>
                </div>
            </c:if>

            <c:if test="${info2.columns.zjhs_img_03.status eq '1'}">
                <div class="layui-row">
                    <div class="layui-inline layui-col-xs12">
                        <label class="layui-form-label w-130"><c:if test="${readOnly ne '1'}"><i class="red">*</i></c:if>一次接线图/电气图：</label>
                        <div class="layui-input-block ">
                            <div>
                                <c:if test="${not empty entry.zjhsImg}">
                                    <c:forEach items="${entry.zjhsImg}" var="file" varStatus="vs">
                                        <div style="margin-top: 5px">
                                                <%-- <span class="layui-icon-close layui-icon" onclick="delImg(this,'attachFilesUploader')"></span>--%>
                                            <a style="color: #0e8ee7"  href="${commonStaticImgPath}${file}" download="${file}" class="download-link">${fns:substringAfterLast(file, '/')}</a>
                                            <a style="color: #0e8ee7;margin-left: 10px" onclick="previewUrl('${commonStaticImgPath}${file}')" target="_blank"  class="download-link">查看</a>
                                            <input type="hidden" class="attachFiles" value="${file}">
                                        </div>
                                        <c:set var="attachFilesCount" value="${vs.count}"/>
                                    </c:forEach>
                                </c:if>
                            </div>
                        </div>
                    </div>
                </div>
            </c:if>

            <div class="layui-row mt-10">
                <div class="layui-col-lg5 layui-col-sm7">
                    <label class="layui-form-label"><c:if test="${readOnly ne '1'}"><i class="mark">*</i></c:if>设计安装容量：</label>
                    <div class="layui-input-block">
                        <div class="layui-inline">
                            <input type="text" class="layui-input layui-bg-gray" style="width: 85px;"
                                   value="${entry.designCapacity / 1000 }" disabled>
                            <span class="pos-a h-32 lh-32 layui-span-unit">kW</span>
                        </div>

                    </div>
                </div>
            </div>
            <c:forEach var="item" items="${assemblyList}" varStatus="vs">
                <div class="layui-row mt-10">
                    <div class="layui-col-lg5 layui-col-sm7">
                        <label class="layui-form-label"><c:if test="${readOnly ne '1'}"><i class="mark">*</i></c:if>组件：</label>
                        <div class="layui-input-block">
                            <div class="layui-inline">
                                <c:choose>
                                    <c:when test="${info2.columns.component3_model.status eq '1'}">
                                        <input type="text" class="layui-input layui-bg-gray " style=""
                                               value="${item.columns.material_model}" disabled>
                                    </c:when>
                                    <c:otherwise>
                                        <input type="text" class="layui-input layui-bg-gray" style=""
                                               value="${item.columns.model}" disabled>
                                    </c:otherwise>
                                </c:choose>
                                <span class="pos-a h-32 lh-32 layui-span-unit">Wp</span>
                            </div>
                            <span class="layui-inline">X </span>
                            <div class="layui-inline">
                                <input type="text" class="layui-input layui-bg-gray" style="width: 85px;"
                                       value="${item.columns.num}" disabled>
                            </div>
                        </div>
                    </div>
                </div>
            </c:forEach>
            <c:forEach var="item" items="${inverterList}" varStatus="vs">
                <div class="layui-row">
                    <div class="layui-col-lg5 layui-col-sm7">
                        <label class="layui-form-label"><c:if test="${readOnly ne '1'}"><i class="mark">*</i></c:if>逆变器：</label>
                        <div class="layui-input-block">
                            <div class="layui-inline">
                                <c:choose>
                                    <c:when test="${info2.columns.component1_model.status eq '1'}">
                                        <input type="text" class="layui-input layui-bg-gray" style=""
                                               value="${item.columns.material_model}" disabled>
                                    </c:when>
                                    <c:otherwise>
                                        <input type="text" class="layui-input layui-bg-gray" style=""
                                               value="${item.columns.model}" disabled>
                                    </c:otherwise>
                                </c:choose>
                            </div>
                            <span class="layui-inline">X </span>
                            <div class="layui-inline">
                                <input type="text" class="layui-input layui-bg-gray" style="width: 85px;"
                                       value="${item.columns.num}" disabled>
                            </div>
                        </div>
                    </div>
                </div>
            </c:forEach>
            <c:forEach var="item" items="${gridConnectionList}" varStatus="vs">
                <div class="layui-row">
                    <div class="layui-col-lg5 layui-col-sm7">
                        <label class="layui-form-label"><c:if test="${readOnly ne '1'}"><i class="mark">*</i></c:if>并网箱：</label>
                        <div class="layui-input-block">
                            <div class="layui-inline">
                                <input type="text" class="layui-input layui-bg-gray" style="width: 85px;"
                                       value="${item.columns.model}" disabled>
                            </div>
                            <span class="layui-inline">X </span>
                            <div class="layui-inline">
                                <input type="text" class="layui-input layui-bg-gray" style="width: 85px;"
                                       value="${item.columns.num}" disabled>
                            </div>
                        </div>
                    </div>
                </div>
            </c:forEach>
            <c:forEach var="item" items="${gridSupportList}" varStatus="vs">
                <div class="layui-row">
                    <div class="layui-col-lg5 layui-col-sm7">
                        <label class="layui-form-label"><c:if test="${readOnly ne '1'}"><i class="mark">*</i></c:if>支架：</label>
                        <div class="layui-input-block">
                            <div class="layui-inline">
                                <input type="text" class="layui-input layui-bg-gray" style="width: 85px;"
                                       value="${item.columns.model}" disabled>
                            </div>
                            <span class="layui-inline">X </span>
                            <div class="layui-inline">
                                <input type="text" class="layui-input layui-bg-gray" style="width: 85px;"
                                       value="${item.columns.num}" disabled>
                            </div>
                        </div>
                    </div>
                </div>
            </c:forEach>
        </div>
        <div class="layui-row mt-10">
            <div class="layui-col-xs12">
                <label class="layui-form-label">方案备注：</label>
                <div class="layui-input-block">
                    <textarea name="schemeRemarks" id="schemeRemarks" class="layui-textarea layui-bg-gray"
                              lay-verify="required" disabled>${entry.schemeRemarks}</textarea>
                </div>
            </div>
        </div>
        </c:if>

        <input type="hidden" name="id" id="id" value="${plan.columns.id}">
        <input type="hidden" name="type" id="type" value="${type}">
    </div>
    <c:if test="${readOnly ne '1'}">
        <div class="layui-form-item operate-footer" style="text-align: center;">
            <c:if test="${mode ne 'view'}">
                <input type="button" lay-submit lay-filter="confirm" id="confirm" class="layui-btn " value="确认">
            </c:if>
            <button type="button" class="layui-btn layui-btn-primary " onclick="closeDiv();">取消</button>
        </div>
    </c:if>
</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 src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/data.js"></script>--%>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.js"></script>
<script src="${ctxPlugin}/lib/base64.js"></script>
<script type="text/javascript">
    var viewer = new Viewer(document.getElementById('LAY_app'));
    //初始数据
    var $form;
    var form;
    var upload;
    var $;
    var imgs = '';
    var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
    var type = '${type}';
    layui.use(['form', 'table', 'upload', 'jquery'], function () {
        $ = layui.jquery;
        form = layui.form;
        upload = layui.upload;
        $form = $('form');


        form.verify({
            attach: function (value) {
                if (isBlank(value)) {
                    return "请上传附件";
                }
            }
        });

        if (${mode eq 'view'}) {
            $('input').prop('disabled', true);
        }

        $(document).on('mouseenter', '#materialTable td', function () {
            var that = this;
            $(that).attr('title', $(that).text());
        });

        window.importMaterial = function (data) {
            var html = "";
            for (var i = 0; i < data.length; i++) {
                html += "<tr>";
                html += '<td>' + (i + 1) + '</td>';
                html += '<td>' + data[i].code + '</td>';
                html += '<td>' + data[i].name + '</td>';
                html += '<td>' + data[i].spec + '</td>';
                html += '<td>' + data[i].unit + '</td>';
                html += '<td>' + data[i].amount + '</td>';
                html += "</tr>";
            }

            $('#materialTable').empty().append(html);
        }

        $('#uploadFile').change(function () {
            if ($('#attachFile >li').length >= 1) {
                layer.msg("最多只能传入一个附件！")
                return;
            }
            var file = $(this)[0].files[0];
            if (isBlank(file)) {
                console.log(111);
                return;
            }
            console.log(file)
            var formData = new FormData();
            formData.append("file", file);
            $.ajax({
                url: "${ctx}/common/uploadFile",
                type: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                success: function (data) {
                    if (type == '2') {
                        $('#attachFile').append('<li><span style="position: relative; top: 4px;" class="uploadFileName">' + file.name + '</span><input type="hidden" name="attach"  value="' + data.path + '"> <input type="hidden" name="attachName" value="' + file.name + '"/><span class="hx_del">删除</span> ');
                    } else {
                        $('#attachFile').append('<li><span style="position: relative; top: 4px;" class="uploadFileName">' + file.name + '</span><input type="hidden" name="attach"  value="' + data.path + '"> <input type="hidden" name="attachName" value="' + file.name + '"/> <span class="hx_del">删除</span>');
                        /* $('.uploadFileName').text(file.name).removeClass('layui-hide');
                         $('input[name=attach]').val(data.path);
                         $('input[name=attachName]').val(file.name);*/
                    }
                    $("#addFile").hide();
                }
            });
        });

        var saveFlag = true;
        form.on('submit(confirm)', function (data) {
            if (!saveFlag) {
                return;
            }
            var plan = {};
            plan.id = data.field.id;
            plan.code = data.field.code;
            plan.name = data.field.name;
            plan.attach = $("input[name=attach]").eq(0).val();
            plan.attachName = $("input[name=attachName]").eq(0).val();
            if (isBlank(plan.attach)) {
                layer.msg("请上传附件");
                return;
            }
            plan.planTypeId = data.field.planTypeId;
            plan.planType = $("#planTypeId").find("option:selected").text();

            plan.type = data.field.type;

            console.log(plan);
            saveFlag = false;
            $.ajax({
                url: '${ctx}/planManage/add',
                method: 'post',
                contentType: 'application/json',
                data: JSON.stringify(plan),
                dataType: 'JSON',
                success: function (res) {
                    if (res.code == "200") {
                        parent.layer.msg("保存成功", {time: 1000});
                        closeDiv();
                        parent.table.reload('test');
                    } else if (res.code == "501") {
                        layer.msg(res.errMsg, {time: 1500}, function () {
                            saveFlag = true;
                        });
                    } else if (res.code == '422') {
                        layer.msg(res.msg, {time: 1500}, function () {
                            saveFlag = true;
                        });
                    } else {
                        layer.msg("保存失败", {time: 1000});
                    }
                },
                complete: function () {

                }
            });
        });

        var uploadInst = upload.render({
            elem: '#uploader' //绑定元素
            , url: '${ctx}/common/uploadFile' //上传接口
            , accept: 'file',
            acceptMime: 'application/pdf',
            exts: 'pdf'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {

                });
            }
            , done: function (res) {
                /* imgs+=res.path+',';
                 $("#imgs").val(imgs);*/
                //上传完毕回调
                addImg(res.path);
            }
            , error: function () {
                //请求异常回调
            }
        });

        $(document).on('click', '.hx_del', function () {
            $('#attachFile').html("");
            $("#addFile").show();
        });

    })

    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 previewUrl(_url) {
        if (!checkUrl(_url)) {
            return false;
        }
        var base = new Base64();
        var b64Encoded = base.encode(_url);
        if(_url.endsWith('pdf')){
            window.open('http://47.98.203.224:8012/onlinePreview?url=' + encodeURIComponent(b64Encoded)+'&officePreviewType=pdf');
        }else{
            window.open('http://47.98.203.224:8012/onlinePreview?url=' + encodeURIComponent(b64Encoded));
        }
    }

    function checkUrl(url) {
        //url= 协议://(ftp的登录信息)[IP|域名](:端口号)(/或?请求参数)
        var strRegex = '^((https|http|ftp)://)'//(https或http或ftp)
            + '(([\\w_!~*\'()\\.&=+$%-]+: )?[\\w_!~*\'()\\.&=+$%-]+@)?' //ftp的user@  可有可无
            + '(([0-9]{1,3}\\.){3}[0-9]{1,3}' // IP形式的URL- 3位数字.3位数字.3位数字.3位数字
            + '|' // 允许IP和DOMAIN（域名）
            + '(localhost)|'	//匹配localhost
            + '([\\w_!~*\'()-]+\\.)*' // 域名- 至少一个[英文或数字_!~*\'()-]加上.
            + '\\w+\\.' // 一级域名 -英文或数字  加上.
            + '[a-zA-Z]{1,6})' // 顶级域名- 1-6位英文
            + '(:[0-9]{1,5})?' // 端口- :80 ,1-5位数字
            + '((/?)|' // url无参数结尾 - 斜杆或这没有
            + '(/[\\w_!~*\'()\\.;?:@&=+$,%#-]+)+/?)$';//请求参数结尾- 英文或数字和[]内的各种字符
        var re = new RegExp(strRegex, 'i');//i不区分大小写
        //将url做uri转码后再匹配，解除请求参数中的中文和空字符影响
        if (re.test(encodeURI(url))) {
            return (true);
        } else {
            return (false);
        }
    }
</script>
</body>
</html>
