<%@ 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"/>
    <style>
        .inline-block{display: inline-block}
    </style>
</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_XMGL_XILR_ADD_T_${partner}" html='<a href="${ctx}/customerEntry/temporaryStorageList/${partner}"><li class="layui-this">信息登记</li></a>'/>
               <sfTags:pagePermission authFlag="XMGL_XMGL_XXSQS_T_${partner}" html='<a href="${ctx}/customerEntry/infoAuthorizationList/${partner}"><li>信息授权书</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">
            <form class="layui-form layui-card" action="" 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">
                            <input type="text" name="powerStationCode" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-col-lg2 layui-col-sm2">
                        <label class="layui-form-label">业主姓名：</label>
                        <div class="layui-input-block">
                            <input type="text" name="tenantName" class="layui-input">
                        </div>
                    </div>

                    <c:if test="${user.userType ne '6' && user.userType ne '7'}">
                        <div class="layui-col-lg2 layui-col-sm2" style="width: 33.3%">
                            <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>

                    </c:if>

                    <c:if test="${'2' ne ifTop}">
                        <div class="layui-col-lg2 layui-col-sm2" style="width: 33.3%">
                            <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-sm2">
                        <label class="layui-form-label">产品名称：</label>
                        <div class="layui-input-block">
                            <input type="text" name="projectName" 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="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">

                            <select name="credit"   lay-search>
                                <%--<option value="0,1,2,3,5">请选择</option>--%>
                                <option value="">请选择</option>
                                <option value="0">暂存</option>
                                <option value="1">待预审</option>
                                <option value="2,3">预审中</option>
<%--                                <option value="4">预审通过</option>--%>
                                <option value="5">预审驳回</option>

                            <%--    <c:forEach items="${projectList}" var="pro">
                                    <option value="${pro.columns.id}">${pro.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="mobile" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-col-lg2 layui-col-sm2">
                        <label class="layui-form-label">授权状态：</label>
                        <div class="layui-input-block">
                            <select name="authorization">
                                <option value="">请选择</option>
                                <option value="1">未授权</option>
                                <option value="2">已发起</option>
                                <option value="3">已授权</option>
                                <option value="4">无授权</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" class="layui-input">
                        </div>
                    </div>--%>
                    <div class="layui-col-lg4 layui-col-sm4 layui-col-md4" >
                        <label class="layui-form-label">安装地址：</label>
                        <div class="inline-block" style="width: 18%">
                            <select name="province" lay-search lay-filter="province"  id="province">
                                <option value="">省</option>
                                <c:forEach items="${province}" var="trader">
                                    <option value="${trader.columns.ProvinceName}"  title="${trader.columns.ProvinceID}">${trader.columns.ProvinceName}</option>
                                </c:forEach>
                            </select>

                        </div>
                        <div class="inline-block" style="width: 18%;">
                            <select name="city" id="city" lay-filter="city"
                                    lay-search>
                                <option value="">市</option>

                            </select>
                        </div>
                        <div class="inline-block" style="width: 18%">
                            <select name="area" id="area" lay-search>
                                <option value="">县/区</option>

                            </select>
                        </div>
                        <div class="inline-block" style="width: 20%">
                            <input type="text" name="address" class="layui-input">

                        </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="createTimeMin" class="layui-input" id="createEndStartTime"
                                       placeholder="开始日期">
                            </div>
                            <div class="layui-col-xs2 text-c lh-30">
                                —
                            </div>
                            <div class="layui-col-xs5">
                                <input type="text" name="createTimeMax" class="layui-input" id="createEndEndTime"
                                       placeholder="结束日期">
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test" lay-filter="test"></table>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                     <c:if test="${user.userType eq '6' || user.userType eq '7'}">
                         <sfTags:pagePermission authFlag="XMGL_DZDACX_XXDJ_B_${partner}"
                                                html=' <button class="layui-btn layui-btn-sm" lay-event="infoEntry" id="infoEntry"><i class="layui-icon layui-icon-add-1"></i>信息登记</button> '/>
                     </c:if>
                     <sfTags:pagePermission authFlag="XMGL_DZDACX_PLSC_B_${partner}"
                                            html=' <button class="layui-btn layui-btn-sm" lay-event="batchDelete" id="batchDelete"><i class="layui-icon layui-icon-delete"></i>批量删除</button> '/>

                     <sfTags:pagePermission authFlag="XMGL_DZDACX_TJYS_B_${partner}"
                                            html=' <button class="layui-btn layui-btn-sm" lay-event="audit" id="audit"><i class="layui-icon layui-icon-auz"></i>提交预审</button> '/>
                    <c:if test="${user.userType eq '6' || user.userType eq '7'}">
                        <button class="layui-btn layui-btn-sm" lay-event="getSignUrl" id="audit"><i
                                class="layui-icon layui-icon-auz"></i>获取授权链接
                        </button>
                    </c:if>
                    <sfTags:pagePermission authFlag="XMGL_DZDACX_UPLOAD_${partner}"
                                           html=' <button class="layui-btn layui-btn-sm" lay-event="uploadFile" id="uploadFile"><i class="layui-icon layui-icon-auz"></i>上传信息授权书</button> '/>
                    <button class="layui-btn layui-btn-sm" lay-event="export" id="exportBtn"><i
                            class="layui-icon layui-icon-export"></i>导出列表
                    </button>
                </div>
            </script>
        </div>
    </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>
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer', 'laypage', 'laydate', 'form'], function () {
        //layui.use(['table','layer','laypage','laydate','form'], function(){
        $ = layui.$;
        tableExt = layui.tableExt;
        layer = layui.layer;
        laypage = layui.laypage;
        laydate = layui.laydate;
        form = layui.form;
        table = tableExt.getLayTable();

        var type = "${user.userType}";

        //开始日期
        var endStartTime = laydate.render({
            elem: '#createEndStartTime'
            /* ,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: '#createEndEndTime'
            /* ,type: 'datetime'*/
            , done: function (value, date) {
                //更新开始日期的最大日期
                endStartTime.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        var editFg='${fns:checkPagePermission(request, editBthPermission)}';


        tableExt.render({
            elem: '#test'
            , title: '信息登记'
            , height: 'full-190'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits: [20, 50, 100]
            , limit: 20
            , page: true //开启分页
            , url: '${ctx}/customerEntry/ajaxForTemporaryStorageData?partner='+'${partner}'
            , method:"post"
            , cols: [[
                {type: 'numbers', fixed: 'left', title: '序号'}
                , {type: 'checkbox', fixed: 'left'}
                , {
                    field: 'id',
                    title: '操作',
                    minWidth: '130',
                    align: 'center',
                    fixed: 'left',
                    templet: function (d) {
                        var html = "";
                        if (type !== '6' && type !== '7') {
                            if (d.credit == '2' || d.credit == '3' ) {
                                html += "<a href=\"#\" class=\"layui-table-link layui-icon  \" style='font-size:14px;' onclick=\"findResult('" + d.id + "', '"+d.credit+"')\">预审查询</a>&nbsp;&nbsp;";
                            }
                            if (d.credit == '5' && d.patnerId == '04'){
                                html += "<a href=\"#\" class=\"layui-table-link layui-icon  \" style='font-size:14px;' onclick=\"findResult('" + d.id + "', '"+d.credit+"')\">预审查询</a>&nbsp;&nbsp;";
                            }
                        } else {

                             if(editFg==0){
                                 if(d.status=='0' && (d.credit == '0'|| d.credit == '5') && d.create_trader_id == '${user.traderId}'){
                                     html += "<a href=\"#\" class=\"layui-table-link layui-icon   \" style='font-size:14px;' onclick=\"editCustomerEntry('" + d.id + "')\">编辑</a>&nbsp;&nbsp;";
                                 }
                             }
                            if (d.credit == '2' || d.credit == '3') {
                                html += "<a href=\"#\" class=\"layui-table-link layui-icon  \" style='font-size:14px;' onclick=\"findResult('" + d.id + "', '"+d.credit+"')\">预审查询</a>&nbsp;&nbsp;";
                            }
                            if (d.credit == '5' && d.patnerId == '04'){
                                html += "<a href=\"#\" class=\"layui-table-link layui-icon  \" style='font-size:14px;' onclick=\"findResult('" + d.id + "', '"+d.credit+"')\">预审查询</a>&nbsp;&nbsp;";
                            }

                        }

                        if (!isBlank(html)) {
                            return html;
                        } else {
                            return "--";
                        }
                    }
                }
                , {
                    field: 'power_station_code',
                    title: '电站编码',
                    minWidth: 150,
                    sort: false,
                    fixed: 'left',
                    align: 'center',
                    exportable: true,
                    templet: function (d) {
                        var flag = d.flag;
                        var html = "";
                        <c:if test="${user.userType ne '6' && user.userType ne '7'}">
                        if (isBlank(flag)) {//
                            html = "<i class=\"icon iconfont\" style=\"color: #8D8D8D\" onclick=\"customerEntryFlag('" + d.id + "')\">&#xe6b0;</i>";
                        } else {
                            html = "<i class=\"icon iconfont \" style=\"color: " + d.flag_type + ";\" onclick=\"customerEntryFlag('" + d.id + "')\">&#xe6b0;</i>";
                        }
                        </c:if>
                        return html + '<a href="#" class="layui-table-link" onclick="psDetail(\'' + d.id + '\')">' + d.power_station_code + '</a>';
                    }
                }
                , {
                    field: 'tenant_name',
                    title: '业主姓名/单位名称',
                    fixed: 'left',
                    minWidth: '200',
                    sort: false,
                    align: 'center',
                    exportable: true
                }
                , {
                    field: 'status',
                    title: '电站状态',
                    minWidth: '120',
                    sort: false,
                    fixed: 'left',
                    align: 'center',
                    exportable: true,
                    templet: function (d) {
                        //预审状态 0.暂存 1.待预审 2.预审待审批 3.预审审批中 4.预审通过 5.预审拒绝
                        if (d.credit === '0') {
                            return "暂存";
                        } else if (d.credit === '1') {

                            return "待预审";
                        } else if (d.credit === '2') {
                            return "预审中";
                        } else if (d.credit === '3') {
                            return "预审中";
                        } else if (d.credit === '4') {
                            return "预审通过";
                        }  else if (d.credit === '5') {
                            return "预审拒绝";
                        }else {
                            return "暂存";
                        }
                    },
                    expFormat: function (d) {
                        if (d.credit === '0') {
                            return "暂存";
                        } else if (d.credit === '1') {

                            return "待预审";
                        } else if (d.credit === '2') {
                            return "预审中";
                        } else if (d.credit === '3') {
                            return "预审中";
                        } else if (d.credit === '4') {
                            return "预审通过";
                        }  else if (d.credit === '5') {
                            return "预审拒绝";
                        }else {
                            return "暂存";
                        }
                    }
                }, {
                    field: 'authorization',
                    title: '授权状态',
                    minWidth: '100',
                    sort: false,
                    fixed: 'left',
                    align: 'center',
                    exportable: true,
                    templet: function (d) {
                        if(d.tenant_type ==='2'){
                            return "-"
                        }
                        //1.未授权 2.已发起 3.已授权
                         if (d.authorization === '2') {
                            return "已发起";
                        }else if (d.authorization === '3') {
                             return "已授权";
                         } else if((d.authorization === '4')){
                             return "无授权";
                        }else{
                             return "未授权";
                         }
                    },
                    expFormat: function (d) {
                        if(d.tenant_type ==='2'){
                            return "-"
                        }
                        if (d.authorization === '2') {
                            return "已发起";
                        }else if (d.authorization === '3') {
                            return "已授权";
                        } else {
                            return "未授权";
                        }
                    }
                }
                , {
                    field: 'examine_remarks',
                    title: '审核备注',
                    minWidth: '130',
                    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: '150',
                    sort: false,
                    align: 'center',
                    exportable: true
                }
                , {
                    field: 'traderMobile',
                    title: '代理商电话',
                    minWidth: '100',
                    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: 'tenantFlag', title: '标识', minWidth: '100', sort: false, align: 'center', exportable: true,hide:true}
                , {field: 'mobile', title: '联系方式', minWidth: '100', sort: false, align: 'center', exportable: true}
                , {field: 'id_code', title: '身份证号', minWidth: '100', sort: false, align: 'center', exportable: true}
                , {field: 'address', title: '安装地址', minWidth: '100', sort: false, align: 'center', exportable: true}
                , {field: 'remarks', title: '备注', minWidth: '150', sort: false, align: 'center', exportable: true}
                , {
                    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
                }
            ]], done: function (res, cuss, count) {
                $('span[data-pass="passed"]').parent().parent().parent().css('background-color', '#ffeaf2');
                // $('.layui-table-header .laytable-cell-checkbox input').attr('disabled', 'disabled');
            }
            , exportOpt: {                           //导出选项配置
                ele: '#exportBtn',                   //导出的Dom元素
                headerTitle: '信息登记',             //excel表格的标题
                pageData: false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 5000,                    //当pageData为false生效
                fileName: '信息登记',
                where: function () {                 //当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

        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);
            var ids = [];
            switch (obj.event) {
                case 'infoEntry':
                    layer.open({
                        type: 2,
                        content: '${ctx}/customerEntry/platform/addNewCustomerEntry?capitalId=' + '${partner}',
                        title: '信息登记',
                        area: ['100%', '100%']
                        <%--type: 2,--%>
                        <%--content: '${ctx}/customerEntry/platform/chooseProduct',--%>
                        <%--title: '请选择资方',--%>
                        <%--area: ['80%', '50%']--%>
                    });
                    break;
                case 'batchDelete':
                    if (checkStatus.data.length < 1) {
                        layer.msg("请先选择数据",{icon:5,anim:6});
                        return;
                    }
                    for (var i = 0; i < checkStatus.data.length; i++) {
                        /*if(checkStatus.data[i].create_trader_id != '${user.traderId}'){
                            layer.msg("第"+(i+1)+"条数据,没有删除权限!",{icon:5,anim:6});
                            return;
                        }*/
                        ids.push(checkStatus.data[i].id);
                    }
                    var data = {
                        ids: ids
                    }
                    layer.confirm('删除电站同时会删除客户信息，您确认继续删除吗?',{
                        btn: ['确定', '取消'],
                        success: function (layero, index) {
                            this.enterEsc = function (event) {
                                if (event.keyCode == 13 ) {
                                    //确认  执行的代码
                                    deleteEntry(data);
                                    //关闭弹窗
                                    layer.close(index);
                                    console.log("回车确认时事件")
                                    //取消连续回车键，导致不断弹出询问框
                                    $(':focus').blur();
                                }
                            };
                            //监听键盘事件
                            $(document).on('keydown', this.enterEsc);
                            //esc键触发取消
                            this.escQuit = (ev) => {
                                let code_val = ev.which;
                                if(code_val == 0x1B){
                                    $('.layui-layer-btn1').click();
                                    return false;
                                }
                            };
                            $(document).on('keydown', this.escQuit);
                        },
                        end: function () {
                            //取消键盘监听事件
                            $(document).off('keydown', this.enterEsc);
                            $(document).off('keydown', this.escQuit);
                        },
                        yes: function () {
                            //确认执行的代码
                            deleteEntry(data);
                        },
                        no: function () {

                        }
                    });
                    break;
                case 'admit':
                    if (checkStatus.data.length < 1) {
                        layer.msg("请先选择数据",{icon:5,anim:6});
                        return;
                    }
                    for (var i = 0; i < checkStatus.data.length; i++) {
                        ids.push(checkStatus.data[i].id);
                    }
                    var data = {
                        ids: ids
                    }
                    layer.confirm('确定对选中数据申请准入？', {
                        icon: 3,
                        btn: ['确定', '取消']
                    }, function () {
                        $.ajax({
                            type: 'post',
                            url: '${ctx}/customerEntry/batchAdmit',
                            contentType: 'application/json;charsetset=UTF-8',
                            data: JSON.stringify(data),
                            success: function(result) {
                                if (result.code === '200') {
                                    layer.msg('操作成功', {time: 1000}, function() {
                                        $(".layui-laypage-btn").click();
                                    });
                                } else {
                                    layer.msg('操作失败！'+result.errMsg);
                                }
                            }
                        })
                    });
                    break;
                case 'audit':
                    if (checkStatus.data.length < 1) {
                        layer.msg("请先选择数据",{icon:5,anim:6});
                        return;
                    }
                    var checkItem = false;
                    for (var i = 0; i < checkStatus.data.length; i++) {
                        var authorization = checkStatus.data[i].authorization;
                        var tenant_type = checkStatus.data[i].tenant_type;
                        var filing_type = checkStatus.data[i].filing_type;
                        var tenantFlag = checkStatus.data[i].tenantFlag;
                        var isHistory = checkStatus.data[i].is_history;
                        if (isHistory == '1'){
                            layer.msg("第"+(i+1)+"条数据是历史电站，不可提交预审!",{icon:5,anim:6});
                            checkItem = true;
                            return;
                        }
                        if(tenantFlag != '1'){
                            if (${partner ne '04'}){
                                if (authorization != '3' && '1' == tenant_type) {
                                    layer.msg('选中数据未完成信息使用授权',{icon:5,anim:6});
                                    checkItem = true;
                                    return;
                                }
                            }else {
                                if ('1' == filing_type){
                                    if (authorization != '3') {
                                        layer.msg('选中数据未完成信息使用授权',{icon:5,anim:6});
                                        checkItem = true;
                                        return;
                                    }
                                }else {
                                    if (authorization != '3' && authorization != '2' ) {
                                        layer.msg('选中数据未完成信息使用授权',{icon:5,anim:6});
                                        checkItem = true;
                                        return;
                                    }
                                }

                            }
                            if(checkStatus.data[i].create_trader_id != '${user.traderId}' && ${user.id ne '1'} && ${user.userType ne '4'} ){
                                layer.msg("第"+(i+1)+"条数据,没有提交预审权限!",{icon:5,anim:6});
                                return;
                            }
                        }
                        ids.push(checkStatus.data[i].id);
                    }
                    if (checkItem) {
                        return;
                    }
                    var data = {
                        ids: ids
                    }
                    layer.confirm('确定对选中数据提交预审？', {
                        icon: 3,
                        btn: ['确定', '取消']
                    }, function () {
                        var index= layer.load(2, {shade: [0.5,'#fff'], content:''});
                        $.ajax({
                            type: 'post',
                            url: '${ctx}/customerEntry/batchAdmit',
                            contentType: 'application/json;charsetset=UTF-8',
                            data: JSON.stringify(data),
                            success: function(result) {
                                if (result.code === '200') {
                                    layer.msg('提交成功', {time: 1000}, function() {
                                        $(".layui-laypage-btn").click();
                                    });
                                } else {
                                    layer.msg('提交失败！'+result.errMsg);
                                }
                            },
                            complete: function () {
                                layer.close(index);
                            },
                        })
                    });
                    break;
                case 'getSignUrl':
                    if (checkStatus.data.length < 1) {
                        layer.msg("请先选择数据",{icon:5,anim:6});
                        return;
                    }
                    if (checkStatus.data.length > 1) {
                        layer.msg("最多只能选择一条数据",{icon:5,anim:6});
                        return;
                    }
                    if (isBlank(checkStatus.data[0].id_code)) {
                        layer.msg("身份证号为空，没有授权信息！",{icon:5,anim:6});
                        return;
                    }
                    var idCode=checkStatus.data[0].idCode;
                    var mobile=checkStatus.data[0].mobile;
                    var patnerId=checkStatus.data[0].patnerId;

                    $.ajax({
                        type: 'post',
                        url: '${ctx}/customerEntry/getEsignUrl',
                        data: {
                            idCode: idCode,
                            mobile:mobile,
                            patnerId:patnerId
                        },
                        success: function(result) {
                            if (result.code === '200') {
                                layer.confirm('授权签约短链接：'+result.data.shortUrl, {
                                    icon: 3,
                                    btn: ['确定', '取消']
                                })
                            } else {
                                layer.msg(result.errMsg);
                            }
                        }
                    })

                    break;
                case 'uploadFile':
                    if (checkStatus.data.length < 1) {
                        layer.msg("请先选择数据",{icon:5,anim:6});
                        return;
                    }
                    if (checkStatus.data.length > 1) {
                        layer.msg("最多只能选择一条数据",{icon:5,anim:6});
                        return;
                    }
                    if ('2' == checkStatus.data[0].tenant_type){
                        layer.msg("单位无需上传信息授权书",{icon:5,anim:6});
                        return;
                    }
                    if (checkStatus.data[0].create_time > '2024-09-26 00:00:00' && checkStatus.data[0].distributor_id !== '2c96190d9178ac2601917cc9598c0e80'){
                        layer.msg("历史电站才可上传信息授权书",{icon:5,anim:6});
                        return;
                    }
                    if (checkStatus.data[0].credit != '0' || checkStatus.data[0].authorization != '1')  {
                        layer.msg("当前电站状态不可上传信息授权书",{icon:5,anim:6});
                        return;
                    }
                    let entryId = checkStatus.data[0].id;
                    layer.open({
                        type: 2,
                        title: '上传信息授权书',
                        content: '${ctx}/customerEntry/uploadAuthorizationPage?entryId='+entryId,
                        area: ['30%', '30%']
                    });
                    break;
            }

        });

        form.on('select(province)', function (data) {
            var province = $(data.elem).find("option:selected").attr("title");
            provinceOrder(province);
        });
        form.on('select(city)', function (data) {
            var city = $(data.elem).find("option:selected").attr("title");
            cityOrder(city);

        });

        function provinceOrder(province) {
            $("#city").empty();
            $("#area").empty();
            if (isBlank(province)) {
                $("#city").append("<option value=''>市</option>");
                return "";
            }
            $.ajax({
                type: "POST",
                url: "${ctx}/main/redirect/getCitysByProId",
                data: {
                    province: province
                },
                success: function (result) {

                    if (result == "205") {
                        layer.msg("暂无数据!")
                        return
                    }
                    var html = " <option value=''>市</option>";
                    for (var i = 0; i < result.length; i++) {
                        var city = result[i];
                        html = html + '<option value="' + city.columns.CityName + '" title="' + city.columns.CityID + '">' + city.columns.CityName + '</option>';
                    }
                    $("#city").append(html);
                    form.render('select');
                }
            });

        }

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

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

        }



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

        document.addEventListener('keydown', function (event) {
            if (event.keyCode === 13) {
                //执行相关操作
                $("#searchBtn").click();
            }
        });
    })


    function searchOrder() {
        layer.closeAll()
        //执行重载
        var wherobj = _serializeJson($("#searchForm"));
        tableExt.reload('test', {
            where: wherobj
        });
    }

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

            }
        });
    }

    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 editCustomerEntryFa(id) {
        layer.open({
            type: 2,
            content: "${ctx}/customerEntry/getDqrCustomerEntryForm?entryId=" + id //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
            , area: ['100%', '100%']
            , title: false //不显示标题栏
            , closeBtn: 0
            , shadeClose: true
            /*,shade: 0.8*/
            /*  ,btn: ['确认生成', '取消']*/
            /*,btnAlign: 'c'*/
            /*,scrollbar:false*/
            , cancel: function () {
                searchOrder();
            }
        });
    }

    function editCustomerEntry(id) {
        layer.open({
            type: 2,
            content: "${ctx}/customerEntry/editCustomerEntryForm?entryId=" + id //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
            , title: '信息登记' //不显示标题栏
            ,area: ['100%', '100%']
            , cancel: function () {
                searchOrder();
            }
        });
    }

    function askToContract(id){
        layer.confirm('确认邀请农户签约？', {
            icon:3,
            btn:['确定','取消'] //按钮
        }, function(){
            $.ajax({
                type: 'GET',
                url: '${ctx}/customerEntry/inviteSignQr',
                contentType: 'application/json',
                data: {id:id},
                success: function(data){
                    if (data.code === '200') {
                        layer.msg('操作成功', {time: 2000});
                        searchOrder();
                    }else {
                        layer.msg(data.errMsg, {time: 2500});
                    }
                }
            })
        });
    }

    function deleteEntry(id){
        $.ajax({
            type: 'post',
            url: '${ctx}/customerEntry/batchDelete',
            contentType: 'application/json;charsetset=UTF-8',
            data: JSON.stringify(id),
            success: function(result) {
                if (result.code === '200') {
                    layer.msg('操作成功', {time: 1000}, function() {
                        searchOrder();
                    });
                } else {
                    layer.msg('操作失败！'+result.errMsg);
                }
            }
        })
    }

    function findResult(id, credit) {
        if (credit == '0') {
            layer.msg('请先提交预审',{icon: 5, anim: 6});
            return;
        }
        layer.open({
            type: 2,
            title: '预审查询',
            content: '${ctx}/customerEntryExtra/findResult?id=' + id,
            area: ['650px', '316px'],
            cancel: function () {
                searchOrder(); //数据刷新
            }
        });
    }

    function deleteWarranty(id) {
        var indexla = layer.confirm('您确定要删除项目信息吗？', {
            icon: 3,
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                type: "POST",
                url: "${ctx}/customerEntry/deleteCustomerEntry",
                data: {
                    cusId: id
                },
                success: function (result) {
                    if (result.code == '200') {
                        layer.msg('删除成功！', {icon: 1, time: 1000}, function () {
                            searchOrder();
                        });
                    } else {
                        console.log(result)
                        layer.msg('删除失败!', {icon: 2});
                    }
                },
                error: {}
            })
        }, function () {
            layer.close(indexla);
        });
    }

    function admittance(id) {
        $.ajax({
            type: "POST",
            url: "${ctx}/customerEntry/shoudongCustomerEntry",
            data: {
                id: id
            },
            success: function (result) {
                if (result.code == '200') {
                    layer.msg('准入成功！', {icon: 1, time: 1000}, function () {
                        searchOrder();
                    });
                } else {
                    layer.msg('操作失败！'+result.errMsg, {icon: 2});
                }
            },
            error: {}
        })
    }

    function Prohibit(id) {
        layer.open({
            type: 2,
            content: "${ctx}/customerEntry/toExamineForm?entryId=" + id //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
            , area: ['80%', '88%']
            , title: '审核信息' //不显示标题栏
            , shade: 0.8
            , btnAlign: 'c'
            , scrollbar: false
        });
    }

    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("");
    }
</script>
</body>
</html>

