<%@ 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_DZAZ_T_${partner}" html='<a href="${ctx}/customerEntry/waitInstall/${partner}"><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>
        <form 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">
                        <input type="text" name="powerStationCode" id="powerStationCode" 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="tenantName" id="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-sm3">
                    <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">
                            <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="installFlag" id="installFlag">
                            <option value="">请选择</option>
                            <option value="1">待派工</option>
                            <option value="2">待安装</option>
                            <option value="3">自审驳回</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="mobile" 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="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">
                        <select name="installWay" id="installWay">
                            <option value="">请选择</option>
                            <c:forEach items="${installWays}" var="installWay">
                                <option value="${installWay.columns.id}">${installWay.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">--%>
<%--                        <select name="roofType" id="roofType">--%>
<%--                            <option value="">请选择</option>--%>
<%--                            <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">
                        <select name="plan" id="plan">
                            <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-lg2 layui-col-sm3">
                    <label class="layui-form-label">标记类型：</label>
                    <div class="layui-input-block">
                        <select name="flag" xm-select="flag" xm-select-type="1" xm-select-height="25px"
                                xm-select-show-count="6">
                            <option value="">请选择</option>
                            <option value="0">不标记</option>
                            <c:forEach items="${typeList}" var="flag">
                                <option value="${flag.columns.id}">${flag.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="remarks" id="remarks" class="layui-input">--%>
<%--                    </div>--%>
<%--                </div>--%>
                <div class="layui-col-lg6 layui-col-sm6">
                    <label class="layui-form-label">安装地址：</label>
                    <div class="layui-input-block">
                        <div class="layui-col-lg2 layui-col-sm2 pr-10">
                            <select name="province" id="province"
                                    lay-filter="province" lay-search>
                                <option value="">请选择省</option>
                                <c:forEach items="${pros}" var="pro">
                                    <option value="${pro.columns.ProvinceName}"
                                            title="${pro.columns.ProvinceID }"
                                            <c:if test="${entry.province eq pro.columns.ProvinceName}">selected</c:if>>${pro.columns.ProvinceName}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <div class="layui-col-lg2 layui-col-sm2 pr-10">
                            <select name="city" id="city"  lay-filter="city"
                                    lay-search>
                                <option value="">请选择市</option>

                            </select>
                        </div>
                        <div class="layui-col-lg2 layui-col-sm2 pr-10">
                            <select name="area" id="area"  lay-search>
                                <option value="">请选择县/区</option>

                            </select>
                        </div>
                        <div class="layui-col-lg6 layui-col-sm6">

                            <input type="text" name="address"
                                   autocomplete="off" class="layui-input layui-col-lg2 "
                                   value="${entry.customerAddress}">
                        </div>
                    </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" readonly name="receiveTimeMin" class="layui-input" id="endStartTime"
                                   placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" readonly name="receiveTimeMax" class="layui-input" id="endEndTime"
                                   placeholder="结束日期">
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </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">
                    <sfTags:pagePermission authFlag="XMGL_DZAZ_PLPG_B_${partner}"
                                           html='<button class="layui-btn layui-btn-sm" lay-event="batchDispatch" id="batchDispatch"><i class="layui-icon layui-icon-ok-circle"></i>批量派工</button>'/>
                    <sfTags:pagePermission authFlag="XMGL_DZAZ_PLPG_B_${partner}"
                                           html='<button class="layui-btn layui-btn-sm" lay-event="turnbackDispatch" id="turnbackDispatch"><i class="layui-icon layui-icon-ok-circle"></i>撤销派工</button>'/>
                    <sfTags:pagePermission authFlag="XMGL_DZAZ_SQZG_B_${partner}"
                                           html='<button class="layui-btn layui-btn-sm" lay-event="modify" id="modify"><i class="layui-icon layui-icon-ok-circle"></i>申请整改</button>'/>
                    <c:if test="${user.id eq '1' }">
                        <button class="layui-btn layui-btn-sm" lay-event="backTKBtn" id="backTKBtn"><i class="layui-icon layui-icon-ok-circle"></i>退回勘测</button>
                    </c:if>
                    <sfTags:pagePermission authFlag="XMGL_DZAZ_DC_B_${partner}"
                                           html='<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>

    var entrycount = 0;
    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 wgBtn = '${fns:checkPagePermission(request, wgBtnPermission)}';//完工

        //开始日期
        var endStartTime = laydate.render({
            elem: '#endStartTime'
            /* ,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: '#endEndTime'
            /* ,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=4&partner='+'${partner}',
            method:"post",
            cols: [[
                {type: 'numbers', fixed: 'left', title: '序号'}
                , {field: 'id', minWidth: '4%', checkbox: true, align: 'center', rowspan: '2', fixed: 'left'}
                , {field: 'id', minWidth: 100, title: '操作', align: 'center', rowspan: '2', fixed: 'left',
                    templet: function (d) {
                        var html = "";

                        if (wgBtn === '0'){
                            if (d.install_flag ==='2' || d.install_flag ==='3' ){
                                html += '<a href="#" class="layui-table-link" onclick="completeInstall(\'' + d.id + '\')">完工</a>';
                            }
                        }
                        if(!isBlank(html)){
                            return html;
                        }else {
                            return "--";
                        }
                    }
                }
                , {
                    field: 'power_station_code',
                    title: '电站编码',
                    minWidth: 200,
                    sort: false,
                    align: 'center',
                    fixed: 'left',
                    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: 150, align: 'center', exportable: true}
                , {
                    field: 'install_flag', title: '电站状态', minWidth: 150, align: 'center', exportable: true
                    , templet: function (d) {
                        //1.待派工 2.待安装 3.自审驳回 4.安装完成
                        if(d.install_flag=='1'){
                            return '待派工';
                        }else if(d.install_flag=='2'){
                            return '待安装';
                        }else if(d.install_flag=='3'){
                            return '自审驳回';
                        }else if(d.install_flag=='4'){
                            return '安装完成';
                        }
                        return '-';
                    }
                    , expFormat: function (d) {
                        if(d.install_flag=='1'){
                            return '待派工';
                        }else if(d.install_flag=='2'){
                            return '待安装';
                        }else if(d.install_flag=='3'){
                            return '自审驳回';
                        }else if(d.install_flag=='4'){
                            return '安装完成';
                        }
                        return '-';
                    }
                }
          /*      , {field: 'next_apply_status', title: '进件状态', minWidth: 130, align: 'center', exportable: true
                    , templet:function(d){
                        return applyStatusStr(d.apply_status);
                    }
                    , expFormat: function(d){
                        return applyStatusStr(d.apply_status);
                    }
                }*/
                , {field: 'apply_back_reason',title: '进件退回原因',minWidth: 200,sort: false,align: 'center',exportable: true}
                // , {
                //     field: 'scheme_type', title: '设计方案', minWidth: 150, align: 'center', exportable: true
                //     , templet: function (d) {
                //         if (d.scheme_type === '1') {
                //             return '标准方案';
                //         } else {
                //             return '组合方案';
                //         }
                //     }
                //     , expFormat: function (d) {
                //         if (d.scheme_type === '1') {
                //             return '标准方案';
                //         } else {
                //             return '组合方案';
                //         }
                //     }
                // }
                , {field: 'scheme_type_name', title: '方案类型', minWidth: 150, align: 'center', exportable: true}
                , {field: 'planName', title: '方案名称', minWidth: 150, align: 'center', exportable: true}
                , {
                    field: 'province',
                    title: '项目名称',
                    minWidth: '180',
                    sort: false,
                    align: 'center',
                    exportable: true,
                    templet: function (d) {
                        return d.province + '' + d.area + d.tenant_name + d.design_capacity / 1000 + "KW光伏电站";
                    },
                    expFormat: function (d) {
                        return d.province + '' + d.area + d.tenant_name + d.design_capacity / 1000 + "KW光伏电站";
                    }
                }
                , {field: 'remarks', title: '备注', minWidth: 150, align: 'center', exportable: true}
                , {field: 'projectCode', title: '产品编号', minWidth: 130, align: 'center', exportable: true}
                , {field: 'projectName', title: '产品名称', minWidth: 130, align: 'center', exportable: true}
                <c:if test="${user.userType ne '6' && user.userType ne '7'}">
                , {field: 'traderName', title: '代理商名称', minWidth: 150, align: 'center', exportable: true}
                , {field: 'traderMobile', title: '代理商电话', minWidth: 120, 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: 'mobile', title: '联系方式', minWidth: 120, align: 'center', exportable: true}
                , {field: 'id_code', title: '身份证号', minWidth: 160, align: 'center', exportable: true}
                , {field: 'roof_type', title: '屋顶类型', minWidth: 100, align: 'center', exportable: true}
                , {field: 'address', title: '安装地址', minWidth: 180, align: 'center', exportable: true}
                , {field: 'distance', title: '并网距离（米）', minWidth: 130, align: 'center', exportable: true}
                , {
                    field: 'azimuth', title: '方位角', minWidth: 100, align: 'center', exportable: true,
                    templet: function (d) {
                        if (d.patnerId == '03'){
                            if (d.azimuth === '1') {
                                return '正西';
                            } else if (d.azimuth === '2') {
                                return '东偏南';
                            } else if (d.azimuth === '3') {
                                return '南偏西';
                            } else if (d.azimuth === '4') {
                                return '北偏西';
                            } else if (d.azimuth === '5') {
                                return '西偏南';
                            } else if (d.azimuth === '6') {
                                return '东偏北';
                            } else if (d.azimuth === '7') {
                                return '北偏东';
                            } else if (d.azimuth === '8') {
                                return '西偏北';
                            } else if (d.azimuth === '9') {
                                return '南偏东';
                            } else if (d.azimuth === '10') {
                                return '正南';
                            } else if (d.azimuth === '11') {
                                return '正北';
                            } else if (d.azimuth === '12') {
                                return '正东';
                            }else {
                                return "";
                            }
                        }else {
                            if (d.azimuth === '1') {
                                return '正南';
                            } else if (d.azimuth === '2') {
                                return '南偏东' + d.angle + '度';
                            } else if (d.azimuth === '3') {
                                return '南偏西' + d.angle + '度';
                            }else {
                                return "";
                            }
                        }
                    },
                    expFormat: function (d) {
                        if (d.patnerId == '03'){
                            if (d.azimuth === '1') {
                                return '正西';
                            } else if (d.azimuth === '2') {
                                return '东偏南';
                            } else if (d.azimuth === '3') {
                                return '南偏西';
                            } else if (d.azimuth === '4') {
                                return '北偏西';
                            } else if (d.azimuth === '5') {
                                return '西偏南';
                            } else if (d.azimuth === '6') {
                                return '东偏北';
                            } else if (d.azimuth === '7') {
                                return '北偏东';
                            } else if (d.azimuth === '8') {
                                return '西偏北';
                            } else if (d.azimuth === '9') {
                                return '南偏东';
                            } else if (d.azimuth === '10') {
                                return '正南';
                            } else if (d.azimuth === '11') {
                                return '正北';
                            } else if (d.azimuth === '12') {
                                return '正东';
                            }else {
                                return "";
                            }
                        }else {
                            if (d.azimuth === '1') {
                                return '正南';
                            } else if (d.azimuth === '2') {
                                return '南偏东' + d.angle + '度';
                            } else if (d.azimuth === '3') {
                                return '南偏西' + d.angle + '度';
                            }else {
                                return "";
                            }
                        }
                    }
                }
                , {field: 'building_height', title: '建筑高度（米）', minWidth: 130, align: 'center', exportable: true}
                , {
                    field: 'shoot_type', title: '拍摄方式', minWidth: 100, align: 'center', exportable: true
                    , templet: function (d) {
                        if (d.shoot_type === '1') {
                            return '无人机拍摄';
                        } else {
                            return '手机拍摄';
                        }
                    }
                    , expFormat: function (d) {
                        if (d.shoot_type === '1') {
                            return '无人机拍摄';
                        } else {
                            return '手机拍摄';
                        }
                    }
                }
                , {
                    field: 'repayment_method', title: '划转方式', minWidth: 100, align: 'center', exportable: true
                    , templet: function (d) {
                        if (d.repayment_method === '2') {
                            return '光E宝';
                        } else if(d.repayment_method === '1') {
                            return '二类卡';
                        }else if(d.repayment_method === '0'){
                            return "其它"
                        }
                    }
                    , expFormat: function (d) {
                        if (d.repayment_method === '2') {
                            return '光E宝';
                        }else if(d.repayment_method === '1') {
                            return '二类卡';
                        }else if(d.repayment_method === '0'){
                            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, align: 'center', exportable: true}
                , {field: 'examine_time', title: '提交时间', minWidth: 180, align: 'center', exportable: true}
                , {
                    field: 'receive_time',
                    title: '收货时间',
                    minWidth: 180,
                    sort: false,
                    align: 'center',
                    exportable: true
                }
                , {
                    field: 'examine_remarks',
                    title: '备注',
                    minWidth: 180,
                    sort: false,
                    align: 'center',
                    exportable: true
                }
                , {
                    field: 'examine_time',
                    title: '审核时间',
                    minWidth: 180,
                    sort: false,
                    align: 'center',
                    exportable: true
                }
            ]]
            ,
            exportOpt: {                           //导出选项配置
                ele: '#exportBtn',                   //导出的Dom元素
                headerTitle: '电站安装',             //excel表格的标题
                pageData: false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '电站安装',
                where: function () {                 //当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
            ,
            done: function (res, curr, count) {
                //得到数据总量

                entrycount = count;
            }
        });

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

        }

        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 === 'complete') {
                if (checkStatus.data.length < 1) {
                    layer.msg("请先选择数据", {icon: 5, anim: 6});
                    return;
                }
                var checkpro = false;
                var ids = [];
                for (var i = 0; i < checkStatus.data.length; i++) {
                    ids.push(checkStatus.data[i].id);
                    /*  if(_checkProjectCode(checkStatus.data[i].projectCode)){
                          checkpro = true;
                          layer.msg("选择的数据中含有不可操作的项目信息",{icon:5,anim:6});
                          return;
                      }*/
                }
                if (checkpro) {
                    layer.msg("选择的数据中含有不可操作的项目信息", {icon: 5, anim: 6});
                    return;
                }
                layer.confirm('确认安装完成吗？', {
                    icon: 3,
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    $.ajax({
                        type: 'post',
                        url: '${ctx}/customerEntry/batchInstall',
                        contentType: 'application/json',
                        data: JSON.stringify(ids),
                        success: function (data) {
                            if (data.code === '200') {
                                layer.msg('操作成功', {time: 1000});
                                searchOrder();
                            } else if (data.code === '501') {
                                layer.msg(data.errMsg, {time: 1000});
                            } else {
                                layer.msg('操作失败', {time: 1000});
                            }
                        }
                    })
                });
            } else if (obj.event === 'batchDispatch') {
                if (checkStatus.data.length < 1) {
                    layer.msg("请先选择数据", {icon: 5, anim: 6});
                    return;
                }
                var ids = [];
                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);
                }
                layer.open({
                    type: 2,
                    content: "${ctx}/customerEntry/toBatchDispatchPage?entryIds=" + ids.join(',')
                    , title: "批量派工"
                    , area: ["60%", "80%"]
                    , success: function (layero) {

                    }
                });


            } else if (obj.event === 'turnbackDispatch') {
                if (checkStatus.data.length < 1) {
                    layer.msg("请先选择数据", {icon: 5, anim: 6});
                    return;
                }
                var ids = [];
                for (var i = 0; i < checkStatus.data.length; i++) {
                    if(checkStatus.data[i].dispatch_status != '1'){
                        layer.msg("选择的数据中含有未派工的数据",{icon:5,anim:6});
                        return;
                    }
                    <%--if(checkStatus.data[i].create_trader_id != '${user.traderId}'){--%>
                    <%--    layer.msg("第"+(i+1)+"条数据,没有撤销派工权限!",{icon:5,anim:6});--%>
                    <%--    return;--%>
                    <%--}--%>
                    ids.push(checkStatus.data[i].id);
                }

                layer.confirm('确认撤销派工吗？', {
                    icon: 3,
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    $.ajax({
                        type: 'post',
                        url: '${ctx}/customerEntry/turnbackDispatch',
                        data: {ids:ids.join(',')},
                        success: function (data) {
                            if (data.code === '200') {
                                layer.msg('操作成功', {time: 1000});
                                searchOrder();
                            } else if (data.code === '501') {
                                layer.msg(data.errMsg, {time: 1000});
                            } else {
                                layer.msg('操作失败', {time: 1000});
                            }
                        }
                    })
                });


            } else if (obj.event === 'modify') {
                if (checkStatus.data.length < 1) {
                    layer.msg("请先选择数据", {icon: 5, anim: 6});
                    return;
                }
                var ids = [];
                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);
                }
                layer.open({
                    type: 2,
                    content: "${ctx}/customerEntry/applyChangeDetail?ids=" + ids
                    , title: "申请整改"
                    , area: ["50%", "60%"]
                });
            }else if (obj.event === 'backTKBtn') {//退回待踏勘
                if (checkStatus.data.length < 1) {
                    layer.msg("请先选择数据", {icon: 5, anim: 6});
                    return;
                }
                if (checkStatus.data.length > 1) {
                    layer.msg("只能选择数据一条数据", {icon: 5, anim: 6});
                    return;
                }
                var id =checkStatus.data[0].id;
                var index= layer.load(2, {shade: [0.5,'#fff'], content:''});
                $.ajax({
                    type: 'post',
                    url: '${ctx}/customerEntry/azReturnToSurvey',
                    data: {
                        id: id
                    },
                    success: function (result) {
                        layer.close(index);
                        if (result.code === '200') {
                            layer.msg('操作成功！', {time: 1000}, function(){
                                searchOrder();
                            })
                        } else {
                            layer.msg('操作失败!'+result.errMsg)
                        }
                    },complete:function (){
                        layer.close(index);
                    }
                });
            }
        });

        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
                }
            });
        });

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

    function downloadAttach(scheme_id) {
        /* attach=decodeURI(attach);
         attach = attach.replace(/\+/g,"%2B"); //*/
        $.ajax({
            type: 'post',
            url: '${ctx}/customerEntry/getPlanBySchemeId',
            data: {schemeId: scheme_id},
            success: function (data) {
                console.log(data)
                if (data != null) {
                    var attach = decodeURI(data.attach);
                    attach = attach.replace(/\+/g, "%2B");
                    window.location.href = '${commonStaticImgPaths}/' + attach;
                }

            }
        })


    }

    function downloadMaterial(id) {
        window.location.href = '${ctx}/customerEntry/exportsMaterial?id=' + id;
    }

    function searchOrder() {
        layer.closeAll()
        //执行重载
        table.reload('test', {
            where: function () {
                return _serializeJson($("#searchForm"));
            }, page: {
                curr: 1
            }, done: function (res, curr, count) {
                entrycount = count;
                console.log("zongshu ::" +
                    "" + entrycount)
            }
        });
        table.render();
        return false;
    }

    //查看详情
    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 planDetail(entryId) {
        layer.open({
            type: 2,
            title: '查看',
            content: '${ctx}/planManage/viewMatchedPlan?entryId=' + entryId,
            area: ['80%', '80%']
        });
    }

    function completeInstall(entryId){
        layer.open({
            type: 2,
            title: '完工',
            content: '${ctx}/customerEntry/toCompleteInstallPage?id=' + entryId,
            area: ['100%', '100%']
        });
    }

    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  applyStatusStr(applyStatus){
        if(applyStatus == '0'){
            return "待预审";
        }else if(applyStatus == '1'){
            return "预审中";
        }else if(applyStatus == '2'){
            return "预审成功";
        }else if(applyStatus == '3'){
            return "预审驳回";
        }else if(applyStatus == '4'){
            return "待进件";
        }else if(applyStatus == '5'){
            return "进件审核中";
        }else if(applyStatus == '6'){
            return "进件审核成功";
        }else if(applyStatus == '7'){
            return "进件审核驳回";
        }else if(applyStatus == '8'){
            return "合同待签约";
        }else if(applyStatus == '9'){
            return "合同已签约";
        }else if(applyStatus == '10'){
            return "合同审核中";
        }else if(applyStatus == '11'){
            return "合同签约驳回";
        }else if(applyStatus == '12'){
            return "合同已审核";
        }else if(applyStatus == '13'){
            return "待提交完工资料";
        }else if(applyStatus == '14'){
            return "完工资料审核中";
        }else if(applyStatus == '15'){
            return "完工资料审核通过";
        }else if(applyStatus == '16'){
            return "完工资料审核驳回";
        }else if(applyStatus == '17'){
            return "待提交并网资料";
        }else if(applyStatus == '18'){
            return "并网资料已提交";
        }else {
            return "";
        }
    }
</script>
</body>
</html>

