<%@ 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" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.css" media="all">
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        table{
            text-align: left;
        }
        .tableHeader{
            height: 38px;
            /*line-height: 38px;*/
            background-color: #d2b790 !important; color: #FFF;
        }
        .title{
            font-weight: bold;
            font-size: 14px;
            line-height: 30px;
            text-align: left;
        }
        td{
            padding: 0 5px;
        }
        .add{
            width: 60px;
            height: 60px;
            bordeR:1px solid #dddddd;
            position: relative;
            /*float: left;*/
            margin: 5px auto;
        }
        .add span{
            position: absolute;
            left: 0;top: 0;
            z-index: 0;
            width: 100%;
            height: 100%;
            font-size: 20px;
            text-align: center;
            line-height: 60px;
            font-weight: normal;
        }
        .add input{
            width: 100%;
            height: 100%;
            opacity: 0;
            position: absolute;
            z-index:10;
            left: 0;
            top: 0;
        }
        .bj-img > span {
            position: absolute;
            right: 0;
            top: 0;
            background-color: #f00;
            width: 20px;
            height: 20px;
            line-height: 20px;
            text-align: center;
            color: #fff;
            cursor: pointer;
            display: none;
        }
        .bj-img:hover span {
            display: block;
        }
        .img{
            overflow: hidden;
            padding: 5px 0;
            display: flex;
            justify-content: center;
        }
        .img>ul{
            float: left;
            list-style: none;
        }
        .img li{
            width: 60px;
            height: 60px;
            bordeR:1px solid #dddddd;
            position: relative;
            float: left;
            margin-right: 10px;
        }
        .img li img{
            object-fit: scale-down;
            width: 100%;
            height: 100%;
        }
        .img+span{
            line-height: 30px;
            font-size: 12px;
            color: red;
        }
        .pd-20{
            padding: 20px;
        }
        .form-title{
            line-height: 40px;
            font-weight: bold;
        }
        .form-input{
            width: 100%;
            padding: 5px 0;
            border: none;
            outline: none;
        }
        .red{
            color: red;
        }
        .unit{
            position: absolute;
            right: 30px;
            top: 8px;
            font-weight: bold;
        }
        .pos-r{
            position: relative;
        }

        .no-resize{
            resize: none;
        }
        .flex{
            display: flex;
        }
        .text-r{
            text-align: right;
        }
        .m-10{
            margin: 10px;
        }
        .operate-footer {
            width: 100%;
            position: fixed;
            bottom: 0;
            z-index: 30000;
            background: #F8F8F8;
            padding: 10px 0;
            text-align: center;
        }
        .footer-btn {
            height: 27px;
            line-height: 27px;
            padding: 0 18px;
            border-radius: 2px;
            font-size: 14px;
            cursor: pointer;
            border: 1px solid #C9C9C9;
            background-color: #fff;
            outline: none;
        }
        .pb-50{
            padding-bottom: 50px;
        }
        .pd-10{
            padding: 10px;
        }
        .normal-btn{
            border: 1px solid #D9B589;
            background-color: #D9B589 !important;
            color: #fff;
        }
        .layui-layer-btn0{
            border-color:#D9B589 !important;
            background-color: #D9B589 !important;
        }
        .idea-text{
            width: 320px; height: 100px;outline: none; padding: 3px
        }
        .hide{
            display: none;
        }
        .f-l{
            float: left;
        }
        .title1 {
            /*border-left: 4px solid #D9B589;*/
            padding-left: 10px;
            font-size: 14px;
            margin: 10px auto 0 auto;
            font-weight: 600;
            height: 42px;
            line-height: 42px;
            background-color: #848484;
            color: #FFF;
        }
        .mark {
            color: #ff0000;
            line-height: 15px;
            width: 8px;
            display: inline-block;
            text-align: left;
        }
        .report-table{background: #fff}
        .report-table td{border: 1px solid #dddddd; padding: 5px 10px}
        .report-table tr:nth-child(even) {
            background-color: #f7f7f7;
        }
        .report-table tr:nth-child(odd) {
            background-color: #ffffff;
        }
        .blank-img {
            background: url('${ctxPlugin}/static/imgs/blankImg.png') center center no-repeat;
            width: 62px;
            height: 62px;
            display: inline-block;
        }
        .pointer {
            cursor: pointer;
        }
    </style>
</head>
<body>

<div class="layui-fluid pd-20"  id="LAY_app" style="padding-bottom: 70px;">
    <table border cellpadding="0" cellspacing="0" width="100%" class="report-table">

        <tr class="tableHeader">
            <td colspan="8">项目信息</td>
        </tr>

        <tr>
            <td width="25%" colspan="2">电站编号</td>
            <td width="25%" colspan="2"><input type="text" class="form-input" value="${entry.powerStationCode}"
                                               disabled/></td>
            <td width="25%" colspan="2">产品名称</td>
            <td width="25%" colspan="2"><input type="text" class="form-input" disabled value="${entry.projectId}"/></td>
        </tr>
        <tr>
            <td colspan="2">代理商</td>
            <td colspan="2"><input type="text" class="form-input" disabled value="${entry.traderName}"/></td>
            <td colspan="2">项目公司</td>
            <td colspan="2"><input type="text" class="form-input" disabled value="${entry.projectCompanyName}"/></td>
        </tr>
        <tr>
            <td colspan="2">电站状态</td>
            <td colspan="2"><input type="text" class="form-input" disabled value="已完成"/></td>
            <td colspan="2">业务员</td>
            <td colspan="2"><input type="text" class="form-input" disabled value="${entry.creator}"/></td>
        </tr>
        <tr>
            <td colspan="2">创建时间</td>
            <td colspan="6"><input type="text" class="form-input" disabled value="<fmt:formatDate value="${entry.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"/></td>
        </tr>

        <tr class="tableHeader">
            <td colspan="8">并网信息</td>
        </tr>
        <tr>
            <td colspan="2"><i class="mark">*</i>发电户号</td>
            <td colspan="2"><input type="text" class="layui-input" id="generatorNo"}
                                   name="generatorNo" value="${entry.generatorNo}"/></td>
            <td colspan="2"><i class="mark">*</i>保险单号</td>
            <td colspan="2"><input type="text" class="layui-input" id="insuranceNumber"}
                                   name="insuranceNumber" value="${entry.insuranceNumber}"/></td>
        </tr>
<%--            <tr>--%>
<%--                <td colspan="2"><i class="mark">*</i>购售电地址是否一致</td>--%>
<%--                <td colspan="2">--%>
<%--                    <div class="layui-form">--%>
<%--                        <div class="layui-input-block" style="margin-left: 0">--%>
<%--                            <select name="addressConsistent" id="addressConsistent" lay-filter="addressConsistent">--%>
<%--                                <option value="">请选择</option>--%>
<%--                                <option value="Y" <c:if test="${entry.addressConsistent eq 'Y'}">selected</c:if> >是</option>--%>
<%--                                <option value="N" <c:if test="${entry.addressConsistent eq 'N'}">selected</c:if> >否</option>--%>
<%--                            </select>--%>
<%--                        </div>--%>
<%--                    </div>--%>
<%--                </td>--%>
<%--                <td colspan="4">--%>
<%--            </tr>--%>
<%--            <tr <c:if test="${empty entry.addressConsistent or entry.addressConsistent eq 'Y'}">style="display: none;"</c:if> id="addressInputs">--%>
<%--                <td width="25%" colspan="2"><i class="mark addressDiv">*</i>购售电地址</td>--%>
<%--                <td width="75%" colspan="6">--%>
<%--                 <div class="layui-form addressDiv" <c:if test="${entry.addressConsistent ne 'N'}">style="display: none"</c:if> >--%>
<%--                            <div class="layui-input-block" style="margin-left: 0">--%>
<%--                                <div class="layui-col-sm2 pr-10" style="width: 22%">--%>
<%--                                    <select name="province" id="province" lay-filter="province" lay-search>--%>
<%--                                        <option value="">请选择省</option>--%>
<%--                                        <c:forEach items="${pros}" var="pro">--%>
<%--                                            <option value="${pro.columns.ProvinceName}"--%>
<%--                                                    title="${pro.columns.ProvinceID }"--%>
<%--                                                    <c:if test="${entry.electricProvince eq pro.columns.ProvinceName}">selected</c:if>>${pro.columns.ProvinceName}</option>--%>
<%--                                        </c:forEach>--%>
<%--                                    </select>--%>
<%--                                </div>--%>
<%--                                <div class="layui-col-sm2 pr-10" style="width: 22%">--%>
<%--                                    <select name="city" id="city" lay-filter="city" lay-search>--%>
<%--                                        <option value="">请选择市</option>--%>
<%--                                        <c:forEach items="${faccitys}" var="city">--%>
<%--                                            <option value="${city.columns.CityName}"--%>
<%--                                                    <c:if test="${entry.electricCity eq city.columns.CityName}">selected</c:if>--%>
<%--                                                    title="${city.columns.CityID}">${city.columns.CityName}</option>--%>
<%--                                        </c:forEach>--%>
<%--                                    </select>--%>
<%--                                </div>--%>
<%--                                <div class="layui-col-sm2 pr-10" style="width: 22%">--%>
<%--                                    <select name="area" id="area" lay-search>--%>
<%--                                        <option value="">请选择县/区</option>--%>
<%--                                        <c:forEach items="${areas}" var="area">--%>
<%--                                            <option value="${area.columns.DistrictName}"--%>
<%--                                                    <c:if test="${entry.electricArea eq area.columns.DistrictName}">selected</c:if>--%>
<%--                                                    title="${area.columns.DistrictID}">${area.columns.DistrictName}</option>--%>
<%--                                        </c:forEach>--%>
<%--                                    </select>--%>
<%--                                </div>--%>

<%--                                <div class="layui-col-sm4">--%>
<%--                                    <input type="text" name="address" id="address" placeholder=""--%>
<%--                                           autocomplete="off" class="layui-input layui-col-lg2 "--%>
<%--                                           value="${entry.electricAddress}">--%>
<%--                                </div>--%>
<%--                            </div>--%>
<%--                        </div>--%>
<%--                </td>--%>
<%--            </tr>--%>
            <tr>
                <td colspan="2"><i class="mark">*</i>购售电合同</td>
                <td colspan="6" id="xsdTD">
                    <div class="layui-input-block pos-r" style="display: flex;align-items: center;margin-left: 0;">
                        <span class="h-32 lh-32 layui-span-unit" style="color:#2890ac;">上传</span>
                        <input type="file" id="uploadFile" style="position: absolute; z-index: 3; opacity: 0; left: 0; width: 44px;"/>
                        <input type="hidden" id="contractFile" value="${report.fixConclusion}"/>
                        <span id="contractFilename">${fns:substringAfterLast(report.fixConclusion, '/')}</span>
                    </div>
                </td>
            </tr>
<%--            <tr>--%>
<%--                <td colspan="2" rowspan="2">电站并网照片</td>--%>
<%--                <td colspan="2"><i class="mark">*</i>近3天发电量</td>--%>
<%--                <td colspan="2">补充信息</td>--%>
<%--                <td colspan="2">补充信息2</td>--%>
<%--            </tr>--%>
<%--            <tr>--%>
<%--                <td colspan="2" id="yxImgTD">--%>
<%--                    <c:if test="${not empty report.yxImg}">--%>
<%--                        <ul class="img">--%>
<%--                            <li class="imgsLi bj-img ">--%>
<%--                                <span class="layui-icon-close layui-icon" onclick="delImg(this,1)"></span>--%>
<%--                                <img src="${report.yxImg}" alt="">--%>
<%--                                <input type="hidden" class="imgValues pointer" id="yxImg" value="${report.yxImg}">--%>
<%--                            </li>--%>
<%--                        </ul>--%>
<%--                        <div class="add layui-hide">--%>
<%--                            <span>+</span>--%>
<%--                            <input type="file" class="uploadFile pointer" max-num="1" accept="image/*">--%>
<%--                        </div>--%>
<%--                    </c:if>--%>
<%--                    <c:if test="${empty report.yxImg}">--%>
<%--                        <div class="add">--%>
<%--                            <span>+</span>--%>
<%--                            <input type="file" class="uploadFile pointer" max-num="1" accept="image/*">--%>
<%--                        </div>--%>
<%--                    </c:if>--%>
<%--                </td>--%>
<%--                <td colspan="2" id="gebImgTD">--%>
<%--                    <c:if test="${not empty report.gebImg}">--%>
<%--                        <ul class="img">--%>
<%--                            <li class="imgsLi bj-img ">--%>
<%--                                <span class="layui-icon-close layui-icon" onclick="delImg(this,1)"></span>--%>
<%--                                <img src="${report.gebImg}" alt="">--%>
<%--                                <input type="hidden" class="imgValues" id="gebImg" value="${report.gebImg}">--%>
<%--                            </li>--%>
<%--                        </ul>--%>
<%--                        <div class="add layui-hide">--%>
<%--                            <span>+</span>--%>
<%--                            <input type="file" class="uploadFile pointer" max-num="1" accept="image/*">--%>
<%--                        </div>--%>
<%--                    </c:if>--%>
<%--                    <c:if test="${empty report.gebImg}">--%>
<%--                            <div class="add">--%>
<%--                                <span>+</span>--%>
<%--                                <input type="file" class="uploadFile pointer" max-num="1" accept="image/*">--%>
<%--                            </div>--%>
<%--                        </c:if>--%>
<%--                </td>--%>
<%--                <td colspan="2" id="gebImg2TD">--%>
<%--                    <c:if test="${not empty report.gebImg2}">--%>
<%--                        <ul class="img">--%>
<%--                            <li class="imgsLi bj-img ">--%>
<%--                                <span class="layui-icon-close layui-icon" onclick="delImg(this,1)"></span>--%>
<%--                                <img src="${report.gebImg2}" alt="">--%>
<%--                                <input type="hidden" class="imgValues" id="gebImg2" value="${report.gebImg2}">--%>
<%--                            </li>--%>
<%--                        </ul>--%>
<%--                        <div class="add layui-hide">--%>
<%--                            <span>+</span>--%>
<%--                            <input type="file" class="uploadFile pointer" max-num="1" accept="image/*">--%>
<%--                        </div>--%>
<%--                    </c:if>--%>
<%--                    <c:if test="${empty report.gebImg2}">--%>
<%--                        <div class="add">--%>
<%--                            <span>+</span>--%>
<%--                            <input type="file" class="uploadFile pointer" max-num="1" accept="image/*">--%>
<%--                        </div>--%>
<%--                    </c:if>--%>
<%--                </td>--%>
<%--            </tr>--%>
            <tr>
                <td colspan = '2'><i class="mark">*</i>三天发电量截图:</td>
                <td colspan="6">
                    <c:if test="${not empty report.powerCapacityUrl}">
                        <ul class="img">
                            <li class="imgsLi bj-img ">
                                <span class="layui-icon-close layui-icon" onclick="delImg(this,1)"></span>
                                <img src="${report.powerCapacityUrl}" alt="">
                                <input type="hidden" class="imgValues" id="powerCapacityUrl" value="${report.powerCapacityUrl}">
                            </li>
                        </ul>
                        <div class="add layui-hide">
                            <span>+</span>
                            <input type="file" class="uploadPowerCapacityUrl pointer" max-num="1" accept="image/*">
                        </div>
                    </c:if>
                    <c:if test="${empty report.powerCapacityUrl}">
                        <div class="add">
                            <span>+</span>
                            <input type="file" class="uploadPowerCapacityUrl pointer" max-num="1" accept="image/*">
                        </div>
                    </c:if>
                </td>
            </tr>
            <tr>
            <td colspan="2"><i class="mark">*</i>电表照片</td>
            <td colspan="6">
                <c:if test="${not empty report.dbImgs}">
                    <ul id="dbImgsul" class="img">
                        <c:forEach items="${report.dbImgs}" var="file" varStatus="vs">
                            <li class="imgsLi bj-img ">
                                <span class="layui-icon-close layui-icon" onclick="delImg2(this,1)"></span>
                                <img src="${file}" alt="">
                                <input type="hidden" class="dbImgs" id="dbImgs" value="${file}">
                            </li>
                        </c:forEach>
                    </ul>
                    <div class="add layui-hide">
                        <span>+</span>
                        <input type="file" class="uploadDbImgs pointer" max-num="2" accept="image/*">
                    </div>
                </c:if>`
                <c:if test="${empty report.dbImgs}">
                    <ul id="dbImgsul" class="img">
                    </ul>
                    <div class="add">
                        <span>+</span>
                        <input type="file" class="uploadDbImgs pointer" max-num="2" accept="image/*">
                    </div>
                </c:if>
            </td>
        </tr>
            <tr>
                <td colspan="2"><i class="mark">*</i>电表箱照片</td>
                <td colspan="6">
                    <c:if test="${not empty report.safetyWarningImg}">
                        <ul id="safetyWarningImgul" class="img">
                            <c:forEach items="${report.safetyWarningImg}" var="file" varStatus="vs">
                                <li class="imgsLi bj-img ">
                                    <span class="layui-icon-close layui-icon" onclick="delImg2(this,1)"></span>
                                    <img src="${file}" alt="">
                                    <input type="hidden" class="safetyWarningImg" id="safetyWarningImg" value="${file}">
                                </li>
                            </c:forEach>
                        </ul>
                        <div class="add layui-hide">
                            <span>+</span>
                            <input type="file" class="uploadDbxImgs pointer" max-num="1" accept="image/*">
                        </div>
                    </c:if>
                    <c:if test="${empty report.safetyWarningImg}">
                        <ul id="safetyWarningImgul" class="img">
                        </ul>
                        <div class="add">
                            <span>+</span>
                            <input type="file" class="uploadDbxImgs pointer" max-num="1" accept="image/*">
                        </div>
                    </c:if>
                </td>
            </tr>
        <tr style="height: 100px">
            <td colspan="2">其他附件(荷载报告、接入方案，并网意见单等)</td>
            <td colspan="6">
                <div class="layui-input-block img-box" style="margin-left: 20px;">
                    <div style="display: flex;flex-wrap: wrap;">
                        <div id="supplementUrlDiv">
                            <div id="supplementUrlUploader"
                                    <c:if test="${supplementUrlCount >= 9}">style="display: none"</c:if>
                            >
                                   <span style="color:blue;cursor: pointer" id="supplementUrl">上传</span>
                            </div>
                            <c:if test="${not empty report.supplementUrl }">
                                <c:forEach items="${report.supplementUrl }" var="file"  varStatus="vs">
                                    <div style="margin-top: 5px">
                                         <span style="color: red" class="layui-icon-close layui-icon" onclick="delImg3(this,'supplementUrlUploader')"></span>
                                        <a style="color:#2890ac;" target="_blank" onclick="previewUrl('${file}')" class="download-link">${fns:substringAfterLast(file, '/')}</a>
                                        <input type="hidden" class="supplementUrl"   value="${file}">
                                    </div>
                                </c:forEach>
                            </c:if>
                        </div>
                    </div>
                </div>
            </td>
        </tr>
<%--        <tr>--%>
<%--            <td colspan="2"><i class="mark">*</i>并网调试报告</td>--%>
<%--            <td colspan="6">--%>
<%--                <div class="layui-input-block pos-r" style="display: flex;align-items: center;margin-left: 0;">--%>
<%--                    <c:if test="${opt ne 'TwoMergeAccept'}">--%>
<%--                        <span class="h-32 lh-32 layui-span-unit" style="color:#2890ac;">上传</span>--%>
<%--                        <input type="file" id="uploadReport" style="position: absolute; z-index: 3; opacity: 0; left: 0; width: 44px;"/>--%>
<%--                        <input type="hidden" id="bwtsFile" name="bwtsFile" value="${insurance.bwtsFile}"/>--%>
<%--                        <div id="bwtsFileName" style="text-overflow: ellipsis;max-width: 130px;white-space: nowrap;overflow: hidden;">${insurance.bwtsFilename}</div>--%>
<%--                    </c:if>--%>
<%--                    <c:if test="${opt eq 'TwoMergeAccept'}">--%>

<%--                        <div class="layui-input-block pos-r view-attachment">--%>
<%--                            <a class="h-32 lh-32 layui-span-unit lookBtn" target="_blank" href="${commonStaticImgPath}${insurance.bwtsFile}" style="color: #2890ac;">${insurance.bwtsFilename}</a>--%>
<%--                        </div>--%>
<%--                    </c:if>--%>

<%--                </div>--%>
<%--            </td>--%>
<%--        </tr>--%>
    </table>

</div>

<div class="operate-footer">
    <button class="footer-btn normal-btn mergeSubmitBtn">保存</button>
    <button class="footer-btn" onclick="closeSelf();">取消</button>
</div>

<script src="https://cdn.bootcss.com/html2canvas/0.5.0-beta4/html2canvas.min.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/factory.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.js"></script>
<script src="${ctxPlugin}/lib/base64.js"></script>
<script>
    //图片查看效果
    var viewer = new Viewer(document.getElementById('LAY_app'));
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','upload','form'], function(){
        //layui.use(['table','layer','laypage','laydate','form'], function(){
        $ = layui.$;
        tableExt = layui.tableExt;
        layer = layui.layer;
        laypage = layui.laypage;
        laydate = layui.laydate;
        form = layui.form;
        table = tableExt.getLayTable();
        var upload = layui.upload;
        upload.render({
            elem: '#supplementUrlUploader',
            url: '${ctx}/common/uploadFile3',
            accept: 'file',
            exts: 'jpg|png|gif|doc|docx|ppt|pdf|xls|xlsx',
            before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                });
            },
            done: function (res) {
                //上传完毕回调
                let path = res.path;
                let index = path.lastIndexOf('/');
                let name = path.substring(index + 1);
                let imgCount = $("#supplementUrlDiv").find(".supplementUrl").length;
                if ((imgCount + 1) >= 9) {
                        $("#supplementUrlUploader").hide();
                    }
                let html = '<div style="margin-top: 5px"><span style="color: red" class="layui-icon-close layui-icon" onclick="delImg3(this,\'supplementUrlUploader\')"></span>';
                html += '<a style="color:#2890ac;"  target="_blank" onclick="previewUrl(' + "\'" + '${commonStaticImgPath}' + path + "\'" + ')"    class="download-link">' + name + '</a>';
                html += '<input type="hidden" class="supplementUrl" value="${commonStaticImgPath}' + path + '"/> </div>';
                $("#supplementUrlDiv").append(html);
            },
            error: function () {
                //请求异常回调
            }
        });

        $('#uploadFile').change(function () {

            var file = $(this)[0].files[0];
            if(isBlank(file)){
                return;
            }
            var formData = new FormData();
            formData.append("file", file);
            $.ajax({
                url: "${ctx}/common/uploadFile",
                type: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                success: function (data) {
                    $("#contractFile").val('${commonStaticImgPath}'+data.path);
                    $("#contractFilename").text(file.name);
                }
            });
        });

        <%--$('#uploadReport').change(function () {--%>
        <%--    var file = $(this)[0].files[0];--%>
        <%--    if(isBlank(file)){--%>
        <%--        return;--%>
        <%--    }--%>
        <%--    var formData = new FormData();--%>
        <%--    formData.append("file", file);--%>
        <%--    $.ajax({--%>
        <%--        url: "${ctx}/common/uploadFile",--%>
        <%--        type: 'POST',--%>
        <%--        data: formData,--%>
        <%--        processData: false,--%>
        <%--        contentType: false,--%>
        <%--        success: function (data) {--%>
        <%--            $("#bwtsFile").val(data.path);--%>
        <%--            $("#bwtsFileName").text(file.name);--%>
        <%--        }--%>
        <%--    });--%>
        <%--});--%>

        <%--$('#uploadBxd').change(function () {--%>
        <%--    var file = $(this)[0].files[0];--%>
        <%--    if(isBlank(file)){--%>
        <%--        return;--%>
        <%--    }--%>
        <%--    var formData = new FormData();--%>
        <%--    formData.append("file", file);--%>
        <%--    $.ajax({--%>
        <%--        url: "${ctx}/common/uploadFile",--%>
        <%--        type: 'POST',--%>
        <%--        data: formData,--%>
        <%--        processData: false,--%>
        <%--        contentType: false,--%>
        <%--        success: function (data) {--%>
        <%--            $("#bxdFile").val(data.path);--%>
        <%--            $("#bxdFileName").text(file.name);--%>
        <%--        }--%>
        <%--    });--%>
        <%--});--%>


        $('.uploadDbImgs').change(function(){
            var $this = $(this);
            var file = $(this)[0].files[0];
            if(isBlank(file)){
                return;
            }
            var formData = new FormData();
            formData.append("file", file);
            $.ajax({
                url: "${ctx}/common/uploadFile",
                type: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                success: function (data) {
                    var maxNum = $this.attr('max-num');
                    var html = ' <li class="imgsLi bj-img ">' +
                        '           <span class="layui-icon-close layui-icon" onclick="delImg2(this,'+maxNum+')"></span>'+
                        '            <img src="${commonStaticImgPaths}' + data.path + '" alt="">' +
                        '            <input type="hidden" class="dbImgs" id="dbImgs" value="${commonStaticImgPaths}' + data.path + '">'+
                        '          </li>';
                    $("#dbImgsul").append(html)
                    var imgCount=$(".dbImgs").length;
                    if((imgCount)>=2){
                        $this.closest('.add').addClass('layui-hide');
                    }
                }
            });
        });
        $('.uploadPowerCapacityUrl').change(function(){
            var $this = $(this);
            var file = $(this)[0].files[0];
            if(isBlank(file)){
                return;
            }
            var formData = new FormData();
            formData.append("file", file);
            $.ajax({
                url: "${ctx}/common/uploadFile",
                type: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                success: function (data) {
                    var maxNum = $this.attr('max-num');
                    var html = '<ul class="img"> ' +
                        '         <li class="imgsLi bj-img ">' +
                        '           <span class="layui-icon-close layui-icon" onclick="delImg(this,'+maxNum+')"></span>'+
                        '            <img src="${commonStaticImgPaths}' + data.path + '" alt="">' +
                        '            <input type="hidden" class="imgValues" id="powerCapacityUrl" value="${commonStaticImgPaths}' + data.path + '">'+
                        '          </li>' +
                        '        </ul>';
                    $this.closest('.add').before(html);
                    $this.closest('.add').addClass('layui-hide');

                }
            });
        });

        $('.uploadDbxImgs').change(function(){
            var $this = $(this);
            var file = $(this)[0].files[0];
            if(isBlank(file)){
                return;
            }
            var formData = new FormData();
            formData.append("file", file);
            $.ajax({
                url: "${ctx}/common/uploadFile",
                type: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                success: function (data) {
                    var maxNum = $this.attr('max-num');
                    var html = ' <li class="imgsLi bj-img ">' +
                        '           <span class="layui-icon-close layui-icon" onclick="delImg2(this,'+maxNum+')"></span>'+
                        '            <img src="${commonStaticImgPaths}' + data.path + '" alt="">' +
                        '            <input type="hidden" class="safetyWarningImg" id="safetyWarningImg" value="${commonStaticImgPaths}' + data.path + '">'+
                        '          </li>';
                        $("#safetyWarningImgul").append(html);
                    // $this.closest('.add').before(html);
                    var imgCount=$(".safetyWarningImg").length;
                    if((imgCount)>=2){
                        $this.closest('.add').addClass('layui-hide');
                    }

                }
            });
        });

        function getImgs(selector){
            var arr = [];
            $(selector).find('input.imgValues').each(function(){
                arr.push($(this).val());
            });
            return arr.join(",");
        }

        $('.uploadFile').change(function(){
            var $this = $(this);
            var file = $(this)[0].files[0];
            if(isBlank(file)){
                return;
            }
            var formData = new FormData();
            formData.append("file", file);
            $.ajax({
                url: "${ctx}/common/uploadFile",
                type: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                success: function (data) {
                    var maxNum = $this.attr('max-num');
                    var html = '<ul class="img"> ' +
                        '         <li class="imgsLi bj-img ">' +
                        '           <span class="layui-icon-close layui-icon" onclick="delImg(this,'+maxNum+')"></span>'+
                        '            <img src="${commonStaticImgPaths}' + data.path + '" alt="">' +
                        '            <input type="hidden" class="imgValues" value="' + data.path + '">'+
                        '          </li>' +
                        '        </ul>';
                    $this.closest('.add').before(html);
                    var length = $this.closest('td').find('ul').length;
                    if(!isBlank(maxNum) && length >= maxNum){
                        $this.closest('.add').addClass('layui-hide');
                    }
                }
            });
        });

        function afterSuccess(data) {
            console.log(data)
            if (data.code === '200') {
                layer.msg('操作成功', {icon: 1,time:500},function (){
                    closeSelf();
                    parent.searchOrder();
                });

            } else if (data.code === '500') {
                layer.msg(data.errMsg, {icon: 2});
            } else if (data.code === '501') {
                layer.msg(data.errMsg, {icon: 2});
            }else if (data.code === '400' && !isBlank(data.errMsg)) {
                layer.msg(data.errMsg, {icon: 2});
            } else {
                layer.msg('操作失败', {icon: 2});
            }
        }

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

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

        function getInsurance() {
            return {
                id: $("#insuranceId").val(),
                entryId: '${entry.id}',

                bwtsFile: $("input[name='bwtsFile']").val(),
                bwtsFilename: $("#bwtsFileName").text()
            };
        }

        //并网提交
        $('.mergeSubmitBtn').click(function(){
            var $this = $(this);
            //发电户号
            var generatorNo = $('input[name="generatorNo"]').val();
            if (isBlank(generatorNo)) {
                layer.msg('发电户号不能为空');
                return;
            }
            var insuranceNumber = $('input[name="insuranceNumber"]').val();
            if (isBlank(insuranceNumber)) {
                layer.msg('保险单号不能为空');
                return;
            }
            //购售电合同
            let contractFile = $("#contractFile").val();
            if (isBlank(contractFile)) {
                layer.msg('购售电合同不能为空');
                return;
            }
            //三天连续发电量监控系统截图
            var powerCapacityUrl = $("#powerCapacityUrl").val();
            if (isBlank(powerCapacityUrl)) {
                layer.msg('三天发电量截图不能为空');
                return;
            }
            var dbImgs = [];
            $(".dbImgs").each(function(){
                dbImgs.push($(this).val());
            })
            if (dbImgs.length==0) {
                layer.msg('电表照片不能为空');
                return;
            }

            var dbxImgs = [];
            $(".safetyWarningImg").each(function(){
                dbxImgs.push($(this).val());
            })
            if (dbxImgs.length==0) {
                layer.msg('电表箱照片不能为空');
                return;
            }
            //其他附件
            let supplementUrl = "";
            $(".supplementUrl").each(function () {
                if (isBlank(supplementUrl)) {
                    supplementUrl = $(this).val();
                } else {
                    supplementUrl = supplementUrl + "," + $(this).val();
                }
            });
            $this.prop('disabled', true);
            var order = {
                entryId: '${entry.id}',
                generatorNo: generatorNo,
                insuranceNumber:insuranceNumber,
                dbImgs:dbImgs.join(","),
                dbxImgs:dbxImgs.join(","),
                contractFile: contractFile,
                contractFilename: $("#contractFilename").text(),
                powerCapacityUrl: powerCapacityUrl,
                supplementUrl:supplementUrl
            }
            $.ajax({
                type: 'post',
                url: '${ctx}/nhPowerStation/updateBWInfo',
                contentType: "application/json;charsetset=UTF-8",
                data: JSON.stringify(order),
                success: function(data){
                    afterSuccess(data);
                },
                complete: function(){
                    $this.prop('disabled', false);
                }
            })
        });

        $('.downloadPro').click(function(){

            var check_accept_imgs ="${entry.checkAcceptImgs}";
            if(!isBlank(check_accept_imgs)){
                // url="technical/imgDownload";
                // window.open('http://192.168.2.24/sfimggroup/'+check_accept_imgs)
                //  var name ="${entry.traderName}-${entry.powerStationCode}-户用电站验收报告.";
                location.href = '${commonStaticImgPath}' + check_accept_imgs;
            }else{
                var hideSubmitForm = document.createElement("form");
                hideSubmitForm.id = "tempForm1";
                hideSubmitForm.method = "post";
                hideSubmitForm.action = "${ctx}/customerEntry/downLoadPDF";
                hideSubmitForm.target = "_blank";
                hideSubmitForm.appendChild(createHideInput("id", "${entry.id}"));
                hideSubmitForm.addEventListener('onsubmit', function(){
                    // this.openDownloadWindow(name);
                });
                document.body.appendChild(hideSubmitForm);
                hideSubmitForm.submit();
                document.body.removeChild(hideSubmitForm);
            }
        })

        function  createHideInput(name, value){
            var hideInput = document.createElement("input");
            hideInput.type = "hidden";
            hideInput.name = name;
            hideInput.value = value;
            return hideInput;
        }


        form.on('select(addressConsistent)', function (data) {
            var addressConsistent = $("#addressConsistent").val();
            if (addressConsistent === 'N') {
                $(".addressDiv").show();
                $("#addressInput").hide();
                $("#addressInputs").show();
            } else {
                $(".addressDiv").hide();
                $("#addressInput").show();
                $("#addressInputs").hide();
            }
        });
        form.on('select(province)', function (data) {
            var province = $(data.elem).find("option:selected").attr("title");
            provinceOrder(province);
        });
        form.on('select(city)', function (data) {
            var city = $(data.elem).find("option:selected").attr("title");
            cityOrder(city);

        });
    })

    function provinceOrder(province) {
        $("#city").empty();
        $("#area").empty();
        if (isBlank(province)) {
            $("#city").append("<option value=''>请选择</option>");
            return "";
        }
        $.ajax({
            type: "POST",
            url: "${ctx}/main/redirect/getCitysByProId",
            data: {
                province: province
            },
            success: function (result) {
                if (result == "205") {
                    layer.msg("暂无数据!")
                    return
                }
                var html = " <option value=''>请选择</option>";
                for (var i = 0; i < result.length; i++) {
                    var city = result[i];
                    html = html + '<option value="' + city.columns.CityName + '" title="' + city.columns.CityID + '">' + city.columns.CityName + '</option>';
                }
                $("#city").append(html);
                form.render('select');
            }
        });

    }

    function cityOrder(city) {
        $("#area").empty()
        if (isBlank(city)) {
            $("#area").append("<option value=''>请选择</option>");
            return "";
        }
        $.ajax({
            type: "POST",
            url: "${ctx}/main/redirect/getAreaByCityId",
            data: {
                city: city
            },
            success: function (result) {
                if (result == "205") {
                    layer.msg("暂无数据!")
                    return
                }
                var html = "<option value=''>请选择</option>";
                for (var i = 0; i < result.length; i++) {
                    var area = result[i];
                    html = html + '<option value="' + area.columns.DistrictName + '" title="' + area.columns.DistrictID + '">' + area.columns.DistrictName + '</option>';
                }
                $("#area").append(html);

                form.render('select');
            }
        });

    }

    window.closeSelf = function() {
        var index = parent.layer.getFrameIndex(window.name);
        // window.parent.location.reload();//刷新父级页面
        parent.layer.close(index);//关闭当前页
    }

    function delImg(that,maxNum){
        $(that).closest('td').find('.add').removeClass("layui-hide");

        $(that).closest('ul').remove();
    }
    function delImg2(that,maxNum){
        $(that).closest('td').find('.add').removeClass("layui-hide");
        $(that).parent().remove();
    }
    function delImg3(that, id) {
        $("#" + id).show();
        $(that).parent().remove();
    }
    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);
        }
    }
    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

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

