<%@ 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/style/formSelects-v4.css" media="all">
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/lib/font/iconfont.css" />
</head>
<body>

<div class="layui-fluid">
    <div class="layui-form layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="XMGL_HTQS_HTQS_T" html='<a href="${ctx}/customerEntry/signContract"><li class="layui-this">合同签署</li></a>'/>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " type="reset"  onclick="reset()" >
                    <i class="layui-icon fs-12">&#xe9aa;</i>
                    重置
                </button>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10" id="searchBtn" lay-submit lay-filter="LAY-user-back-search"><i class="layui-icon fs-12">&#xe615;</i>查询</button>
            </ul>
        </div>
        <div class="layui-card-body layuiadmin-card-header-auto" id="searchForm">
            <div class="layui-form-item">
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">产品编号：</label>
                    <div class="layui-input-block" >
                        <select name="projectCode" id="projectId" lay-search>
                            <option value="">请选择</option>
                            <c:forEach items="${projectList}" var="project">
                                <option value="${project.columns.id}">${project.columns.code}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">产品名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="projectName" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">电站编码：</label>
                    <div class="layui-input-block">
                        <input type="text" name="powerStationCode" id="powerStationCode" class="layui-input" autocomplete="off">
                    </div>
                </div>

                <c:if test="${user.userType ne '6' && user.userType ne '7'}">
                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">代理商名称：</label>
                        <div class="layui-input-block" >
                            <select name="traderId" lay-search>
                                <option value="">请选择</option>
                                <c:forEach items="${traderList}" var="trader">
                                    <option value="${trader.columns.id}">${trader.columns.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">代理商电话：</label>
                        <div class="layui-input-block">
                            <input type="text" name="traderMobile" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                </c:if>

                <c:if test="${'2' ne ifTop}">
                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">二级代理商：</label>
                        <div class="layui-input-block">
                            <select name="twoTrader" lay-search>
                                <option value="">请选择</option>
                                <c:forEach items="${twoTrader}" var="trader">
                                    <option value="${trader.columns.id}">${trader.columns.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                </c:if>

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">业主姓名：</label>
                    <div class="layui-input-block">
                        <input type="text" name="tenantName" id="tenantName" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <%--                <div class="layui-col-lg2 layui-col-sm3">--%>
                <%--                    <label class="layui-form-label">安装地址：</label>--%>
                <%--                    <div class="layui-input-block">--%>
                <%--                        <input type="text" name="tenantAddress" id="tenantAddress" class="layui-input" >--%>
                <%--                    </div>--%>
                <%--                </div>--%>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">联系方式：</label>
                    <div class="layui-input-block">
                        <input type="text" name="mobile" id="mobile" class="layui-input" autocomplete="off">
                    </div>
                </div>

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">屋顶类型：</label>
                    <div class="layui-input-block" >
                        <select name="roofType" id="roofType">
                            <option value="">请选择</option>
                            <option value="平屋顶">平屋顶</option>
                            <option value="斜屋顶">斜屋顶</option>
                        </select>
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">备注：</label>
                    <div class="layui-input-block">
                        <input type="text" name="remarks" id="remarks" class="layui-input" >
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">划转方式：</label>
                    <div class="layui-input-block" >
                        <select name="repaymentMethod" id="repaymentMethod">
                            <option value="">请选择</option>
                            <option value="1">二类卡</option>
                            <option value="2">光E宝</option>
                            <option value="0">其它</option>
                        </select>
                    </div>
                </div>

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">审核备注：</label>
                    <div class="layui-input-block">
                        <input type="text" name="examineRemarks" id="examineRemarks" class="layui-input" >
                    </div>
                </div>

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">方案名称：</label>
                    <div class="layui-input-block" >
                        <select name="plan" id="flag">
                            <option value="">请选择</option>
                            <c:forEach items="${plans}" var="plan">
                                <option value="${plan.columns.id}">${plan.columns.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="layui-col-lg4 layui-col-sm6">
                    <label class="layui-form-label">审核时间：</label>
                    <div class="layui-input-block">
                        <div class="layui-col-xs5">
                            <input type="text" name="matchTimeMin" class="layui-input pointer" readonly id="examineTimeStartTime" placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="matchTimeMax" class="layui-input pointer" readonly id="examineTimeEndTime" placeholder="结束日期">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test" lay-filter="test"></table>
        </div>
    </div>
</div>
<!-- toolbar -->
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <sfTags:pagePermission authFlag="XMGL_HTQS_HTQS_SQBG" html='<button class="layui-btn layui-btn-sm" lay-event="retrialBtn" id="retrialBtn"><i class="layui-icon layui-icon-ok-circle"></i>申请整改</button>'/>
        <%--<sfTags:pagePermission authFlag="XMGL_HTQS_HTQS_DCWL" html='<button class="layui-btn layui-btn-sm" lay-event="exportfittingBtn" id="exportfittingBtn"><i class="layui-icon layui-icon-export"></i>导出物料</button>'/>--%>
        <sfTags:pagePermission authFlag="XMGL_HTQS_HTQS_DCLB" html='<button class="layui-btn layui-btn-sm" lay-event="export" id="exportBtn"><i class="layui-icon layui-icon-export"></i>导出列表</button>'/>
    </div>
</script>
<!--操作栏-->
<script type="text/html" id="optTpl">
    {{#if(d.next_apply_status === '1'){    }}
   <%-- <sfTags:pagePermission authFlag="XMGL_HTQS_HTQS_SH" html='<a class="layui-table-opt-link" lay-event="audit">进件审核</a>'/>--%>
    {{#}    }}
    <c:if test="${user.userType eq '6' || user.userType eq '7'}">
        {{#if(d.product_line === '1'){    }}
       <%-- <sfTags:pagePermission authFlag="XMGL_HTQS_HTQS_ECJJSQ" html='<a class="layui-table-opt-link ml-10" lay-event="secEntryApply" id="secEntryApply">进件申请</a>'/>--%>
        {{#} }}
        {{#if(isBlank(d.contract) && d.create_trader_id =='${user.traderId}'){    }}
        <sfTags:pagePermission authFlag="XMGL_HTQS_HTQS_SCHT" html='<a class="layui-table-opt-link ml-10 uploadContract" lay-event="uploadContract">购售电合同</a>'/>
        {{#} }}
    </c:if>
   <%-- {{#if(isBlank(d.bill)){    }}
    <sfTags:pagePermission authFlag="XMGL_HTQS_HTQS_SHFP" html='<a class="layui-table-opt-link ml-10" lay-event="uploadBill">上传发票</a>'/>
    {{#}    }}--%>
    <sfTags:pagePermission authFlag="XMGL_HTQS_HTQS_QSWC" html='<a class="layui-table-opt-link ml-10" lay-event="signFinish">签署完成</a>'/>
</script>
<!-- 电站编码 -->
<script type="text/html" id="stationCodeTpl">
    {{#if(d.design_capacity !== d.actual_capacity){ }}
    <i class="orderNum-diff-icon"></i>
    {{#}    }}
    <c:if test="${user.userType ne '6' && user.userType ne '7'}">
        {{#if(isBlank(d.flag)){ }}
        <i class="icon iconfont" style="color: #8D8D8D" onclick="customerEntryFlag('{{d.id}}')">&#xe6b0;</i>
        {{# }else{  }}
        <i class="icon iconfont " style="color: {{d.flag_type}};" onclick="customerEntryFlag('{{d.id}}')">&#xe6b0;</i>
        {{# }   }}
    </c:if>
    <a href="#" class="layui-table-link" onclick="psDetail('{{d.id}}')">{{d.power_station_code}}</a>
</script>
<!-- 验收报告 -->
<script type="text/html" id="reportTpl">
<%--    <sfTags:pagePermission authFlag="XMGL_HTQS_HTQS_CKYSBG" html=''/>--%>
    <a href="#" class="layui-table-link" onclick="downloadReport('{{d.id}}')">查看</a>
</script>
<!-- 发票 -->
<script type="text/html" id="billTpl">
    {{#if(!isBlank(d.bill)){    }}
    <a href="#" class="layui-table-opt-link" lay-event="viewBill">查看</a>
    {{#}    }}
</script>
<!-- 合同 -->
<script type="text/html" id="contractTpl">
    {{#if(!isBlank(d.contract)){    }}
    <a href="#" class="layui-table-opt-link" lay-event="viewContract">查看</a>
    {{#}    }}
</script>
<!-- 上传文件 -->
<script type="text/html" id="uploadFileTpl">
    <div>
        <div class="upload-div" id="uploadDIV">
            <i class="layui-icon layui-icon-upload file-upload-icon"></i>
            <p>点击上传，或将文件拖拽到此处</p>
        </div>
    </div>
    <p class="ml-20"><i class="red">* </i><span>只能上传pdf文件</span></p>
</script>
<!-- 签署状态查询 -->
<script type="text/html" id="querySignStatusTpl">
    <div class="layui-form pd-20">
        <div class="layui-row mb-10">
            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <label class="layui-form-label">合同签署状态：</label>
                    <div class="layui-form-mid">
                        待签约
                    </div>
                </div>
            </div>
            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <label class="layui-form-label">合同编号：</label>
                    <div class="layui-form-mid">
                        12i74927402102174
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item mb-10">
            <label class="layui-form-label">签署进度：</label>
            <div class="layui-input-block">
                <textarea name="signProgress" readonly placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item mb-10">
            <label class="layui-form-label">退回原因：</label>
            <div class="layui-input-block">
                <textarea name="failReason" readonly placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
    </div>
</script>
<!-- 上传发票 -->
<script type="text/html" id="uploadBillTpl">
    <div>
        <div class="upload-div" id="uploadBillDIV">
            <i class="layui-icon layui-icon-upload file-upload-icon"></i>
            <p>点击上传，或将文件拖拽到此处</p>
        </div>
    </div>
    <p class="ml-20"><i class="red">* </i><span>支持png、jpg等常规图片以及PDF文件</span></p>
    <div class="ml-20 mr-20 mt-20 layui-hide">
        <div class="layui-form-item">
            <div class="layui-form-mid">发票号：</div>
            <div class="layui-input-block" style="margin-left: 70px; top: 3px;">
                <input type="hidden" autocomplete="off" name="bill" readonly/>
                <input type="text" autocomplete="off" name="billNumber" class="layui-input pointer"/>
            </div>
        </div>
    </div>
</script>
<div id="lookImg" class="hide pos-r">
    <div style="position:relative;width:100%;height:500px;">
        <div class="w-500 h-500 lookImg">
            <img src="" width="80%" id="image">
        </div>
        <i class="layui-icon xuanZhuan" style="position:absolute;bottom: -7px;left:50%;">&#xe9aa;</i>
    </div>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/lib/formSelects-v4.js"></script>
<script src="${ctxPlugin}/lib/base64.js"></script>
<script>
    var entrycount=0;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form', 'upload', 'laytpl'], 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;
        laytpl = layui.laytpl;
        table = tableExt.getLayTable();

        var upload = layui.upload;


        //开始日期
        var endStartTime = laydate.render({
            elem: '#examineTimeStartTime'
            /* ,type: 'datetime'*/
            ,done: function(value, date){
                //更新结束日期的最小日期
                endEndTime.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                endEndTime.config.elem[0].focus();
            }
        });
        //结束日期
        var endEndTime = laydate.render({
            elem: '#examineTimeEndTime'
            /* ,type: 'datetime'*/
            ,done: function(value, date){
                //更新开始日期的最大日期
                /* endStartTime.config.max = lay.extend({}, date, {
                     month: date.month - 1
                 });*/
            }
        });

        tableExt.render({
            elem: '#test'
            , title:'发票上传'
            , height: 'full-220'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , url: '${ctx}/customerEntry/ajaxForWaitOrder?status=e'
            , cols: [[
                {type: 'numbers',fixed:'left',title:'序号'}
                ,{field : 'id', minWidth : '4%',checkbox : true,align : 'center',rowspan:'2' , fixed: 'left'}
                , {field : 'id', minWidth : ${user.userType ne '6'? 300: 200} , title: '操作', align : 'center',rowspan:'2' , fixed: 'left', templet: '#optTpl'}
                , {field: 'power_station_code', title: '电站编码',minWidth: 200, sort: false, align: 'center', fixed: 'left',exportable:true, templet: '#stationCodeTpl'}
                ,{field : 'status', minWidth : 120 , title: '电站状态', align : 'center',rowspan:'2',exportable:true, templet: function(d){
                        return d.status === 'e' ? '待签署合同': '';
                    },expFormat:function(d){
                        return d.status === 'e' ? '待签署合同': '';
                    }}
                /*, {
                    field: 'apply_status',
                    title: '进件状态',
                    minWidth: '130',
                    sort: false,
                    align: 'center',
                    exportable: true,
                    templet: function (d) {
                        if (d.management_type === '2') {
                            if (d.apply_status === 'PR') {
                                return "<a href=\"#\" class=\"layui-table-link layui-icon  \" style='font-size:14px;' onclick=\"lookInputEntryStatus('" + d.id + "',2)\">审批通过</a>";
                            } else if (d.apply_status === 'QY') {
                                return "<a href=\"#\" class=\"layui-table-link layui-icon  \" style='font-size:14px;' onclick=\"lookInputEntryStatus('" + d.id + "',2)\">签约</a>";
                            } else if (d.apply_status === 'RJ') {
                                return "拒绝";
                            } else if (d.apply_status === 'NW') {
                                return "未审批";
                            } else if (d.apply_status === 'AP') {
                                return "审批中";
                            }
                        }
                        return "--";
                    },
                    expFormat: function (d) {
                        if (d.management_type === '2') {
                            if (d.apply_status === 'PR') {
                                return "审批通过";
                            } else if (d.apply_status === 'QY') {
                                return "签约";
                            } else if (d.apply_status === 'RJ') {
                                return "拒绝";
                            } else if (d.apply_status === 'NW') {
                                return "未审批";
                            } else if (d.apply_status === 'AP') {
                                return "审批中";
                            }
                        }
                        return "--";
                    }
                }*/
                , {
                    field: 'scheme_type',
                    title: '设计方案',
                    minWidth: 100,
                    sort: false,
                    align: 'center',
                    exportable: true,
                    templet: function (d) {
                        return d.scheme_type === '1'? '标准方案': d.scheme_type === '2'? '组合方案': '';
                    },
                    expFormat: function (d) {
                        return d.scheme_type === '1'? '标准方案': d.scheme_type === '2'? '组合方案': '';
                    }
                }
                , {
                    field: 'planName',
                    title: '方案名称',
                    minWidth: 150,
                    sort: false,
                    align: 'center',
                    exportable: true,
                    templet: function (d) {
                        if (d.scheme_type === '1') {
                            if (isBlank(d.scheme_id)) {
                                return '——';
                            }
                            return '<a href="#" class="layui-table-link" onclick="planDetail(\'' + d.id + '\')">' + d.planName + '</a>';
                        } else if (isBlank(d.planName)) {
                            return '<a href="#" class="layui-table-link" onclick="planDetail(\'' + d.id + '\')">查看方案</a>';
                        } else {
                            return '<a href="#" class="layui-table-link" onclick="planDetail(\'' + d.id + '\')">' + d.planName + '</a>';
                        }
                    }
                }
                , {
                    field: 'sign_status',
                    title: '签约状态',
                    minWidth: '120',
                    sort: false,
                    align: 'center',
                    exportable: true,
                    templet: function (d) {
                        if (d.sign_status === '1') {
                            return "待签约";
                        } else if (d.sign_status === '2') {
                            return "已签约";
                        } else if (d.sign_status === '3') {
                            return "待审核";
                        } else if (d.sign_status === '4') {
                            return "签署驳回";
                        } else if (d.sign_status === '5') {
                            return "已审核";
                        } else {
                            return "--";
                        }
                    },
                    expFormat: function (d) {
                        if (d.sign_status === '1') {
                            return "待签约";
                        } else if (d.sign_status === '2') {
                            return "已签约";
                        } else if (d.sign_status === '3') {
                            return "待审核";
                        } else if (d.sign_status === '4') {
                            return "签署驳回";
                        } else if (d.sign_status === '5') {
                            return "已审核";
                        } else {
                            return "--";
                        }
                    }
                }
             /*   , {
                    field: 'bill',
                    title: '发票',
                    minWidth: 100,
                    sort: false,
                    align: 'center',
                    exportable: false,
                    templet: '#billTpl'
                }*/
                , {
                    field: 'contract',
                    title: '购售电合同',
                    minWidth: 100,
                    sort: false,
                    align: 'center',
                    exportable: false,
                    templet: '#contractTpl'
                }
                <c:if test="${user.userType ne '6' && user.userType ne '7'}">
                    , {
                        field: 'scheme_id',
                        title: '验收报告',
                        minWidth: 100,
                        sort: false,
                        align: 'center',
                        exportable: false,
                        templet: '#reportTpl'
                    }
                </c:if>
                , {field: 'design_capacity', title: '设计安装容量(W)',minWidth: 150, sort: false, align: 'center',exportable:true}
                , {field: 'actual_capacity', title: '实际安装容量(W)',minWidth: 150, sort: false, align: 'center',exportable:true}
                , {field: 'remarks', title: '备注',minWidth: 150, sort: false, align: 'center',exportable:true}
                , {field: 'projectCode', title: '产品编号',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {field: 'projectName', title: '产品名称',minWidth: 130, sort: false, align: 'center',exportable:true}
                <c:if test="${user.userType ne '6' && user.userType ne '7'}">
                , {field: 'traderName', title: '代理商名称',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {field: 'traderMobile', title: '代理商电话',minWidth: 130, sort: false, align: 'center',exportable:true}
                </c:if>
                <c:if test="${'2' ne ifTop}">
                , {field: 'createTraderName',title: '二级代理商',minWidth: '150',sort: false,align: 'center',exportable: true
                    ,templet: function (d) {
                        if(d.distributor_id==d.create_trader_id){
                            return "";
                        }else{
                            return d.createTraderName
                        }
                    },
                    expFormat: function (d) {
                        if(d.distributor_id==d.create_trader_id){
                            return "";
                        }else{
                            return d.createTraderName
                        }
                    }
                }
                </c:if>
                , {field: 'engineer_name', title: '施工团队', minWidth: 150, align: 'center', exportable: true}
                , {field: 'tenant_name', title: '业主姓名',minWidth: 150, sort: false, align: 'center', exportable:true}
                , {field: 'mobile', title: '联系方式',minWidth: 130, sort: false, align: 'center', exportable:true}
                , {field: 'id_code', title: '身份证号',minWidth: 180, sort: false, align: 'center', exportable:true}
                , {field: 'roof_type', title: '屋顶类型',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {field: 'address', title: '安装地址',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {field: 'examine_remarks', title: '审核备注',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {field: 'distance', title: '并网距离（米）',minWidth: 180, sort: false, align: 'center',exportable:true}
                , {
                    field: 'azimuth',
                    title: '方位角',
                    minWidth: 130,
                    sort: false,
                    align: 'center',
                    exportable: true,
                    templet: function (d) {
                        if (d.azimuth === '1') {
                            return '正南';
                        }
                        if (d.azimuth === '2') {
                            return '南偏东';
                        }
                        if (d.azimuth === '3') {
                            return '南偏西';
                        }
                        return '';
                    },
                    expFormat: function (d) {
                        if (d.azimuth === '1') {
                            return '正南';
                        }
                        if (d.azimuth === '2') {
                            return '南偏东';
                        }
                        if (d.azimuth === '3') {
                            return '南偏西';
                        }
                        return '';
                    }
                }

                , {field: 'building_height', title: '建筑高度（米）',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {
                    field: 'shoot_type',
                    title: '拍摄方式',
                    minWidth: 130,
                    sort: false,
                    align: 'center',
                    exportable: true,
                    templet: function (d) {
                        if (d.shoot_type === '1') {
                            return '无人机拍摄';
                        }
                        if (d.shoot_type === '2') {
                            return '手机拍摄';
                        }
                        return '';
                    },
                    expFormat: function (d) {
                        if (d.shoot_type === '1') {
                            return '无人机拍摄';
                        }
                        if (d.shoot_type === '2') {
                            return '手机拍摄';
                        }
                        return '';
                    }
                }
                , {
                    field: 'repayment_method',
                    title: '划款方式',
                    minWidth: 130,
                    sort: false,
                    align: 'center',
                    exportable: true,
                    templet: function (d) {
                        if (d.repayment_method === '1') {
                            return '二类卡';
                        }else if (d.repayment_method === '2') {
                            return '光E宝';
                        }else if (d.repayment_method === '0') {
                            return '其它';
                        }
                        return '';
                    },
                    expFormat: function (d) {
                        if (d.repayment_method === '1') {
                            return '二类卡';
                        }else if (d.repayment_method === '2') {
                            return '光E宝';
                        }else if (d.repayment_method === '0') {
                            return '其它';
                        }
                        return '';
                    }
                }
                , {
                    field: 'product_line_name',
                    title: '产品线',
                    minWidth: '150',
                    sort: false,
                    align: 'center',
                    exportable: true
                }
                , {
                    field: 'product_line',
                    title: '业务属性',
                    minWidth: '100',
                    sort: false,
                    align: 'center',
                    exportable: true,
                    templet: function (d) {
                        return transAttribute(d.product_line);
                    },
                    expFormat: function (d) {
                        return transAttribute(d.product_line);
                    }
                }
                , {
                    field: 'project_company_name',
                    title: '所属项目公司',
                    minWidth: '150',
                    sort: false,
                    align: 'center',
                    exportable: true
                }
                , {field: 'create_time', title: '登记时间',minWidth: 180, sort: false, align: 'center',exportable:true}
               /* , {field: 'to_examine_time', title: '提交时间',minWidth: 180, sort: false, align: 'center',exportable:true}*/
                , {field: 'examine_time', title: '审核时间',minWidth: 180, sort: false, align: 'center',exportable:true}
                , {field: 'examine_remarks', title: '审核备注',minWidth: 130, sort: false, align: 'center',exportable:true}
            ]]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '合同签署',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 5000,                    //当pageData为false生效
                fileName: '合同签署',
                where: function (){                 //当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            },done: function(res, curr, count){
                //得到数据总量
                entrycount = count;
            }
        });

        function transAttribute(productLineAttribute) {
            switch (productLineAttribute) {
                case '1':
                    return '纯租25年业务';
                case '2':
                    return '经营性租赁';
                case '3':
                    return '融资租赁';
                case '4':
                    return '光伏贷';
                case '5':
                    return '全款';
                case '6':
                    return '其他';
                default:
                    return '';
            }
        }

        table.on('toolbar(test)',function(obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            if (obj.event === 'retrialBtn') {
                if(checkStatus.data.length < 1){
                    if(checkStatus.data[i].create_trader_id != '${user.traderId}'){
                        layer.msg("第"+(i+1)+"条数据,没有整改权限!",{icon:5,anim:6});
                        return;
                    }
                    layer.msg("请先选择数据",{icon:5,anim:6});
                    return;
                }
                var ids = [];
                for(var i=0; i<checkStatus.data.length; i++){
                    ids.push(checkStatus.data[i].id);
                }
                layer.open({
                    type: 2,
                    content: "${ctx}/customerEntry/applyChangeDetail?ids="+ids
                    ,title: "申请整改"
                    ,area:["50%","60%"]
                });


            }else  if (obj.event === 'exportfittingBtn') {
                if(entrycount<1){
                    layer.msg('当前无数据导出', {time: 1000});
                    return ;
                }

                let hideSubmitForm = document.createElement("form");
                hideSubmitForm.id = "tempForm1";
                hideSubmitForm.method = "post";
                hideSubmitForm.action = "${ctx}/excel/doExportUserExcel";
                hideSubmitForm.target = "_blank";
                hideSubmitForm.appendChild(createHideInput("status", "6,10"));
                hideSubmitForm.appendChild(createHideInput("projectId", isBlank($("#projectId").val())?"":$("#projectId").val()));
                hideSubmitForm.appendChild(createHideInput("powerStationCode", isBlank($("#powerStationCode").val())?"":$("#powerStationCode").val()));
                hideSubmitForm.appendChild(createHideInput("tenantName", isBlank($("#tenantName").val())?"":$("#tenantName").val()));
                hideSubmitForm.appendChild(createHideInput("tenantAddress", isBlank($("#tenantAddress").val())?"":$("#tenantAddress").val()));
                hideSubmitForm.appendChild(createHideInput("installWay", isBlank($("#installWay").val())?"":$("#installWay").val()));
                hideSubmitForm.appendChild(createHideInput("roofType", isBlank($("#roofType").val())?"":$("#roofType").val()));
                hideSubmitForm.appendChild(createHideInput("plan", isBlank($("#plan").val())?"":$("#plan").val()));
                hideSubmitForm.appendChild(createHideInput("flag", isBlank($("#flag").val())?"":$("#flag").val()));
                hideSubmitForm.appendChild(createHideInput("remarks", isBlank($("#remarks").val())?"":$("#remarks").val()));
                hideSubmitForm.appendChild(createHideInput("installEndEndTime",isBlank($("#endStartTime").val())?"": $("#endStartTime").val()));
                hideSubmitForm.appendChild(createHideInput("installEndEndTime", isBlank($("#endEndTime").val())?"":$("#endEndTime").val()));

                hideSubmitForm.addEventListener('onsubmit',function(){
                    // this.openDownloadWindow(name);
                });
                document.body.appendChild(hideSubmitForm);
                hideSubmitForm.submit();
                document.body.removeChild(hideSubmitForm);

                //  window.open("${ctx}/excel/doExportUserExcel?status=3&"+$("#searchForm"))
            }
        });

        table.on('tool(test)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

            if (layEvent === 'audit') {
                examineInputEntry(data.id);
            }else if(layEvent === 'uploadContract'){
                uploadContract('购售电合同', function(path){
                    $.ajax({
                        type: 'post',
                        url: '${ctx}/customerEntry/uploadContract',
                        contentType: 'application/json',
                        data: JSON.stringify({
                            entryId: data.id,
                            path: path
                        }),
                        dataType: 'json',
                        success: function (res) {
                            if (res.code === '200') {
                                layer.msg('上传成功');
                                searchOrder();
                            } else if (res.code === '501') {
                                layer.msg(res.errMsg);
                                searchOrder();
                            } else {
                                layer.msg('上传失败');
                            }
                        }
                    })
                });
            }else if(layEvent === 'viewContract'){
                var url = '${commonStaticImgPath}' + data.contract;
                <%--window.open('${commonStaticImgPath}' + data.contract)--%>
                previewUrl(url);
            }else if(layEvent === 'viewGdsContract'){
                window.open('${commonStaticImgPath}' + data.gsd_contract)
            }else if(layEvent === 'viewBill'){
                var img = '${commonStaticImgPath}' + data.bill;
                $("#lookImg img").attr('src',img);
                layer.open({
                    type:1,
                    title:'查看图片',
                    area:['500px','550px'],
                    content:$("#lookImg")
                })
                <%--window.open('${commonStaticImgPath}' + data.bill)--%>
            } else if (layEvent === 'secEntryApply'){
                //二次进件申请
                preInputEntry(data.id)
            } else if (layEvent === 'uploadBill') {
                //上传发票
                uploadBill('上传发票', function (path, layIndex) {
                    console.log(path);
                    $.ajax({
                        type: 'post',
                        url: '${ctx}/customerEntry/uploadBillAndNo',
                        contentType: 'application/json',
                        data: JSON.stringify({
                            id: data.id,
                            bill: path,
                            billNumber: ''
                        }),
                        success: function (data) {
                            if (data.code === '200') {
                                layer.msg('操作成功');
                                searchOrder();
                                layer.close(layIndex);
                            } else if (data.code === '501') {
                                layer.msg(data.errMsg);
                            } else {
                                layer.msg('操作失败');
                            }
                        }
                    })

                }, function (layIndex) {
                    return false;
                });
            } else if(layEvent === 'signFinish'){
                layer.confirm('确认签署完成，提交并网验收？', function(){
                    $.ajax({
                        type: 'post',
                        url: '${ctx}/customerEntry/signFinish',
                        data: {
                            entryId: data.id
                        },
                        dataType: 'json',
                        success: function (data) {
                            if (data.code === '200') {
                                layer.msg('操作成功');
                                searchOrder();
                                layer.close(signWin);
                            } else if (data.code === '501') {
                                layer.msg(data.errMsg);
                            } else {
                                layer.msg('操作失败');
                            }
                        }
                    });
                });
            }
        });

        //旋转
        var deg = 0;
        $(".xuanZhuan").click(function(){
            deg += 90;
            document.getElementById("image").style.transform = "rotate(" + deg + "deg)";
        })

        //上传发票
        function uploadBill(title, done, yes){
            var uploadIndex = layer.open({
                type: 1,
                title: title,
                content: $('#uploadBillTpl').html(),
                area: ['600px', '500px'],
                btn: ['确定', '取消'],
                yes: function () {
                    yes(uploadIndex);
                },
                success: function (layero, index) {
                    upload.render({
                        elem: '#uploadBillDIV' //绑定元素
                        , url: '${ctx}/common/uploadFile' //上传接口
                        , accept: 'file'
                        , exts: 'pdf|png|jpg|jpeg'
                        , auto: false
                        , bindAction: '.layui-layer-btn0'
                        , done: function (res) {
                            //上传完毕回调
                            done(res.path, uploadIndex);
                            // layer.close(uploadIndex);
                        }
                        , error: function () {
                            //请求异常回调
                        }
                    });
                }
            })
        }


        function uploadContract(title, done) {
            var uploadIndex = layer.open({
                type: 1,
                title: title,
                content: $('#uploadFileTpl').html(),
                area: ['600px', '500px'],
                btn: ['确定', '取消'],
                yes: function () {
                    return false;
                },
                success: function (layero, index) {
                    upload.render({
                        elem: '#uploadDIV' //绑定元素
                        , url: '${ctx}/common/uploadFile' //上传接口
                        , accept: 'file'
                        , exts: 'pdf'
                        , auto: false
                        , bindAction: '.layui-layer-btn0'
                        , done: function (res) {
                            //上传完毕回调
                            done(res.path);
                            layer.close(uploadIndex);
                        }
                        , error: function () {
                            //请求异常回调
                        }
                    });
                }
            })
        }

        function viewContact(filePath){

        }

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

        //监听搜索
        form.on('submit(LAY-user-back-search)', function(data){
            var field = data.field;
            //执行重载
            tableExt.reload('test', {
                where: field,
                page:{
                    curr:1
                }
            });
        });
    })

    function downloadReport(id){
        layer.open({
            type: 2,
            title: '验收报告',
            content: '${ctx}/customerEntry/toMergeAccept?opt=view&id=' + id,
            area: ['80%','80%']
        });
    }

    function downloadAttach(attach){
        attach=decodeURI(attach);
        attach = attach.replace(/\+/g,"%2B"); //
        window.location.href = '${commonStaticImgPath}' + attach;
    }

    function searchOrder() {
        //执行重载
        table.reload('test', {
            where: function (){
                return _serializeJson($("#searchForm"));
            }
        });
    }

    //查看详情
    function psDetail(id){
        layer.open({
            type: 2
            , title: '电站详情'
            , content: '${ctx}/customerEntry/entryDetail?entryId=' + id
            , area: ['100%', '100%']
            , yes: function(index, layero){

            }
        });
    }

    function examineInputEntry(id){
        layer.open({
            type: 2,
            title: '审核进件申请',
            content: '${ctx}/customerEntryExtra/supplyTwoInputEntry?id='+id,
            area: ['63%','60%']
        });
    }

    function customerEntryFlag(id){
        layer.open({
            type: 2,
            content: "${ctx}/customerEntry/getFlagcustomerEntry?customerEntryId="+id //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
            ,title: "标记项目"
            ,area:["300px","260px"]
            ,closeBtn: 0
            ,shadeClose:true

        });
    }

    function planDetail(entryId){
        layer.open({
            type: 2,
            title: '查看',
            content: '${ctx}/planManage/viewMatchedPlan?entryId=' + entryId,
            area: ['80%','80%']
        });
    }

    function margeAccept(id){
        layer.open({
            type: 2,
            title: '验收报告',
            content: '${ctx}/customerEntry/toMergeAccept?opt=merge&id=' + id,
            area: ['80%','80%']
        });
    }

    function preInputEntry(id){
        layer.open({
            type: 2,
            title: '二次进件申请',
            content: '${ctx}/customerEntryExtra/supplyInputEntry?id='+id,
            area: ['63%','60%']
        });
    }

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }

    function lookInputEntryStatus(id,type){
        layer.open({
            type: 2,
            title: '查看进件状态',
            content: '${ctx}/customerEntryExtra/lookInputEntryStatus?id='+id+'&type='+type,
            area : [ '650px', '450px' ],
            cancel:function(){
                table.reload('test'); //数据刷新
            }
        });
    }

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

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

