<%@ 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/dist/viewer.css" media="all">
    <style>
        html {
            background-color: #fff;
            padding-bottom: 50px;
        }
        .form-span {
            display: block;
            padding: 8px 0;
            margin-left: 110px;
        }

        .page-iframe {
            border: none;
            width: 100%;
            min-height: calc(100vh - 250px);
        }
        .mb-10{
            margin-bottom: 10px !important;
        }
        .pd-10{
            padding: 10px;
        }
        .idea-text{
            width: 320px; height: 100px;outline: none; padding: 3px
        }
        .msg-title{
            text-align: center;
            margin: 10px 0;
            font-size: 16px;
        }
        .title1 {
            border-left: 4px solid #1b6073;
            padding-left: 20px;
            font-size: 14px;
            margin: 10px auto;
            font-weight: 600;
            height: 34px;
            line-height: 34px;
            background-color: #f4f6f9;
            color: #666666;
        }
        .download-link {
            display: inline-block;
            padding: 8px 16px;
            color: #007bff;
            text-decoration: none;
            border-radius: 4px;
        }

        .download-link:hover {
            color: #0056b3;
        }
        .layui-input-block {
            margin-left: 110px;
        }

        .layui-form-label {
            width: 110px;
        }
        .clearfix{*zoom:1;}
        .clearfix:before,.clearfix:after{display:table; line-height:0; content:"";}
        .clearfix:after{clear:both;}

        .layui-tab-title{
            margin: 0 0 0 20px;
        }
        .layui-tab-content{
            margin: 0 0 0 20px;
        }
        .bj-img {
            margin-right: 5px;
        }
        .blank-img {
            background: url('${ctxPlugin}/static/imgs/blankImg.png') center center no-repeat;
            width: 80px;
            height: 80px;
            display: inline-block;
        }
        .link-blue{ color: #1b6073; cursor: pointer;}
        .two-col {
            display: flex;
        }
        .two-col .scheme-item,.component-item {
            padding-right: 20px;
            flex-grow: 1;
            flex-shrink: 1;
            flex-basis: 0;
        }
        .two-col .design-item {
            flex-grow: 1;
            flex-shrink: 1;
            padding-right: 20px;
            flex-basis: 0;
        }
        div.sep {
            border-bottom: 1px dashed #ccc;
            padding-top: 10px;
            clear: both;
            margin-bottom: 10px;
        }
        .two-col .design-doc {
            flex-grow: 1;
            flex-shrink: 1;
            padding-right: 20px;
            flex-basis: 0;
        }
        .design-item-title {
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
<div class="layui-fluid pd-10">
    <div class="order-win layui-form">
        <button class="layui-btn" style="margin-left: 94.5%;" onclick="approvalRecord()">审批记录</button>
        <div class="layui-card-body pt-20 pb-40">
            <div class="layui-col-xs12 form-box">
                <div class="layui-inline layui-col-xs3">
                    <label class="layui-form-label w-130">电站编码：</label>
                    <div class="layui-input-block ">
                        <input type="text" style="float: left;" autocomplete="off"  name="stationCode" lay-verify="stationCode" class="layui-input" value="" disabled>
                        <input type="text" style="width: 78%;float: left;"  id="stationId" lay-verify="stationCode" class="layui-input hide" value="">
                    </div>
                </div>
                <div class="layui-inline layui-col-xs3">
                    <label class="layui-form-label w-130">电站状态：</label>
                    <div class="layui-input-block ">
                        <input type="text"  name="status" class="layui-input" value="" disabled>
                    </div>
                </div>
                <div class="layui-inline layui-col-xs3">
                    <label class="layui-form-label w-130">代理商：</label>
                    <div class="layui-input-block ">
                        <input type="text" name="traderName" class="layui-input" value="" disabled>
                    </div>
                </div>
                <div class="layui-inline layui-col-xs3">
                    <label class="layui-form-label w-130">产品名称：</label>
                    <div class="layui-input-block ">
                        <input type="text" name="projectName"  class="layui-input" value="" disabled>
                    </div>
                </div>
                <div class="layui-inline layui-col-xs3">
                    <label class="layui-form-label w-130">项目公司：</label>
                    <div class="layui-input-block ">
                        <input type="text" name="projectCompanyName" class="layui-input" value="" disabled>
                    </div>
                </div>
                <div class="layui-inline layui-col-xs3">
                    <label class="layui-form-label w-130">所属资方：</label>
                    <div class="layui-input-block ">
                        <input type="text" name="partnerName" class="layui-input" value="" disabled>
                    </div>
                </div>
                <div class="layui-inline layui-col-xs3">
                    <label class="layui-form-label w-130">业主姓名：</label>
                    <div class="layui-input-block ">
                        <input type="text" name="tenantName"  class="layui-input" value="" disabled>
                    </div>
                </div>
                <div class="layui-inline layui-col-xs3">
                    <label class="layui-form-label w-130">身份证号：</label>
                    <div class="layui-input-block ">
                        <input type="text" name="idCode" class="layui-input" value="" disabled>
                    </div>
                </div>
                <div class="layui-inline layui-col-xs9">
                    <label class="layui-form-label w-130">安装地址：</label>
                    <div class="layui-input-block ">
                        <input type="text" name="address" class="layui-input" value="" disabled>
                    </div>
                </div>
                <div class="layui-col-lg3 layui-col-sm3" style="clear:both;">
                    <label class="layui-form-label w-130">变更类型：</label>
                    <div class="layui-input-block ">
                        <input type="text" name="idCode" class="layui-input" value="设计信息" disabled>
                    </div>
                </div>
                <div class="layui-col-lg3 layui-col-sm3">
                    <label class="layui-form-label w-130">变更单号：</label>
                    <div class="layui-input-block ">
                        <input type="text" name="number" class="layui-input" value="" disabled>
                    </div>
                </div>
                <div class="layui-col-lg3 layui-col-sm3">
                    <label class="layui-form-label w-130">变更申请人：</label>
                    <div class="layui-input-block ">
                        <input type="text" name="creator" class="layui-input" value="" disabled>
                    </div>
                </div>
                <div class="layui-col-lg3 layui-col-sm3">
                    <label class="layui-form-label w-130">申请时间：</label>
                    <div class="layui-input-block ">
                        <input type="text" name="creatTime" class="layui-input" value="" disabled>
                    </div>
                </div>
                <div class="layui-inline layui-col-xs12">
                    <label class="layui-form-label w-130">变更原因：</label>
                    <div class="layui-input-block ">
                        <textarea name="reason" id="reason" disabled placeholder="" class="layui-textarea"></textarea>
<%--                        <input type="text" name="reason" id="reason" class="layui-input" value="" disabled>--%>
                    </div>
                </div>
            </div>
        </div>
        <div class="clear-both">
            <p class="layui-elem-quote" style="margin: 0px 0px 0px 10px">设计方案信息</p>
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief" id="LAY_app">

                <div class="layui-tab-content two-col" style="padding: 0">
                    <div class="scheme-item">
                        <div>变更前方案：</div>
                        <table class="layui-table">
                            <thead>
                            <th>方案类型</th>
                            <th>方案名称</th>
                            </thead>
                            <tbody id="contentBody">
                            <tr>
                                <td id="schemeTypeName"></td>
                                <td id="schemeName"></td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="scheme-item">
                        <div>变更后方案：</div>
                        <table class="layui-table">
                            <thead>
                            <th>方案类型</th>
                            <th>方案名称</th>
                            </thead>
                            <tbody id="contentBody2">
                            <tr>
                                <td id="postSchemeTypeName"></td>
                                <td id="postSchemeName"></td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>

                <div class="sep"></div>

                <div class="layui-tab-content  two-col" style="padding: 0">
                    <div class="component-item">
                        <div>变更前物料：</div>
                        <table class="layui-table" id="preComponentTable">
                            <thead>
                            <th>序号</th>
                            <th>物料类型</th>
                            <th>物料规格</th>
                            <th>数量</th>
                            </thead>
                            <tbody id="preComponentTableContent">
                            </tbody>
                        </table>
                        <div>变更前设计安装容量：<span id="preDesignCapacity">-</span>kW</div>
                    </div>
                    <div class="component-item">
                        <div>变更后物料：</div>
                        <table class="layui-table">
                            <thead>
                            <th>序号</th>
                            <th>物料类型</th>
                            <th>物料规格</th>
                            <th>数量</th>
                            </thead>
                            <tbody id="postComponentTableContent">
                            </tbody>
                        </table>
                        <div>变更后设计安装容量：<span id="postDesignCapacity">-</span>kW</div>
                    </div>
                </div>

                <div class="sep"></div>

                <div class="layui-tab-content two-col" style="padding: 0;margin-top: 5px;">
                    <div class="design-doc">
                        <div class=" design_drawings hide">
                            变更前<i class="design_drawings_name">设计图纸：</i>
                            <div id="preDocs">

                            </div>
                        </div>
                        <div class="zjpb_img hide">
                            变更前<i class="zjpb_img_name">组件排布图：</i>
                            <div id="zjpb_img_pre">

                            </div>
                        </div>
                        <div  class="zjzx_img hide">
                            变更前<i class="zjzx_img_name">组件接线图：</i>
                            <div id="zjzx_img_pre">

                            </div>
                        </div>
                        <div  class="zjcs_img hide">
                            变更前<i class="zjcs_img_name">组件支架图：</i>
                            <div id="zjcs_img_pre">

                            </div>
                        </div>
                        <div  class="zjhs_img hide">
                            变更前<i class="zjhs_img_name">一次接线图/电气图：</i>
                            <div id="zjhs_img_pre">

                            </div>
                        </div>
                    </div>
                    <div class="design-doc">
                        <div class="design_drawings hide" >
                            变更后<i class="design_drawings_name">设计图纸：</i>
                            <div id="postDocs">

                            </div>
                        </div>

                        <div class="zjpb_img hide">
                            变更后<i class="zjpb_img_name">组件排布图：</i>
                            <div id="zjpb_img_post">

                            </div>
                        </div>
                        <div  class=" zjzx_img hide">
                            变更后<i class="zjzx_img_name">组件接线图：</i>
                            <div id="zjzx_img_post">

                            </div>
                        </div>
                        <div  class=" zjcs_img hide">
                            变更后<i class="zjcs_img_name">组件支架图：</i>
                            <div id="zjcs_img_post">

                            </div>
                        </div>
                        <div  class=" zjhs_img hide">
                            变更后<i class="zjhs_img_name">一次接线图/电气图：</i>
                            <div id="zjhs_img_post">

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-inline layui-col-xs12">
            <label class="layui-form-label w-130">审核备注：</label>
            <div class="layui-input-block ">
                <input type="text" name="auditRemarks" class="layui-input" value="${design.auditRemark}" autocomplete="off" <c:if test="${fromAudit eq '2'}">disabled</c:if>>
            </div>
        </div>
    </div>
</div>

<c:choose>
    <c:when test="${(fns:checkPagePermission(request, 'DZBG_SJBG_DSH_AUDIT_B') eq '0') && fromAudit eq '1'}">
        <div class="layui-form-item text-c operate-footer">
            <button type="button" class="layui-btn" onclick="temp();">暂存</button>
            <button type="button" class="layui-btn" onclick="pass();">审核通过</button>
            <button type="button" class="layui-btn" onclick="reject();">审核驳回</button>
            <button class="layui-btn layui-btn-primary" onclick="closeSelf()">取消</button>
        </div>
    </c:when>
    <c:otherwise>
        <div class="layui-form-item text-c operate-footer">
            <button class="layui-btn layui-btn-primary" onclick="closeSelf()">关闭</button>
        </div>
    </c:otherwise>
</c:choose>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.js"></script>
<script src="${ctxPlugin}/lib/base64.js"></script>
<script>
    //图片查看效果
    let form = null;
    let entry = null;
    let formSet = null;
    let info2 = null;
    let preComponents = [];
    var viewer = new Viewer(document.getElementById('LAY_app'));
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'jquery', 'layer','upload','form'], function () {
        $ = layui.$;
        layer = layui.layer;
        upload = layui.upload;
        form = layui.form;

        upload.render({
            elem: '#dzImgsUploader',
            url: '${ctx}/common/uploadFile',
            before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                });
            },
            done: function (res) {
                //上传完毕回调
                addImg(res.path,"dzImgs", 4);
            },
            error: function () {
                //请求异常回调
            }
        });

        upload.render({
            elem: '#uploadDzDocPost' //绑定元素
            , accept: 'file'
            , url: '${ctx}/common/uploadFileKeepName' //上传接口
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                });
            }
            , done: function (res, index, upload) {
                $("#inputDzDocPost").val(res.path);
                $("#linkDzDocPost").text(res.filename).attr("href", "${commonStaticImgPath}"+res.path).data('filename', res.filename);
            }
            , error: function () {
                //请求异常回调
            }
        });

        form.on('select(planType)', function (data) {
            var value = $(data.elem).find("option:selected").val();
            if (isBlank(value)) {
                return
            }
            var that_ = $(this);
            //获取当前类型下的方案名称
            $.ajax({
                url: "${ctx}/planManage/findPlanByAssembly",
                type: "POST",
                data: {
                    planType: value
                },
                success: function (result) {
                    let planNameSelect = $(".planName");
                    planNameSelect.empty();
                    var length = result.length;
                    var planNameHtml = "<option value=''>请选择</option>";
                    for (var i = 0; i < length; i++) {
                        planNameHtml += "<option value='" + result[i].columns.id+"'>" + result[i].columns.name + "</option>";
                    }
                    planNameSelect.append(planNameHtml);
                    form.render('select');
                }
            });
        });

        form.on('select(spec)', function (data) {
            const num = $(this).closest('tr').find('td').eq(3).find('input').val();
            var value = $(data.elem).find("option:selected").text();
            const capacity = parseInt(value) * parseInt(num);
            $('#postDesignCapacity').text(isNaN(capacity) ? "-" : capacity);
        });

        searchCode();
    });

    function postDesignDocTempl(index,path) {
        return "<div style=\"margin-top: 5px\">\n" +
            "    <span class=\"layui-icon-close layui-icon\" onclick=\"delDoc(this)\"></span>\n" +
            "    <a href=\"\" class=\"download-link\"></a>\n" +
            "    <a   target=\"_blank\"  onclick=\"previewUrl('${commonStaticImgPath}"+path+"')\" style=\"cursor: pointer\" class=\"download-link\">查看</a>\n" +
            "    <input type=\"hidden\" class=\""+index+"\">\n" +

            "</div>";
    }

    function setPostDesignDocs(design) {
        if(!isBlank(design.designDrawings)){
            $("#postDocs").empty();
            let designDrawings = design.designDrawings;
            let drawings = designDrawings.split(",");
            for(var i=0;i<drawings.length;i++) {
                appendSingleDoc(drawings[i],'postDocs');
            }
        }
        if(!isBlank(design.zjpbImg)){
            $("#zjpb_img_post").empty();
            let zjpbImgs = design.zjpbImg;
            let zjpbImg = zjpbImgs.split(",");
            for(var i=0;i<zjpbImg.length;i++) {
                appendSingleDoc(zjpbImg[i],'zjpb_img_post');
            }
        }
        if(!isBlank(design.zjzxImg)){
            $("#zjzx_img_post").empty();
            let zjzxImgs = design.zjzxImg;
            let zjzxImg = zjzxImgs.split(",");
            for(var i=0;i<zjzxImg.length;i++) {
                appendSingleDoc(zjzxImg[i],'zjzx_img_post');
            }
        }
        if(!isBlank(design.zjcsImg)){
            $("#zjcs_img_post").empty();
            let zjcsImgs = design.zjcsImg;
            let zjcsImg = zjcsImgs.split(",");
            for(var i=0;i<zjcsImg.length;i++) {
                appendSingleDoc(zjcsImg[i],'zjcs_img_post');
            }
        }
        if(!isBlank( design.zjhsImg)){
            $("#zjhs_img_post").empty();
            let zjhsImgs = design.zjhsImg;
            let zjhsImg = zjhsImgs.split(",");
            for(var i=0;i<zjhsImg.length;i++) {
                appendSingleDoc(zjhsImg[i],'zjhs_img_post');
            }
        }
    }
    function setPreDesignDocs(design) {
        if(!isBlank(design.preDesignDrawings)){
            $("#preDocs").empty();
            let designDrawings = design.preDesignDrawings;
            let drawings = designDrawings.split(",");
            for(var i=0;i<drawings.length;i++) {
                let s = $(preDesignDocTempl(drawings[i]));
                let file = s.find('a').eq(0);
                file.attr('href', '${commonStaticImgPath}'+drawings[i]);
                file.attr('download', drawings[i]);
                file.text(filename(drawings[i]));
                $("#preDocs").append(s);
            }
        }
        if(!isBlank(design.preZjpbImg)){
            $("#zjpb_img_pre").empty();
            let zjpbImgs = design.preZjpbImg;
            let zjpbImg = zjpbImgs.split(",");
            for(var i=0;i<zjpbImg.length;i++) {
                let s = $(preDesignDocTempl(zjpbImg[i]));
                let file = s.find('a').eq(0);
                file.attr('href', '${commonStaticImgPath}'+zjpbImg[i]);
                file.attr('download', zjpbImg[i]);
                file.text(filename(zjpbImg[i]));
                $("#zjpb_img_pre").append(s);
            }
        }
        if(!isBlank(design.preZjzxImg)){
            $("#zjzx_img_pre").empty();
            let zjzxImgs = design.preZjzxImg;
            let zjzxImg = zjzxImgs.split(",");
            for(var i=0;i<zjzxImg.length;i++) {
                let s = $(preDesignDocTempl(zjzxImg[i]));
                let file = s.find('a').eq(0);
                file.attr('href', '${commonStaticImgPath}'+zjzxImg[i]);
                file.attr('download', zjzxImg[i]);
                file.text(filename(zjzxImg[i]));
                $("#zjzx_img_pre").append(s);
            }
        }
        if(!isBlank(design.preZjcsImg)){
            $("#zjcs_img_pre").empty();
            let zjcsImgs = design.preZjcsImg;
            let zjcsImg = zjcsImgs.split(",");
            for(var i=0;i<zjcsImg.length;i++) {
                let s = $(preDesignDocTempl(zjcsImg[i]));
                let file = s.find('a').eq(0);
                file.attr('href', '${commonStaticImgPath}'+zjcsImg[i]);
                file.attr('download', zjcsImg[i]);
                file.text(filename(zjcsImg[i]));
                $("#zjcs_img_pre").append(s);
            }
        }
        if(!isBlank( design.preZjhsImg)){
            $("#zjhs_img_pre").empty();
            let zjhsImgs = design.preZjhsImg;
            let zjhsImg = zjhsImgs.split(",");
            for(var i=0;i<zjhsImg.length;i++) {
                let s = $(preDesignDocTempl(zjhsImg[i]));
                let file = s.find('a').eq(0);
                file.attr('href', '${commonStaticImgPath}'+zjhsImg[i]);
                file.attr('download', zjhsImg[i]);
                file.text(filename(zjhsImg[i]));
                $("#zjhs_img_pre").append(s);
            }
        }
    }

    function appendSingleDoc(path, index) {
        let s = $(postDesignDocTempl(index,path));
        let file = s.find('a').eq(0);
        file.attr('href', '${commonStaticImgPath}'+path);
        file.attr('download', path);
        file.text(filename(path));
        $("#"+index).append(s);
        s.find('input').val(path);
    }

    function filename(filePath) {
        if (!filePath) {
            return '';
        }
        let index = filePath.lastIndexOf("/");
        if (index !== -1) {
            return filePath.substring(index+1);
        }
        return filePath;
    }

    function preDesignDocTempl(path) {
        return "<div style=\"margin-top: 5px\">\n" +
            "    <a href=\"\" class=\"download-link\"></a>\n" +
            "    <a   target=\"_blank\"  onclick=\"previewUrl('${commonStaticImgPath}"+path+"')\" style=\"cursor: pointer\" class=\"download-link\">查看</a>\n" +
            "</div>";
    }

    function addRow(r) {
        let target = $(r).closest('tr');
        const nextRow = target.clone();

        function _resetRow(nextRow) {
            let tds = nextRow.find('td');
            tds.eq(2).find('select').val('');
            tds.eq(3).find('input').val('');
            tds.eq(4).find('i.layui-icon-delete').removeClass('layui-hide');
        }
        _resetRow(nextRow);
        nextRow.insertAfter(target);
        initRowNums($('#postComponentTableContent'));
        invalidate('select');
    }

    function deleteRow(r) {
        let target = $(r).closest('tr');
        target.remove();
        initRowNums($('#postComponentTableContent'));
    }

    function invalidate(target) {
        setTimeout(function() {
            form.render(target);
        }, 0);
    }

    function initRowNums(table) {
        let trs = table.find('tr');
        trs.each(function(index, el) {
            $("td:first", $(this)).text(index+1);
        });
    }

    function compChange(t) {
        let target = $(t);
        const num = target.val();
        var value = target.closest('tr').find("option:selected").data("power");
        const capacity = parseInt(value) * parseInt(num);
        $('#postDesignCapacity').text(isNaN(capacity) ? "-" : capacity);
    }

    function searchCode(){
        // var stationCode = $("input[name='stationCode']").val();
        // if (isBlank(stationCode)) {
        //     return;
        // }
        $.ajax({
            type: 'post',
            url: '${ctx}/entryChanges/designInfo/designChangeDetail/${id}',
            dataType: 'json',
            success: function(res) {
                if (res.code === "200") {
                    var customerEntry = res.data.customerEntry;
                    entry = customerEntry;
                    formSet = res.data.formSet;
                    info2 = res.data.info2;
                    partnerId = res.data.customerEntry.partnerId;
                    var project = res.data.project;
                    let design = res.data.design;
                    $("#stationId").val(customerEntry.id);
                    $("input[name='status']").val(getStatus(customerEntry));
                    $("input[name='traderName']").val(customerEntry.createTraderName);
                    $("input[name='projectName']").val(project.name);
                    $("input[name='projectCompanyName']").val(customerEntry.projectCompanyName);
                    $("input[name='partnerName']").val(customerEntry.partnerName);
                    $("input[name='tenantName']").val(customerEntry.tenantName);
                    $("input[name='idCode']").val(customerEntry.idCode);
                    $("input[name='address']").val(customerEntry.province + customerEntry.city + customerEntry.area + customerEntry.address);
                    $("input[name='number']").val(design.number);
                    $("input[name='creator']").val(design.creator);
                    $("input[name='creatTime']").val(design.createTime);
                    // 方案
                    $("#schemeTypeName").text(design.preSchemeTypeName);
                    $("#schemeName").text(design.preSchemeName);
                    $("#postSchemeTypeName").text(design.schemeTypeName);
                    $("#postSchemeName").text(design.schemeName);
                    $("#reason").val(design.reason);
                    $("input[name=stationCode]").val(customerEntry.powerStationCode);
                    $("input[name=auditRemarks]").val(design.auditRemark);
                    // $("#schemeTypeName").data('schemeTypeId', customerEntry.schemeTypeId);
                    // $("#schemeTypeName").data('schemeType', customerEntry.schemeType);
                    // $("#schemeName").data('schemeId', customerEntry.schemeId);
                    // 方案下拉列表
                    // fillPlanTypeSelect(res.data.insta, form);
                    // 物料 pre
                    let tableBody = $("#preComponentTableContent");
                    let postTableBody = $("#postComponentTableContent");
                    setComponentInfo(res.data.assemblyList, res.data.inverterList, res.data.gridConnectionList, res.data.gridSupportList, tableBody);
                    setComponentInfo(res.data.postAssemblyList, res.data.postInverterList, res.data.postGridConnectionList, res.data.postGridSupportList, postTableBody);
                    // 物料 post
                    $('#preDesignCapacity').text((res.data.preCapacity/1000).toFixed(3));
                    $('#postDesignCapacity').text((res.data.postCapacity/1000).toFixed(3));
                    // 设置设计文档和设计图纸
                    setPreDesignDocs(design)
                    setPostDesignDocs(design)
                    hideOrShowHtml(formSet,customerEntry.partnerId);
                } else {
                    clearHtml();
                    layer.msg(res.errMsg);
                }
            }
        });
    }
    function hideOrShowHtml(setData,partnerId) {
        for (var i = 0; i < setData.length; i++) {
            let columnKey = setData[i].columnKey;
            console.log(columnKey);
            if (setData[i].useFlag == '0') {//不启用
                $("." + columnKey).addClass("hide");
            } else {
                if (columnKey.includes(partnerId)) {
                    columnKey = columnKey.substring(0, columnKey.indexOf(partnerId)-1);
                }
                console.log(columnKey);
                $("." + columnKey).removeClass("hide");
                $("." + columnKey+'_name').text(setData[i].columnName);
            }
        }
        resetSort();
    }

    function addImg(data, classimg, count) {
        let icons = $('#postDzImgsDiv').find('.imgSpan').size();
        const uploader = $('#dzImgsUploader');
        if(icons+1>=count){
            uploader.hide();
        }
        var html = '<div class="bj-img imgSpan"><span class="layui-icon-close layui-icon" onclick="deleteIcon(this)"></span>';
        html += '<img src="${commonStaticImgPath}' + data + '" height="700" width="1200"/>';
        html += '<input type="hidden" class="' + classimg + '" value="' + data + '"/> </div>';
        $(html).insertBefore(uploader);
        //图片查看效果
        viewer.update();
    }

    function setDzImgs(data, imgContainer) {
        const imgItem = "<div class=\"bj-img imgSpan\">\n" +
            "    <img src=\"\" height=\"700\" width=\"1200\"/>\n" +
            "    <input type=\"hidden\" name=\"preDzImgs\" class=\"dzImgs\" value=\"\">\n" +
            "</div>";
        const imgs = data.split(',');
        imgContainer.empty();
        for (var i=0;i<imgs.length;i++) {
            const imgItemEl = $(imgItem);
            imgItemEl.find('img').attr('src', "${commonStaticImgPath}"+imgs[i]);
            imgItemEl.find('input').val(imgs[i]);
            imgContainer.append(imgItemEl);
        }
    }

    function deleteIcon(r) {
        const uploader = $('#dzImgsUploader');
        $(r).closest('.imgSpan').remove();
        let icons = $('#postDzImgsDiv').find('.imgSpan').size();
        if (icons >= 4) {
            uploader.hide();
        } else {
            uploader.show();
        }
    }

    function setDzImgsPost(data) {
        const imgItem = "<div class=\"bj-img imgSpan\">\n" +
            "    <span class=\"layui-icon-close layui-icon\" onclick=\"deleteIcon(this)\"></span>\n" +
            "    <img src=\"\" height=\"700\" width=\"1200\"/>\n" +
            "    <input type=\"hidden\" name=\"postDzImgs\" class=\"dzImgs\" value=\"\">\n" +
            "</div>";
        const imgs = data.dzImgs.split(',');
        const imgContainer = $('#postDzImgsDiv');
        $('.imgSpan', imgContainer).remove();
        const uploader = $('#dzImgsUploader');
        for (var i=0;i<imgs.length;i++) {
            const imgItemEl = $(imgItem);
            imgItemEl.find('img').attr('src', "${commonStaticImgPath}"+imgs[i]);
            imgItemEl.find('input').val(imgs[i]);
            imgItemEl.insertBefore(uploader);
        }
        if (imgs.length >= 4) {
            uploader.hide();
        }
    }

    function setComponentInfoPost(data, form) {
        let assemblyList = data.assemblyList;
        let sysAssemblyList = data.sysAssemblyList;
        let inverterList = data.inverterList;
        let sysInverterList = data.sysInverterList;
        let gridConnectionList = data.gridConnectionList;
        let sysGridConnectionList = data.sysGridConnectionList;
        let gridSupportList = data.gridSupportList;
        let sysGridSupportList = data.sysGridSupportList;
        let tableBody = $("#postComponentTableContent");
        tableBody.empty();
        var i, c=0;

        function fillComponentSelect(row, list, item) {
            let select = row.find('select').eq(0);
            for(var i=0;i<list.length;i++) {
                let option = $("<option></option>");
                option.val(list[i].columns.id);
                option.text(list[i].columns.model);
                select.append(option);
            }
            select.val(item.columns.item_id);
            setTimeout(function() {
                form.render('select');
            }, 0);
        }

        for(i=0;i<assemblyList.length;i++) {
            let row = $(createComponentRowTempl("spec"));
            row.data('type', assemblyList[i].columns.item_type);
            let tds = row.find("td");
            tds.eq(0).text(++c);
            tds.eq(1).html('<i class="mark">*</i>组件');
            fillComponentSelect(row, sysAssemblyList, assemblyList[i]);
            tds.eq(3).find('input').eq(0).val(assemblyList[i].columns.num);
            tableBody.append(row);
        }
        for(i=0;i<inverterList.length;i++) {
            let row = $(createComponentRowTempl2("inverter"));
            row.data('type', inverterList[i].columns.item_type);
            let tds = row.find("td");
            tds.eq(0).text(++c);
            tds.eq(1).html('<i class="mark">*</i>逆变器');
            fillComponentSelect(row, sysInverterList, inverterList[i]);
            tds.eq(3).find('input').eq(0).val(inverterList[i].columns.num);
            tableBody.append(row);
        }
        for(i=0;i<gridConnectionList.length;i++) {
            let row = $(createComponentRowTempl2("gridConnection"));
            row.data('type', gridConnectionList[i].columns.item_type);
            let tds = row.find("td");
            tds.eq(0).text(++c);
            tds.eq(1).html('并网箱');
            fillComponentSelect(row, sysGridConnectionList, gridConnectionList[i]);
            tds.eq(3).find('input').eq(0).val(gridConnectionList[i].columns.num);
            tableBody.append(row);
        }
        for(i=0;i<gridSupportList.length;i++) {
            let row = $(createComponentRowTempl2("gridSupport"));
            row.data('type', gridSupportList[i].columns.item_type);
            let tds = row.find("td");
            tds.eq(0).text(++c);
            tds.eq(1).html('支架');
            fillComponentSelect(row, sysGridSupportList, gridSupportList[i]);
            tds.eq(3).find('input').eq(0).val(gridSupportList[i].columns.num);
            tableBody.append(row);
        }
    }

    function createComponentRowTempl(name) {
        return "<tr>\n" +
            "   <td data-seq></td>\n" +
            "   <td></td>\n" +
            "   <td>\n" +
            "       <select lay-filter=\"" + name + "\" name=\"" + name + "\" lay-search>\n" +
            "           <option value=\"\">请选择</option>\n" +
            "       </select>\n" +
            "   </td>\n" +
            "   <td>\n" +
            "       <input type=\"text\" name=\"num\" oninput=\"compChange(this)\" class=\"layui-input\"/>\n" +
            "   </td>\n" +
            "   <td></td>\n" +
            "</tr>";
    }

    function createComponentRowTempl2(name) {
        return "<tr>\n" +
            "   <td data-seq></td>\n" +
            "   <td></td>\n" +
            "   <td>\n" +
            "       <select lay-filter=\""+name+"\" lay-search>\n" +
            "           <option value=\"\">请选择</option>\n" +
            "       </select>\n" +
            "   </td>\n" +
            "   <td>\n" +
            "       <input type=\"text\" name=\"num\" class=\"layui-input\" />\n" +
            "   </td>\n" +
            "   <td>\n" +
            "       <i class=\"layui-icon layui-icon-add-circle\" style=\"color: #1b6073;font-size: 25px;\"\n" +
            "          onclick=\"addRow(this)\"></i>\n" +
            "       <i class=\"layui-icon layui-icon-delete layui-hide\"\n" +
            "          style=\"color: #1b6073;font-size: 25px;\" onclick=\"deleteRow(this)\"></i>\n" +
            "   </td>\n" +
            "</tr>";
    }

    function savePreComponentInfo(assemblyList, inverterList, gridConnectionList, gridSupportList) {
        let ret = []
        let list = [];
        list = list.concat(assemblyList);
        list = list.concat(inverterList);
        list = list.concat(gridConnectionList);
        list = list.concat(gridSupportList);
        for (var i=0;i<list.length;i++) {
            let el = list[i].columns;
            let item = {
                type: el.item_type,
                spec: el.model,
                itemId: el.item_id,
                num: $.trim(el.num),
                flag: '0'
            }
            ret.push(item);
        }
        preComponents = ret;
    }

    function setComponentInfo(assemblyList, inverterList, gridConnectionList, gridSupportList, tableBody) {
        let row = "<tr>\n" +
            "  <td></td>\n" +
            "  <td></td>\n" +
            "  <td></td>\n" +
            "  <td></td>\n" +
            " </tr>";
        let list = [];
        list = list.concat(assemblyList);
        list = list.concat(inverterList);
        list = list.concat(gridConnectionList);
        list = list.concat(gridSupportList);
        let length = list.length;
        tableBody.empty();
        for (var i = 0; i < length; i++) {
            let tr = $(row);
            let tds = tr.find('td');
            tds.eq(0).text(i+1+"");
            tds.eq(1).text(list[i].columns.label);
            if (list[i].columns.item_type === '3') {
                tds.eq(2).data("power",list[i].columns.model);
                if(info2.columns.component3_model!=null&&info2.columns.component3_model.status == '1'){
                    tds.eq(2).text(list[i].columns.material_model+"Wp");
                }else {
                    tds.eq(2).text(list[i].columns.model+"Wp");
                }
            } else if(list[i].columns.item_type === '1'){
                if(info2.columns.component1_model!=null&&info2.columns.component1_model.status == '1'){
                    tds.eq(2).text(list[i].columns.material_model);
                }else {
                    tds.eq(2).text(list[i].columns.model);
                }
            }else {
                tds.eq(2).text(list[i].columns.model);
            }
            tds.eq(3).text(list[i].columns.num);
            tableBody.append(tr);
        }
    }

    function fillPlanTypeSelect(planTypes, form) {
        let planTypeSelect = $("select[name=planType]");
        planTypeSelect.empty();
        var length = planTypes.length;
        var planTypeHtml = "<option value=''>请选择</option>";
        for (var i = 0; i < length; i++) {
            planTypeHtml+='<option value="'+planTypes[i].columns.id+'">'+planTypes[i].columns.name+'</option>';
        }
        planTypeSelect.append(planTypeHtml);
        form.render('select');
    }

    function clearHtml(){
        $("#stationId").val("");
        $("input[name='status']").val("");
        $("input[name='traderName']").val("");
        $("input[name='projectName']").val("");
        $("input[name='projectCompanyName']").val("");
        $("input[name='tenantName']").val("");
        $("input[name='idCode']").val("");
        $("input[name='address']").val("");
    }
    function appendHtml(data){
    }

    function getStatus(d) {
        var status =d.status;
        if (status == '0') {
            //预审状态 0.暂存 1.待预审 2.预审待审批 3.预审审批中 4.预审通过 5.预审拒绝
            if(d.credit=='1'){
                return '待预审';
            }else if(d.credit=='2'){
                return '预审审批中';
            }else if(d.credit=='3'){
                return '预审审批中';
            }else if(d.credit=='4'){
                if(d.designAuditFlag == '3'){
                    return '自审驳回';
                }else if(d.designAuditFlag == 'a'){
                    return '待设计';
                }else {
                    return '待踏勘';
                }
            }else if(d.credit=='5'){
                return '预审拒绝';
            }
            return '暂存';
        }
        if (status == '1') {
            //设计审核状态：1.待踏勘 2.待自审 3.自审驳回 4.自审通过 5.设计审核驳回 6.设计审核通过/已完成 7.进件审核驳回
            if(d.designAuditFlag=='1'){
                return '待踏勘';
            }else if(d.designAuditFlag=='2'){
                return '待自审';
            }  else if(d.designAuditFlag=='3'){
                return '自审驳回';
            } else if(d.designAuditFlag=='4'){
                return '自审通过';
            } else if(d.designAuditFlag=='5'){
                return '设计审核驳回';
            } else if(d.designAuditFlag=='6'){
                return '设计审核通过';
            } else if(d.designAuditFlag=='7'){
                return '进件审核驳回';
            } else if(d.designAuditFlag=='a'){
                return '待设计';
            }
            return '待审核';
        }
        if (status == '2') {
            return '审核驳回';
        }
        if (status == '3') {
            return '待下单';
        }
        if (status == '4') {
            return '待安装';
        }
        if(status == '5'){
            return '待安装验收';
        }
        if(status == 'f'){
            return '安装验收退回';
        }
        if(status == '6'){
            return '待并网';
        }
        if(status == '7'){
            return '待并网验收';
        }
        if(status == '8'){
            return '待交付';
        }
        if(status == '9'){
            return '待归档';
        }
        if(status == '10'){
            return '验收驳回';
        }
        if(status == '11'){
            return '归档驳回';
        }
        if(status == 'a'){
            return '已完成';
        }if(status == 'c'){
            return '待代理商确认';
        }
        // if(status == 'd'){
        //     return '待上传发票';
        // }
        if(status == 'e'){
            return '待签署合同';
        }
        if(status == 'w'){
            return '信息登记';
        }
        if(status == 'g'){
            return '设计审核';
        }
        if(status == 'AN'){
            return '待安装确认';
        }
        if(status == 'AT'){
            return '安装确认驳回';
        }
        if(status == 'BW'){
            return '待并网确认';
        }
        if(status == 'BN'){
            return '并网确认驳回';
        }
        if(status == 'h'){
            return '设计自审';
        }
        if(status == 'i'){
            return '安装自审';
        }
    }

    function closeSelf() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);//关闭当前页
        parent.parent.layer.closeAll();
    }

    <c:if test="${(fns:checkPagePermission(request, 'DZBG_SJBG_DSH_AUDIT_B') eq '0') && fromAudit eq '1' }">

    let tempReq = false;
    function temp() {
        if (auditing) {
            return;
        }
        var remark = $("input[name='auditRemarks']").val();
        if (isBlank(remark)) {
            layer.msg("请输入审核备注！",{icon:"2"});
            return;
        }
        auditing = true;
        var index= layer.load(2, {shade: [0.5,'#fff'], content:''});
        $.ajax({
            url: "${ctx}/entryChanges/designInfo/tempDesignChange",
            type: "POST",
            contentType : "application/json;charsetset=UTF-8",
            data: JSON.stringify({
                changeId: '${id}',
                msg: remark
            }),
            success: function (data) {
                if (data.code === "200") {
                    top.layer.msg("暂存成功，请处理下一条数据!");
                } else {
                    auditing = false;
                    layer.msg(data.errMsg);
                }
            },
            error: function () {
                layer.msg('系统忙，请稍后再试')
                auditing = false;
            }
            ,complete: function () {
                layer.close(index);
            }
        });
    }


    function pass() {
        audit("1");
    }

    function reject() {
        audit("2");
    }

    let auditing = false;
    function audit(auditResult) {
        if (auditing) {
            return;
        }
        var remark = $("input[name='auditRemarks']").val();
        if (auditResult != '1' && isBlank(remark)) {
            layer.msg("请输入审核备注！",{icon:"2"});
            return;
        }
        auditing = true;
        $.ajax({
            url: "${ctx}/entryChanges/designInfo/auditDesignChange",
            type: "POST",
            contentType : "application/json;charsetset=UTF-8",
            data: JSON.stringify({
                changeId: '${id}',
                value: auditResult,
                msg: remark
            }),
            success: function (data) {
                if (data.code === "200") {
                    top.layer.msg("操作成功");
                    parent.searchOrder();
                    closeSelf();
                } else {
                    auditing = false;
                    layer.msg(data.errMsg);
                }
            },
            error: function () {
                layer.msg('系统忙，请稍后再试')
                auditing = false;
            }
        });
    }
    </c:if>

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }
    function resetSort(){
        var sort = 1;
        $("#contentBody").find("tr").each(function (index) {
            if (!$(this).hasClass("hide")) {
                $(this).find("td:first").text(sort);
                sort++;
            }
        });
    }
    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 approvalRecord(){
        layer.open({
            title: '审批记录',
            type: 2,
            area: ['35%', '100%'],
            offset: 'rt',
            content: '${ctx}/customerEntry/approvalRecordPage?entryId='+$("#stationId").val()
        })
    }
</script>
</body>
</html>
