<%@ 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="${project.name}"/></td>
        </tr>
        <tr>
            <td colspan="2">代理商</td>
            <td colspan="2"><input type="text" class="form-input" disabled value="${trader.name}"/></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="${entryStatus}"/></td>
                <td colspan="2">备案类型</td>
                <td colspan="2"><input type="text" class="form-input" disabled value="${entryFilingType}"/></td>
            </tr>
            <tr>
                <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" ${opt eq 'merge'? '': 'readonly'}
                                   name="generatorNo" value="${entry.generatorNo}"/></td>
            <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="provinceCode" id="provinceCode" lay-search ${opt eq 'merge'? '': 'disabled'}>
                            <option value="">请选择省</option>
                            <c:choose>
                                <c:when test="${empty entry.provinceCode}">
                                    <c:forEach items="${procodes}" var="code">
                                        <option value="${code.columns.code}"
                                                <c:if test="${entry.province eq code.columns.name}">selected</c:if>
                                        >${code.columns.power_company}</option>
                                    </c:forEach>
                                </c:when>
                                <c:otherwise>
                                    <c:forEach items="${procodes}" var="code">
                                        <option value="${code.columns.code}"
                                                <c:if test="${entry.provinceCode eq code.columns.code}">selected</c:if>
                                        >${code.columns.power_company}</option>
                                    </c:forEach>
                                </c:otherwise>
                            </c:choose>

                        </select>
                    </div>
                </div>
            </td>
        </tr>
        <c:if test="${opt eq 'merge'}">
            <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>
        </c:if>
        <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">
                <%--
                <input type="text" class="form-input" disabled id="addressInput"
                       <c:if test="${entry.addressConsistent eq 'N' && opt eq 'merge'}">style="display: none"</c:if>
                       value="${entry.province}${entry.city}${entry.area}${entry.address}"/>
                --%>
                <c:if test="${opt eq 'merge'}">
                    <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>

                </c:if>
            </td>
        </tr>
        <tr>
            <td colspan="2"><i class="mark">*</i>购售电合同</td>
            <td colspan="6" id="xsdTD">
            <c:if test="${opt eq 'merge'}">
                <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="${entry.contract}"/>
                    <span id="contractFilename">${entry.contractFilename}</span>
                </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}${entry.contract}" style="color: #2890ac;">${entry.contractFilename}</a>
                    </div>

                </c:if>
            </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"></td>
        </tr>
        <tr>
            <td colspan="2" id="yxImgTD">
                <c:if test="${opt eq 'merge'}">
                    <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="${commonStaticImgPaths}${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>
                </c:if>
                <c:if test="${opt ne 'merge'}">
                    <ul class="img">
                        <li class="imgsLi bj-img ">
                            <img src="${commonStaticImgPaths}${report.yxImg}" alt="">
                        </li>
                    </ul>
                </c:if>
            </td>
            <td colspan="2" id="gebImgTD">
                <c:if test="${opt eq 'merge'}">
                    <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="${commonStaticImgPaths}${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>
                </c:if>
                <c:if test="${opt ne 'merge'}">
                    <ul class="img">
                        <li class="imgsLi bj-img ">
                            <c:if test="${not empty report.gebImg}">
                                <img src="${commonStaticImgPaths}${report.gebImg}" alt="">
                            </c:if>
                            <c:if test="${empty report.gebImg}">
                                <i class="blank-img"></i>
                            </c:if>
                        </li>
                    </ul>
                </c:if>
            </td>
            <td></td>
        </tr>
        <tr>
            <td colspan="2">电表照片</td>
            <td colspan="6">
                    <ul class="img">
                        <li class="imgsLi bj-img ">
                            <c:if test="${not empty report.dbImgs}">
                                <img src="${commonStaticImgPaths}${report.dbImgs}" alt="">
                            </c:if>
                            <c:if test="${empty report.dbImgs}">
                                <i class="blank-img"></i>
                            </c:if>
                        </li>
                    </ul>

            </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="insType" id="insType" lay-filter="insType">
                            <option value="1">财产险</option>
                        </select>
                    </div>
                </div>
            </td>
            <td colspan="4"></td>
        </tr>
        <tr>
            <td colspan="2"><i class="mark">*</i>保险公司<input type="hidden" id="insuranceId" name="id" class="hide" value="${insurance.id}" ></td>
            <td colspan="2"><input type="text" class="layui-input" name="insuranceCompany" value="${insurance.insuranceCompany}" ${opt eq 'TwoMergeAccept'? 'readonly': ''}/></td>
            <td colspan="2"><i class="mark">*</i>第一受益人</td>
            <td colspan="2"><input type="text" name="firstBeneficiary" class="layui-input layui-bg-gray" readonly value="广州越秀融资租赁有限公司"></td>
        </tr>
        <tr>
            <td colspan="2"><i class="mark">*</i>保险编号</td>
            <td colspan="2">
                <input type="text" name="insuranceNumber" class="layui-input" value="${insurance.insuranceNumber}"  ${opt eq 'TwoMergeAccept'? 'readonly': ''}>
            </td>
            <td colspan="2"><i class="mark">*</i>投保金额</td>
            <td colspan="2">
                <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}" ${opt eq 'TwoMergeAccept'? 'readonly': ''}>
            </td>
        </tr>
        <tr>
            <td colspan="2"><i class="mark">*</i>保险开始日期</td>
            <td colspan="2">
                <input name="insuranceDateFrom" id="insuranceDateFrom" lay-verify="required"   class="layui-input" ${opt eq 'TwoMergeAccept'? 'disabled': ''} placeholder="年月日" value="${insurance.insuranceDateFrom}">
            </td>
            <td colspan="2"><i class="mark">*</i>保险结束日期</td>
            <td colspan="2">
                <input   name="insuranceDateTo"  id="insuranceDateTo" lay-verify="required"  class="layui-input" ${opt eq 'TwoMergeAccept'? 'disabled': ''} placeholder="年月日" value="${insurance.insuranceDateTo}">
            </td>
        </tr>
        <tr>
            <td colspan="2"><i class="mark">*</i>保险单</td>
            <td colspan="2" id="bxdTD">
                <c:if test="${opt eq 'merge'}">
                    <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;cursor: pointer;">上传</span>
                    <input type="file" id="uploadBxd" style="position: absolute; z-index: 3; opacity: 0; left: 0; width: 44px;"/>
                    <input type="hidden" id="bxdFile" name="bxdFile" value="${insurance.insurancePolicy}"/>
                    <div id="bxdFileName" style="text-overflow: ellipsis;max-width: 130px;white-space: nowrap;overflow: hidden;">${insurance.insurancePolicyName}</div>
                    </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.insurancePolicy}" style="color: #2890ac;">${insurance.insurancePolicyName}</a>
                    </div>

                </c:if>
            </td>
            <td colspan="2"><i class="mark">*</i>并网调试报告</td>
            <td colspan="2">
                <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>
<c:if test="${opt eq 'view'}">
    <div class="operate-footer">
        <button class="layui-btn layui-btn-primary" onclick="closeSelf();">取消</button>
    </div>
</c:if>
<c:if test="${opt eq 'fixAccept'}">
    <!-- 安装验收 -->
    <div class="operate-footer">
        <button class="footer-btn normal-btn TwoAcceptPassBtn">同意</button>
        <button class="footer-btn normal-btn fixAcceptRefuseBtn">驳回</button>
        <button class="footer-btn" onclick="closeSelf();">取消</button>
    </div>
</c:if>
<c:if test="${opt eq 'merge'}">
    <!-- 并网 -->
    <div class="operate-footer">
        <button class="footer-btn normal-btn mergeTmpBtn">暂存</button>
        <button class="footer-btn normal-btn mergeSubmitBtn">提交</button>
        <button class="footer-btn" onclick="closeSelf();">取消</button>
    </div>
</c:if>
<c:if test="${opt eq 'TwoMergeAccept'}">
    <!-- 并网验收审核 -->
    <div class="operate-footer">
        <button class="footer-btn normal-btn TwomergeAcceptPassBtn">同意</button>
        <button class="footer-btn normal-btn TwomergeAcceptRefuseBtn">驳回</button>
        <button class="footer-btn" onclick="closeSelf();">取消</button>
    </div>
</c:if>

<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>
    //图片查看效果
    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','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();

        $('#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(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);
                }
            });
        });

        $('.changeInput').change(function(){
            var spec = $('#componentSpec').val().trim();
            var num = $('#componentNum').val().trim();
            if(!isNaN(spec) && !isNaN(num)){
                $('#capacity').val(spec*num);
            }
        });

        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 updateFileEntry(id) {
            $.ajax({
                type: 'post',
                url: '${ctx}/customerEntry/uploadTwoAttachment',
                data: {
                    id: id,
                    type:'1'
                },
                success: function(data){
                    console.log(data)
                }
            });
        }

        function afterSuccess(data) {
            console.log(data)
            if (data.code === '200') {
                parent.layer.msg('操作成功', {icon: 1});
                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});
            }
        }

        function uploadAttachment(id) {
            $.ajax({
                type: 'post',
                url: '${ctx}/customerEntry/createEntryPdf',
                data: {
                    id: id
                },
                success: function(data){
                    console.log(data)
                }
            });
        }

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

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

        //安装验收通过
        $('.fixAcceptPassBtn').click(function(){
            var $this = $(this);
            //安装验收意见
            var fixRemark = $('textarea[name="fixConclusionSh"]').val();

            // if (isBlank(fixRemark)) {
            //     layer.msg('请填写备注');
            //     return;
            // }
            $this.prop('disabled', true);
            $.ajax({
                type: 'post',
                url: '${ctx}/customerEntry/fixAcceptPass',
                data: {
                    id: '${entry.id}',
                    fixConclusion: fixRemark
                },
                success: function(data){
                    afterSuccess(data);
                },
                complete: function(){
                    $this.prop('disabled', false);
                }
            })
        });
        //安装验收退回
        $('.fixAcceptRefuseBtn').click(function(){
            var $this = $(this);
            //安装验收意见
            var fixRemark = $('textarea[name="fixConclusionSh"]').val();
            if (isBlank(fixRemark)) {
                layer.msg('请填写备注');
                return;
            }
            $this.prop('disabled', true);
            $.ajax({
                type: 'post',
                url: '${ctx}/customerEntry/fixAcceptRefuse',
                data: {
                    id: '${entry.id}',
                    fixConclusion: fixRemark
                },
                success: function(data){
                    afterSuccess(data);
                },
                complete: function(){
                    $this.prop('disabled', false);
                }
            })
        });

        //安装验收通过
        $('.TwoAcceptPassBtn').click(function(){
            var index= layer.load(2, {shade: [0.5,'#fff'], content:''});
            var $this = $(this);
            //二次安装验收意见
            var fixRemark = $('textarea[name="fixConclusionSh"]').val();
            // if (isBlank(fixRemark)) {
            //     layer.msg('请填写备注');
            //     return;
            // }

            $this.prop('disabled', true);
            $.ajax({
                type: 'post',
                url: '${ctx}/customerEntry/toNetAcceptPass',
                data: {
                    id: '${entry.id}',
                    type:'1',
                    fixConclusionSh: fixRemark
                },
                success: function(data){
                    afterSuccess(data);
                },
                complete: function(){
                    layer.close(index);
                    $this.prop('disabled', false);
                }
            })
        });
        //二次安装验收退回
        $('.TwoAcceptRefuseBtn').click(function(){
            var $this = $(this);
            //安装验收意见
            var fixRemark = $('textarea[name="fixConclusionSh"]').val();
            if (isBlank(fixRemark)) {
                layer.msg('请填写备注');
                return;
            }
            $this.prop('disabled', true);
            $.ajax({
                type: 'post',
                url: '${ctx}/customerEntry/toNetAcceptPass',
                data: {
                    id: '${entry.id}',
                    type:'2',
                    fixConclusionSh: fixRemark
                },
                success: function(data){
                    afterSuccess(data);
                },
                complete: function(){
                    $this.prop('disabled', false);
                }
            })
        });

        function getInsurance() {
            return {
                id: $("#insuranceId").val(),
                entryId: '${entry.id}',
                insuranceType: "1",//只支持财产险
                insuranceDateFrom: $("input[name='insuranceDateFrom']").val(),
                insuranceDateTo: $("input[name='insuranceDateTo']").val(),
                insuranceCompany: $("input[name='insuranceCompany']").val(),
                insuranceNumber: $("input[name='insuranceNumber']").val(),
                insuranceAmount: $("input[name='insuranceAmount']").val(),
                firstBeneficiary: $("input[name='firstBeneficiary']").val(),
                insurancePolicy: $("input[name='bxdFile']").val(),
                bwtsFile: $("input[name='bwtsFile']").val(),
                bwtsFilename: $("#bwtsFileName").text(),
                insurancePolicyName: $("#bxdFileName").text()
            };
        }

        //并网暂存
        $('.mergeTmpBtn').click(function(){
            var $this = $(this);
            //发电户号
            var generatorNo = $('input[name="generatorNo"]').val();
            var provinceCode = $("#provinceCode").val()
            var addressConsistent = $("#addressConsistent").val();//购售电地址是否一致
            var province = $("#province").val();
            var city = $("#city").val();
            var area = $("#area").val();
            var address = $("#address").val();

            //近3天发电量
            var yxImg = getImgs($('#yxImgTD'));
            //划转截图
            var gebImg = getImgs($('#gebImgTD'));
            $this.prop('disabled', true);
            let application = {
              entryId: '${entry.id}',
                resultType:0,
                insurance: getInsurance()
            };
            var order = {
                entryId: '${entry.id}',
                generatorNo: generatorNo,
                yxImg: yxImg,
                gebImg: gebImg,
                addressConsistent: addressConsistent,
                province: province,
                city: city,
                area: area,
                address: address,
                provinceCode:provinceCode,
                contractFile: $("#contractFile").val(),
                contractFilename: $("#contractFilename").text(),
                application: application
            }
            $.ajax({
                type: 'post',
                url: '${ctx}/customerEntry/mergeTmp',
                contentType: "application/json;charsetset=UTF-8",
                data: JSON.stringify(order),
                success: function(data){
                    afterSuccess(data);
                },
                complete: function(){
                    $this.prop('disabled', false);
                }
            })
        });
        //并网提交
        $('.mergeSubmitBtn').click(function(){
            var $this = $(this);
            //发电户号
            var generatorNo = $('input[name="generatorNo"]').val();
            var provinceCode = $("#provinceCode").val()
            var addressConsistent = $("#addressConsistent").val();//购售电地址是否一致
            if (isBlank(addressConsistent)) {
                layer.msg("请选择购售电地址是否一致");
                return;
            }
            var province = $("#province").val();
            var city = $("#city").val();
            var area = $("#area").val();
            var address = $("#address").val();
            if (addressConsistent === 'N') {
                if (isBlank(province) || isBlank(city) || isBlank(area) || isBlank(address)) {
                    layer.msg("购售电地址不能为空");
                    return;
                }
            }

            //近3天发电量
            var yxImg = getImgs($('#yxImgTD'));
            //划转截图
            var gebImg = getImgs($('#gebImgTD'));


            if (isBlank(generatorNo)) {
                layer.msg('发电户号不能为空');
                return;
            }
            if (isBlank(provinceCode)) {
                layer.msg('请选择所属电力公司');
                return;
            }
            if (isBlank(yxImg)) {
                layer.msg('近3天发电量不能为空');
                return;
            }
            let application = {
                entryId: '${entry.id}',
                resultType: 1,
                insurance: getInsurance()
            };
            let insurance = application.insurance;
            if (isBlank(insurance.insuranceCompany)) {
                layer.msg('保险公司不能为空');
                return;
            }
            if (isBlank(insurance.insuranceNumber)) {
                layer.msg('保险编号不能为空');
                return;
            }
            if (isBlank(insurance.insuranceAmount)) {
                layer.msg('投保金额不能为空');
                return;
            }
            if (isBlank(insurance.insuranceDateFrom)) {
                layer.msg('保险开始日期不能为空');
                return;
            }
            if (isBlank(insurance.insuranceDateTo)) {
                layer.msg('保险结束日期不能为空');
                return;
            }
            if (isBlank(insurance.insurancePolicy)) {
                layer.msg('保险单不能为空');
                return;
            }
            if (isBlank(insurance.bwtsFile)) {
                layer.msg('并网调试报告不能为空');
                return;
            }

            $this.prop('disabled', true);
            var order = {
                entryId: '${entry.id}',
                generatorNo: generatorNo,
                yxImg: yxImg,
                gebImg: gebImg,
                addressConsistent: addressConsistent,
                province: province,
                city: city,
                area: area,
                address: address,
                provinceCode:provinceCode,
                contractFile: $("#contractFile").val(),
                contractFilename: $("#contractFilename").text(),
                application: application
            }
            $.ajax({
                type: 'post',
                url: '${ctx}/customerEntry/mergeSubmit',
                contentType: "application/json;charsetset=UTF-8",
                data: JSON.stringify(order),
                success: function(data){
                    afterSuccess(data);
                },
                complete: function(){
                    $this.prop('disabled', false);
                }
            })
        });
        //并网验收退回
        $('.mergeAcceptRefuseBtn').click(function(){
            var $this = $(this);
            var mergeConclusion = $('textarea[name="fixConclusionSh"]').val();
            if (isBlank(mergeConclusion)) {
                layer.msg('请填写备注');
                return;
            }
            $this.prop('disabled', true);
            $.ajax({
                type: 'post',
                url: '${ctx}/customerEntry/mergeAcceptRefuse',
                data: {
                    id: '${entry.id}',
                    mergeConclusion: mergeConclusion
                },
                success: function(data){
                    afterSuccess(data);
                },
                complete: function(){
                    $this.prop('disabled', false);
                }
            });
        });

        //并网验收通过
        $('.mergeAcceptPassBtn').click(function(){
            var $this = $(this);
            var fixConclusionSh = $('textarea[name="fixConclusionSh"]').val();
            // if (isBlank(fixConclusionSh)) {
            //     layer.msg('请填写备注');
            //     return;
            // }
            $this.prop('disabled', true);
            $.ajax({
                type: 'post',
                url: '${ctx}/customerEntry/mergeAcceptPass',
                data: {
                    id: '${entry.id}',
                    mergeConclusion: fixConclusionSh
                },
                success: function(data){
                    afterSuccess(data);
                },
                complete: function(){
                    $this.prop('disabled', false);
                }
            });
        });

        //并网验收审核退回
        $('.TwomergeAcceptRefuseBtn').click(function(){
            var $this = $(this);

            var fixConclusionSh = $('textarea[name="fixConclusionSh"]').val();
            if (isBlank(fixConclusionSh)) {
                layer.msg('请填写备注');
                return;
            }
            $this.prop('disabled', true);
            $.ajax({
                type: 'post',
                url: '${ctx}/customerEntry/twoMergeAcceptRefuse',
                data: {
                    id: '${entry.id}',
                    type:'2',
                    finalConclusion: fixConclusionSh
                },
                success: function(data){
                    afterSuccess(data);
                },
                complete: function(){
                    $this.prop('disabled', false);
                }
            });
        });

        //并网验收审核通过
        $('.TwomergeAcceptPassBtn').click(function(){
            var $this = $(this);

            var finalConclusion = $('textarea[name="fixConclusionSh"]').val();
            // if (isBlank(finalConclusion)) {
            //     layer.msg('请填写备注');
            //     return;
            // }
            var index= layer.load(2, {shade: [0.5,'#fff'], content:''});

            $this.prop('disabled', true);
            $.ajax({
                type: 'post',
                url: '${ctx}/customerEntry/twoMergeAcceptRefuse',
                data: {
                    id: '${entry.id}',
                    type: '1',
                    finalConclusion: finalConclusion
                },
                success: function(data){
                    afterSuccess(data);
                },
                complete: function(){
                    $this.prop('disabled', false);
                    layer.close(index);
                }
            });
        });

        $('.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 isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

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

