i<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <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" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
    <style>
        .layui-form-select dl {
            max-height: 150px;
        }
    </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="SXGL_XMSX_DSH_T"
                                       html='<li class="layui-this"><a href="${ctx}/itemManagement/proj/waitDealItemPage">待审核</a></li>'/>
                <sfTags:pagePermission authFlag="SXGL_XMSX_DFP_T"
                                       html='<li class=""><a href="${ctx}/itemManagement/proj/waitDispatchItemPage">待分配</a></li>'/>
                <sfTags:pagePermission authFlag="SXGL_XMSX_YSH_T"
                                       html='<li class=""><a href="${ctx}/itemManagement/proj/endAuditItemPage">已审核</a></li>'/>
                <sfTags:pagePermission authFlag="SXGL_XMSX_SDSZ_T"
                                       html='<li><a href="${ctx}/itemManagement/proj/auditSettingPage">审单设置</a></li>'/>
                <sfTags:pagePermission authFlag="SXGL_XMSX_YXSDSZ_T"
                                       html='<li class=""><a href="${ctx}/itemManagement/proj/priorAuditSettingPage">优先审单设置</a></li>'/>
<%--                <ul class="layui-tab-title">--%>
<%--                    <li class="layui-this">待处理</li>--%>
<%--                    <li>已处理</li>--%>
<%--                </ul>--%>
                <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-md2 layui-col-sm2">
                    <label class="layui-form-label">申请类型：</label>
                    <div class="layui-input-block">
                        <select name="formKey">
                            <option value="">请选择</option>
                            <option value="91">设计审核</option>
                            <option value="92">档案审核</option>
                            <option value="93">安装验收</option>
                            <option value="94">并网验收</option>
                            <option value="95">勘测信息变更</option>
                            <option value="96">完工信息变更</option>
                            <option value="97">设计信息变更</option>
                            <option value="98">客户信息变更</option>
                            <option value="99">物料信息变更</option>
                            <option value="100">并网信息变更</option>
                        </select>
                    </div>
                </div>

                <div class="layui-col-md2 layui-col-sm2">
                    <label class="layui-form-label">资方：</label>
                    <div class="layui-input-block" >
                        <select name="partnerId" lay-search>
                            <option value="">请选择</option>
                            <c:forEach items="${partnerList}" var="partner">
                                <option value="${partner.columns.id}">${partner.columns.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="layui-col-md2 layui-col-sm2">
                    <label class="layui-form-label">代理商名称：</label>
                    <div class="layui-input-block" >
                        <select name="traderId" lay-search>
                            <option value="">请选择</option>
                            <c:forEach items="${traderList}" var="trader">
                                <option value="${trader.columns.id}">${trader.columns.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="layui-col-md2 layui-col-sm2">
                    <label class="layui-form-label">审核人员：</label>
                    <div class="layui-input-block" >
                        <select name="employeeUserId" lay-search>
                            <option value="">请选择</option>
                            <c:forEach items="${reviewMembers}" var="member">
                                <option value="${member.columns.user_id}">${member.columns.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="layui-col-md2 layui-col-sm2">
                    <label class="layui-form-label">电站编号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="entryNo" class="layui-input" id="entryNo">
                    </div>
                </div>

                <div class="layui-col-md2 layui-col-sm2">
                    <label class="layui-form-label">业主姓名：</label>
                    <div class="layui-input-block">
                        <input type="text" name="tenantName" class="layui-input" id="tenantName">
                    </div>
                </div>
<%--                <div class="layui-col-md2 layui-col-sm2">--%>
<%--                    <label class="layui-form-label">流程标题：</label>--%>
<%--                    <div class="layui-input-block">--%>
<%--                        <input type="text" name="name" class="layui-input" id="name">--%>
<%--                    </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="pro">
                                <option value="${pro.columns.ProvinceName}"  title="${pro.columns.ProvinceID}">${pro.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>

                <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="createTimeSta" id="createTimeSta" class="layui-input"  placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="createTimeEnd" id="createTimeEnd" class="layui-input"  placeholder="结束日期">
                        </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" name="dispatchTimeSta" id="dispatchTimeSta" class="layui-input"  placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="dispatchTimeEnd" id="dispatchTimeEnd" class="layui-input"  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">
                <c:if test="${isLeader}">
                <sfTags:pagePermission authFlag='SXGL_XMSX_DSH_ZP_B' html='<button class="layui-btn layui-btn-sm" lay-event="redispatch" id="redispatch" onclick="showDispatchForm()">转派</button>'/>
                </c:if>
                <c:if test="${signStatus.needSign}">
                <sfTags:pagePermission authFlag='SXGL_XMSX_DSH_QD_B' html='<button class="layui-btn layui-btn-sm ${signStatus.signinEnable? "":"layui-btn-disabled"}" ${signStatus.signinEnable? "":"disabled"}  lay-event="signin" id="signinBtn" onclick="signinBtn()">签到</button>'/>
                </c:if>
                <c:if test="${signStatus.needSign}">
                <sfTags:pagePermission authFlag='SXGL_XMSX_DSH_QT_B' html='<button class="layui-btn layui-btn-sm ${not signStatus.signinEnable? "":"layui-btn-disabled"}" ${not signStatus.signinEnable? "":"disabled"} lay-event="signout" id="signoutBtn" onclick="signoutBtn()">签退</button>'/>
                </c:if>
                <sfTags:pagePermission authFlag="SXGL_XMSX_DSH_DC_B" html='<button class="layui-btn layui-btn-sm" lay-event="exportBtn" id="exportBtn"><i class="layui-icon"></i>导出</button>'/>
<%--                <c:if test="${userType ne '6' && userType ne '7'}">--%>
<%--                </c:if>--%>
<%--                <c:if test="${userType eq '6' || userType eq '7'}">--%>
<%--                </c:if>--%>
            </script>
        </div>
    </div>
</div>

<!-- 弹窗 -->
<div class="hide" id="redispatchWin" style="position: relative;height:100%;overflow: hidden;">
    <form class="layui-form mt-20" action="" lay-filter="demo-val-filter">
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="mark">*</span>审单组：</label>
            <div class="layui-input-inline">
                <input type="text" name="groupName" id="groupName" placeholder="请输入" autocomplete="off" class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="mark">*</span>审核人：</label>
            <div class="layui-input-inline">
                <select name="members" lay-filter="members" lay-search id="members">
                    <option value=""></option>
                    <c:forEach items="${members}" var="item">
                        <option value="${item.columns.id}">${item.columns.name}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
        <input type="hidden" name="itemIds" id="itemIds">
    </form>

    <div class="layui-form-item text-c operate-footer" style="position: absolute;">
        <button type="button" class="layui-btn" id="save" onclick="save()">提交</button>
        <button class="layui-btn layui-btn-primary" onclick="closeSelf()">取消</button>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/data.js"></script>
<script type="text/javascript">
    var saveMark = false;
    //初始数据
    var $form;
    var form;
    var upload;
    var $;
    var table;
    var laydate;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form','excel'], function(){
        $ = layui.$
            ,form = layui.form
            ,tableExt = layui.tableExt;
        laydate = layui.laydate;
        table = layui.table;

        //开始日期
        var insStart = laydate.render({
            elem: '#createTimeSta'
            ,type: 'date'
            ,done: function(value, date){
                //更新结束日期的最小日期
                insEnd.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                insEnd.config.elem[0].focus();
            }
        });
        //结束日期
        var insEnd = laydate.render({
            elem: '#createTimeEnd'
            ,type: 'date'
            ,done: function(value, date){
                //更新开始日期的最大日期
                insStart.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });
        var pdStart = laydate.render({
            elem: '#dispatchTimeSta'
            ,type: 'date'
            ,done: function(value, date){
                //更新结束日期的最小日期
                pdEnd.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                pdEnd.config.elem[0].focus();
            }
        });
        //结束日期
        var pdEnd = laydate.render({
            elem: '#dispatchTimeEnd'
            ,type: 'date'
            ,done: function(value, date){
                //更新开始日期的最大日期
                pdStart.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        function formatApplyType (d) {
            if (d.formKey === '01') {
                return '代理商准入申请';
            }else if(d.formKey ==='02'){
                return '供应商准入申请';
            }else if(d.formKey ==='03'){
                return '保证金调整申请';
            }/*else if(d.formKey ==='04'){
                            return '授信额调整申请';
                        }*/else if(d.formKey ==='05'){
                return '质保金调整申请';
            }else if(d.formKey ==='06'){
                return '分包标准价申请';
            }else if(d.formKey ==='07'){
                return '结算额调整申请';
            }else if(d.formKey ==='08'){
                return '赊销下单申请';
            }else if(d.formKey ==='09'){
                return '采购申请';
            }else if(d.formKey ==='10'){
                return '盘点单申请';
            }else if(d.formKey ==='11'){
                return '调拨单申请';
            }else if(d.formKey ==='12'){
                return '请款申请';
            }else if(d.formKey ==='13'){
                return '仓库申请';
            }else if(d.formKey ==='14'){
                return '零售价系数申请';
            }else if(d.formKey ==='15'){
                return '备货申请';
            }else if(d.formKey ==='16'){
                return '支架账户申请';
            }else if(d.formKey ==='17'){
                return '现金下单申请';
            }else if(d.formKey ==='18'){
                return '保证金额度申请';
            }else if(d.formKey ==='91'){
                return '设计审核';
            }else if(d.formKey ==='92'){
                return '档案审核';
            }else if(d.formKey ==='93'){
                return '安装验收';
            }else if(d.formKey ==='94'){
                return '并网验收';
            }else if(d.formKey ==='95'){
                return '勘测信息变更';
            }else if(d.formKey ==='96'){
                return '完工信息变更';
            }else if(d.formKey ==='97'){
                return '设计信息变更';
            }else if(d.formKey ==='98'){
                return '客户信息变更';
            }else if(d.formKey ==='99'){
                return '物料信息变更';
            }else if(d.formKey ==='100'){
                return '并网信息变更';
            }
        }
       /* var toExamine_sj = '${fns:checkPagePermission(request, "XMGL_XMGL_DSHXX_SH_B")}';
        var ptysBtn_az = '${fns:checkPagePermission(request, "XMGL_AZYS_AZYS_YS")}';
        var examine_bw= '${fns:checkPagePermission(request, "XMGL_BWYS_BWYS_YS")}';*/
        tableExt.render({
            elem: '#test'
            , height: 'full-190'
            , id: 'test'
            , defaultToolbar: false
            , url: '${ctx}/itemManagement/proj/waiteDealItemList'
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , page: true
            , toolbar:"#toolbarDemo"
            , method:"post"
            , limits: [20, 50, 100]
            , limit: 20
            , cols: [[
                {field: 'number', minWidth: 50, title: '序号', align: 'center', type: 'numbers', fixed: 'left'}
                ,{field:'id', type: 'checkbox', fixed: 'left', title: '选择'}
                , {field: 'id', title: '操作', minWidth : 100, align: 'center', fixed: 'left', templet:function(d){
                    if (d.assign_audit_user_id === '${userId}') {
                        if (d.formKey == '91') {
                            return '<a class="layui-table-opt-link" lay-event="audit_entry">审核</a>';  // 设计审核
                        } else if (d.formKey == '92') {
                            return '<a class="layui-table-opt-link" lay-event="audit_entry">审核</a>';  // 档案审核
                        } else if (d.formKey == '93') {
                            return '<a class="layui-table-opt-link" lay-event="audit_entry">审核</a>';   //安装验收
                        } else if (d.formKey == '94') {
                            return '<a class="layui-table-opt-link" lay-event="audit_entry">审核</a>';   //并网验收
                        } else if (d.formKey == '95' || d.formKey == '96' || d.formKey == '97' || d.formKey == '98' || d.formKey == '99' || d.formKey == '100') {
                            return '<a class="layui-table-opt-link" lay-event="audit_entry">审核</a>';   //变更申请
                        }
                    }
                        return '--';
                    }
                }
                , {field: 'assignee', title: '审核人', minWidth: 150, align: 'center',exportable:true }
                , {field: 'name', title: '流程标题', minWidth: 600, align: 'center',exportable:true}
                ,{field: 'formKey', title: '申请类型', minWidth: 130, align: 'center', exportable:true,
                    templet: formatApplyType,
                    expFormat: formatApplyType
                }
                , {field: 'partnerName', title: '资方', minWidth: 200, align: 'center',exportable:true }
                , {field: 'tenantName', title: '业主姓名', minWidth: 80, align: 'center',exportable:true }
                , {field: 'power_station_code', title: '电站编码', minWidth: 150, align: 'center',exportable:true }
                , {field: 'province', title: '安装地址-省', minWidth: 120, align: 'center',exportable:true }
                , {field: 'city', title: '安装地址-市', minWidth: 120, align: 'center',exportable:true }
                , {field: 'area', title: '安装地址-区/县', minWidth: 130, align: 'center',exportable:true }
                , {field: 'createName', title: '申请人', minWidth: 300, align: 'center',exportable:true }
                , {field: 'createTime', title: '发起时间', minWidth: 200, align: 'center',exportable:true }
                , {field: 'assignTime', title: '派单时间', minWidth: 200, align: 'center',exportable:true }
            ],
            ]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '待审核',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 10000,                    //当pageData为false生效
                fileName: '待审核',
                where: function (){
                    return _serializeJson($("#searchForm"));
                }
            }
        });

        $('input').on('keydown', function(event){
            if(event.keyCode == 13){
                //执行相关操作
                console.log($('#name').val().trim())
                $("#searchBtn").click();
            }
        });


        <%--$("#redispatch").click(function() {--%>
        <%--    layer.open({--%>
        <%--        type: 2,--%>
        <%--        title: '转派',--%>
        <%--        content: '${ctx}/taskdispatch/crmReviewGroupMember/redispatchPage',--%>
        <%--        area: ['50%','70%']--%>
        <%--    });--%>
        <%--});--%>

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

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

        var active = {
            reload: function(){
                reload();
            }
        };

        $(".layui-tab-title li").click(function () {
            // 切换对应的标签页内容
            var index = $(this).index();
            $('.layui-tab-item').eq(index).addClass('layui-show').siblings('.layui-tab-item').removeClass('layui-show');

            // 将当前点击的标签设为活动状态
            $(this).addClass("layui-this").siblings().removeClass("layui-this");

            // 切换 box1 和 box2 的状态
            if (index === 0) {
                $('.box1').addClass('layui-show');
                $('.box2').removeClass('layui-show');
            } else {
                $('.box1').removeClass('layui-show');
                $('.box2').addClass('layui-show');
            }
        });


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

        }



        table.on('tool(test)',function(obj){
             var data=obj.data;
             var applicationId=data.application_id;
             var formKey=data.formKey;
            if(obj.event === 'audit'){
                if(formKey =='01'){  //代理商准入申请
                    layer.open({type: 2,
                        title: '审批',
                        content: '${ctx}/flowpath/traderApply/traderApplyDetail?from=audit&id='+applicationId,
                        area: ['90%', '90%'],
                        end: function(){
                            searchOrder();
                        }
                    });
                }else if(formKey =='02'){  //供应商准入申请
                    layer.open({type: 2,
                        title: '审批',
                        content: '${ctx}/flowpath/supplySupplierApply/supplierApplyDetail?from=audit&id='+applicationId,
                        area: ['80%', '90%'],
                        end: function(){
                            searchOrder();
                        }
                    });
                }else if(formKey =='03'){  //保证金调整申请
                    layer.open({
                        title:'审批',
                        type: 2,
                        area: ["70%", "80%"],
                        content: '${ctx}/apply/bondAdjustment/bondAdjustmentApplyDetail?id='+applicationId+'&from=audit',
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='04'){   //授信额调整申请
                    layer.open({
                        title:'审批',
                        type: 2,
                        area: ["70%", "80%"],
                        content: '${ctx}/apply/distributionGoods/ApplyDistributionGoods?id='+applicationId+'&from=audit',
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='05'){   //质保金调整申请
                    layer.open({
                        title:'审批',
                        type: 2,
                        area: ["70%", "80%"],
                        content: '${ctx}/apply/warrantyDeposit/applyWarrantyDeposit?id='+applicationId+'&from=audit',
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='06'){   //分包标准价申请
                    layer.open({
                        title:'审批',
                        type: 2,
                        area: ["70%", "80%"],
                        content: '${ctx}/apply/standardPrice/standardPriceApplyDetailPage?id='+applicationId+'&from=audit',
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='07'){   //结算额调整申请
                    layer.open({
                        title:'审批',
                        type: 2,
                        area: ["70%", "80%"],
                        content: '${ctx}/apply/settlementAmount/settlementAmountApplyDetail?id='+applicationId+'&from=audit',
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='08'){  //赊销下单申请
                    layer.open({
                        title:'审批',
                        type: 2,
                        area: ['100%', '100%'],
                        content: '${ctx}/material/order/supplyMaterialOrderAudit?id='+applicationId+'&from=audit',
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='09'){   //采购申请
                    layer.open({
                        type: 2,
                        title: '审批',
                        content: '${ctx}/supplyOrder/purchaseAudit/auditPurchaseOrderPage?id=' + applicationId+'&from=audit',
                        area: ['80%', '90%'],
                        end: function(){
                            searchOrder();
                        }
                    });
                }else if(formKey =='10'){   //盘点单申请
                    layer.open({
                        type: 2,
                        title: '审批',
                        content: '${ctx}/inventory/toInventoryOrderDetailForm?mode=audit&id=' + applicationId+'&from=audit',
                        area: ['80%', '80%'],
                        end: function(){
                            searchOrder();
                        }
                    });
                }else if(formKey =='11'){    //调拨单申请
                    layer.open({
                        title:'审批',
                        type: 2,
                        area: ['80%', '75%'],
                        fixed: false,
                        content: '${ctx}/allocation/examineAllocationOrderPage?model=audit&id='+applicationId,
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='12'){    //请款申请
                    layer.open({
                        title:'审批',
                        type: 2,
                        area: ["100%", "100%"],
                        content: '${ctx}/apply/outCash/cashOutDetailPage?id='+applicationId+'&from=audit',
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='13'){    //仓库申请
                    layer.open({
                        title:'审批',
                        type: 2,
                        area: ["70%", "80%"],
                        content: '${ctx}/apply/warehouseApply/warehouseApplyDetail?id='+applicationId+'&from=audit',
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='14'){    //零售价系数申请
                    layer.open({
                        title:'审批',
                        type: 2,
                        area: ["80%", "80%"],
                        content: '${ctx}/apply/priceCoefficient/priceCoefficientApplyDetail?id='+applicationId+'&from=audit',
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='15'){   //备货申请
                    layer.open({
                        type: 2,
                        title: '审批',
                        content: '${ctx}/fittingStockUp/fittingStockUpDetailPage?id=' + applicationId+'&from=audit',
                        area: ['80%', '90%'],
                        end: function(){
                        searchOrder();
                    },
                    });
                }else if(formKey =='17'){   //现金下单申请
                    layer.open({
                        title:'审批',
                        type: 2,
                        area: ['100%', '100%'],
                        content: '${ctx}/material/order/supplyMaterialOrderAudit?id='+applicationId+'&from=audit&formKey=17',
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='18'){    //保证金额度申请
                    layer.open({
                        title:'审批',
                        type: 2,
                        area: ["70%", "80%"],
                        content: '${ctx}/apply/bondLimitApply/bondLimitApplyDetail?id='+applicationId+'&from=audit',
                        end: function(){
                            searchOrder();
                        }
                    })
                }
            }else if(obj.event ==='audit_entry'){
                if(formKey=='91' || formKey =='92' || formKey =='93' || formKey =='94' || formKey =='95' || formKey =='96' || formKey =='97' || formKey =='98' || formKey =='99' || formKey =='100'){
                    layer.open({
                        type: 2,
                        content: ['${ctx}/priorReviewSetting/examineMainTab?id='+data.id, 'no'] //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                        ,area: ['100%', '100%']
                        ,title: '审核信息', //不显示标题栏
                        scrollbar: false,// 关闭滚动条
                        end: function(){
                            searchOrder();
                        }
                    });
                }
                <%--if(formKey=='91'){   //设计审核--%>
                <%--    layer.open({--%>
                <%--        type: 2,--%>
                <%--        content: "${ctx}/customerEntry/toExamineForm?type=2&entryId="+applicationId //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响--%>
                <%--        ,area: ['100%', '100%']--%>
                <%--        ,title: '审核信息', //不显示标题栏--%>
                <%--        end: function(){--%>
                <%--            searchOrder();--%>
                <%--        }--%>
                <%--    });--%>
                <%--}else if(formKey =='92'){   //档案审核--%>
                <%--    layer.open({--%>
                <%--        type: 2,--%>
                <%--        content: "${ctx}/customer/org/files/toFileReviewForm?entryId="+applicationId,--%>
                <%--        area: ['100%', '100%'],--%>
                <%--        title: '档案审核'--%>
                <%--    });--%>
                <%--}else if(formKey =='93'){   //安装验收--%>
                <%--    layer.open({--%>
                <%--        type: 2,--%>
                <%--        title: '验收',--%>
                <%--        content: '${ctx}/customerEntry/toCheckAccept?id=' + applicationId,--%>
                <%--        area: ['100%','100%'],--%>
                <%--        end: function(){--%>
                <%--            searchOrder();--%>
                <%--        }--%>
                <%--    });--%>
                <%--}else if(formKey =='94'){   //并网验收--%>
                <%--    //验收--%>
                <%--    layer.open({--%>
                <%--        type: 2,--%>
                <%--        title: '验收报告',--%>
                <%--        content: '${ctx}/customerEntry/toMergeAccept?opt=TwoMergeAccept&id=' + applicationId,--%>
                <%--        area: ['100%', '100%'],--%>
                <%--        end: function(){--%>
                <%--            searchOrder();--%>
                <%--        }--%>
                <%--    });--%>
                <%--}else --%>
                <%--else if(formKey =='95'){   //勘测信息变更--%>
                <%--    layer.open({--%>
                <%--        type: 2--%>
                <%--        , title: '审核'--%>
                <%--        , content: '${ctx}/customer/entry/change/survey/surveyAudit/' + data.process_instance_id--%>
                <%--        , area: ['100%', '100%']--%>
                <%--        , yes: function (index, layero) {--%>

                <%--        }--%>
                <%--    });--%>
                <%--}else if(formKey =='96'){  //完工信息变更--%>
                <%--    layer.open({--%>
                <%--        type: 2--%>
                <%--        , title: '审核'--%>
                <%--        , content: '${ctx}/completion/change/audit/' + data.process_instance_id--%>
                <%--        , area: ['100%', '100%']--%>
                <%--        , yes: function (index, layero) {--%>

                <%--        }--%>
                <%--    });--%>
                <%--}else if(formKey =='97'){   //设计信息变更--%>
                <%--    layer.open({--%>
                <%--        type: 2--%>
                <%--        , title: '审核'--%>
                <%--        , content: '${ctx}/entryChanges/designInfo/toAuditPage/' + data.process_instance_id+'/'+data.partner_id--%>
                <%--        , area: ['100%', '100%']--%>
                <%--        , yes: function (index, layero) {--%>
                <%--        }--%>
                <%--    });--%>
                <%--}else if(formKey =='98'){   //客户信息变更--%>
                <%--    layer.open({--%>
                <%--        title:'审核',--%>
                <%--        type: 2,--%>
                <%--        area: ["100%", "100%"],--%>
                <%--        content: '${ctx}/entryChanges/customerInformationChange/toChangeAudit?id='+data.process_instance_id--%>
                <%--    })--%>
                <%--}else if(formKey =='99'){   //物料信息变更--%>
                <%--    layer.open({--%>
                <%--        type: 2--%>
                <%--        , title: '审核'--%>
                <%--        , content: '${ctx}/entryChanges/materialInformationChange/materialAudit/' + data.process_instance_id--%>
                <%--        , area: ['100%', '100%']--%>
                <%--        , yes: function (index, layero) {--%>

                <%--        }--%>
                <%--    });--%>
                <%--}else if (formKey == '100'){  //并网信息变更--%>
                <%--    layer.open({--%>
                <%--        type: 2--%>
                <%--        , title: '审核'--%>
                <%--        , content: '${ctx}/onGridInfo/change/audit/' + data.process_instance_id--%>
                <%--        , area: ['100%', '100%']--%>
                <%--        , yes: function (index, layero) {--%>

                <%--        }--%>
                <%--    });--%>
                <%--}--%>

            }else if(obj.event ==='lookDetail'){
                if(formKey =='01'){  //代理商准入申请
                    layer.open({
                        type: 2,
                        title: '查看',
                        content: '${ctx}/flowpath/traderApply/traderApplyDetail?id='+applicationId,
                        area: ['90%', '90%'],
                        end: function(){
                            searchOrder();
                        }
                    });
                }else if(formKey =='02'){  //供应商准入申请
                    layer.open({
                        type: 2,
                        title: '查看',
                        content: '${ctx}/flowpath/supplySupplierApply/supplierApplyDetail?id='+applicationId,
                        area: ['80%', '90%'],
                        end: function(){
                            searchOrder();
                        }
                    });
                }else if(formKey =='03'){  //保证金调整申请
                    layer.open({
                        title:'查看',
                        type: 2,
                        area: ["70%", "80%"],
                        content: '${ctx}/apply/bondAdjustment/bondAdjustmentApplyDetail?id='+applicationId,
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='04'){   //授信额调整申请
                    layer.open({
                        title:'查看',
                        type: 2,
                        area: ["70%", "80%"],
                        content: '${ctx}/apply/distributionGoods/ApplyDistributionGoods?id='+applicationId,
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='05'){   //质保金调整申请
                    layer.open({
                        title:'查看',
                        type: 2,
                        area: ["70%", "80%"],
                        content: '${ctx}/apply/warrantyDeposit/applyWarrantyDeposit?id='+applicationId,
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='06'){   //分包标准价申请
                    layer.open({
                        title:'查看',
                        type: 2,
                        area: ["70%", "80%"],
                        content: '${ctx}/apply/standardPrice/standardPriceApplyDetailPage?id='+applicationId,
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='07'){   //结算额调整申请
                    layer.open({
                        title:'查看',
                        type: 2,
                        area: ["70%", "80%"],
                        content: '${ctx}/apply/settlementAmount/settlementAmountApplyDetail?id='+applicationId,
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='08'){  //赊销下单申请
                    layer.open({
                        type: 2,
                        title: "查看",
                        resize: false,
                        area: ['80%', '90%'],
                        content: '${ctx}/material/order/auditOderDetailPage?id=' + applicationId,
                        end: function(){
                            searchOrder();
                        }
                    });
                }else if(formKey =='09'){   //采购申请
                    layer.open({
                        type: 2,
                        title: '查看',
                        content: '${ctx}/supplyOrder/purchaseAudit/auditPurchaseOrderPage?id=' + applicationId+'&from=detail',
                        area: ['80%', '90%'],
                        end: function(){
                            searchOrder();
                        }
                    });
                }else if(formKey =='10'){   //盘点单申请
                    layer.open({
                        type: 2,
                        title: '查看',
                        content: '${ctx}/inventory/toInventoryOrderDetailForm?mode=view&id=' + applicationId,
                        area: ['80%', '80%'],
                        end: function(){
                            searchOrder();
                        }
                    });
                }else if(formKey =='11'){    //调拨单申请
                    layer.open({
                        type: 2,
                        title: '查看',
                        content: '${ctx}/allocation/examineAllocationOrderPage?from=look&id='+applicationId,
                        area: ['80%','80%'],
                        end: function(){
                            searchOrder();
                        }
                    });
                }else if(formKey =='12'){    //请款申请
                    layer.open({
                        title:'查看',
                        type: 2,
                        area: ["100%", "100%"],
                        content: '${ctx}/apply/outCash/cashOutDetailPage?id='+applicationId,
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='13'){    //仓库申请
                    layer.open({
                        title:'查看',
                        type: 2,
                        area: ["70%", "80%"],
                        content: '${ctx}/apply/warehouseApply/warehouseApplyDetail?id='+applicationId,
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='14'){    //零售价系数申请
                    layer.open({
                        title:'查看',
                        type: 2,
                        area: ["80%", "80%"],
                        content: '${ctx}/apply/priceCoefficient/priceCoefficientApplyDetail?id='+applicationId,
                        end: function(){
                            searchOrder();
                        }
                    })
                }else if(formKey =='15'){   //备货申请
                    layer.open({
                        type: 2,
                        title: '查看',
                        content: '${ctx}/fittingStockUp/fittingStockUpDetailPage?id=' + applicationId+'&from=detail',
                        area: ['80%', '90%'],
                        end: function(){
                            searchOrder();
                        }
                    });
                }else if(formKey =='17'){   //现金下单申请
                    layer.open({
                        type: 2,
                        title: "查看",
                        resize: false,
                        area: ['80%', '90%'],
                        content: '${ctx}/material/order/auditOderDetailPage?id=' + applicationId,
                        end: function(){
                            searchOrder();
                        }
                    });
                }else if(formKey =='18'){    //保证金额度申请
                    layer.open({
                        title:'查看',
                        type: 2,
                        area: ["70%", "80%"],
                        content: '${ctx}/apply/bondLimitApply/bondLimitApplyDetail?id='+applicationId,
                        end: function(){
                            searchOrder();
                        }
                    })
                }
            }else if(obj.event ==='signin'){
                // $(this).attr('disabled', true);
                layer.open({
                    type: 2,
                    title: '签到',
                    content: '${ctx}/taskdispatch/crmReviewGroupMember/signinPage',
                    area: ['40%','50%']
                });
            }else if(obj.event ==='signout'){
                // $(this).attr('disabled', true);
                // $(this).addClass("layui-btn-disabled");
                layer.open({
                    type: 2,
                    title: '签退',
                    content: '${ctx}/taskdispatch/crmReviewGroupMember/signoutPage',
                    area: ['40%','50%']
                });
            }
        })


    });

    function reload(){
        table.reload('test', {
            where: {
                name: $('#name').val().trim(),
                province:$("#province").val().trim(),
                telephone:$("#telephone").val().trim()
            }
        });
    }



    function searchOrder(orderId) {
        //执行重载
        table.reload('test', {
            page: {
                curr: 1
            }
        });
    }
    let currentSort = {
        column: 'createTime',
        order: 'desc'
    };

    // 定义排序函数
    function sortTable() {
        // 切换排序顺序
        currentSort.order = currentSort.order === 'asc' ? 'desc' : 'asc';

        // 重新加载表格，并传递动态排序信息
        table.reload('test', {
            initSort: {
                field: currentSort.column,
                type: currentSort.order
            }
        });

        // 切换排序图标，根据当前排序顺序显示不同的图标（可根据需要自定义）
        const sortIcon = document.getElementById('sortIcon');
        if (currentSort.order === 'asc') {
            sortIcon.src = "${ctxPlugin}/static/sxImg/xm_sx_x.png";
        } else {
            sortIcon.src = "${ctxPlugin}/static/sxImg/xm_sx_s.png";
        }
    }


    let dispatching = false;
    function save() {
        let memberId = $("#members").val();
        if (!memberId) {
            layer.msg('请选择审核人！', {icon:2});
            return;
        }
        if (dispatching) {
            return;
        }
        dispatching = true;
        let itemIds = $("#itemIds").val().split(",");
        $.ajax({
            type: "POST",
            url: "${ctx}/taskdispatch/crmReviewDispatch/batchReAssign",
            contentType : "application/json;charsetset=UTF-8",
            data: JSON.stringify({
                memberId: memberId,
                itemIds: itemIds,
            }),
            success: function (data) {
                if (data.code === "200") {
                    layer.msg('转派成功！')
                    searchOrder()
                    closeSelf();
                } else {
                    layer.msg(data.errMsg, {icon:2});
                }
            },
            complete: function() {
                dispatching = false;
            },
            error: function() {
                layer.msg('系统忙，请稍后再试！', {icon:2});
            }
        });
    }

    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 changeSigninState() {
        $("#signinBtn").attr('disabled', true);
        $("#signinBtn").addClass("layui-btn-disabled");
        $("#signoutBtn").attr('disabled', false);
        $("#signoutBtn").removeClass("layui-btn-disabled");
    }

    function changeSignoutState() {
        $("#signoutBtn").attr('disabled', true);
        $("#signoutBtn").addClass("layui-btn-disabled");
        $("#signinBtn").attr('disabled', false);
        $("#signinBtn").removeClass("layui-btn-disabled");
    }

    function signinBtn() {
        // $(this).attr('disabled', true);
        layer.open({
            type: 2,
            title: '签到',
            content: '${ctx}/taskdispatch/crmReviewGroupMember/signinPage',
            area: ['40%','50%'],
            end: function(){
                window.location.href="${ctx}/itemManagement/proj/waitDealItemPage";
            }
        });
    }

    function signoutBtn() {
        // $(this).attr('disabled', true);
        // $(this).addClass("layui-btn-disabled");
        layer.open({
            type: 2,
            title: '签退',
            content: '${ctx}/taskdispatch/crmReviewGroupMember/signoutPage',
            area: ['40%','50%'],
            end: function(){
                window.location.href="${ctx}/itemManagement/proj/waitDealItemPage";
            }
        });
    }

    function showDispatchForm() {
        let formKey = "";
        let itemIds = [];
        let checked = table.checkStatus('test').data;
        if(!checked || !checked.length) {
            layer.msg('请勾选待转派的待办事项！', {icon:2});
            return;
        }
        formKey = checked[0].formKey;
        for (let i =0; i<checked.length;i++){
            itemIds.push(checked[i].id);
            // if (checked[i].formKey !== formKey) {
            //     layer.msg('选定的待办事项必须为同一申请类型！', {icon:2});
            //     return;
            // }
        }
        $("#groupName").val(mapGroupName()[formKey]);
        $("#itemIds").val(itemIds.join(","));
        $.ajax({
            type: "POST",
            url: "${ctx}/taskdispatch/crmReviewGroupMember/groupMembers",
            data: {
                itemIds: itemIds.join(",")
            },
            success: function (data) {
                if (data.code === "200") {
                    let membersEl =  $("#members");
                    let members = data['data'] || [];
                    membersEl.empty();
                    membersEl.append('<option value="">请选择</option>');
                    for(var i=0;i<members.length;i++) {
                        let option = $('<option></option>');
                        option.val(members[i].columns.id);
                        option.text(members[i].columns.name);
                        membersEl.append(option);
                    }
                    form.render('select');
                    batchAssignLayer = layer.open({
                        type: 1,
                        title: '转派',
                        content: $('#redispatchWin'),
                        area: ['40%', '400px']
                    });
                } else {
                    layer.msg(data.errMsg || '获取组员失败！', {icon:2});
                }
            }
        });
    }

    function mapGroupName() {
        return {
            // 91设计审核 92档案审核 93安装验收 94并网验收 95勘测信息变更 96 完工信息变更 97设计变更 98客户信息变更 99物料变更)
            '91': '设计审核组',
            '92': '档案审核组',
            '93': '安装验收组',
            '94': '并网验收组',
            '95': '设计审核组',
            '96': '安装验收组',
            '97': '设计审核组',
            '98': '档案审核组',
            '99': '安装验收组'
        }
    }

    function closeSelf() {
        layer.close(batchAssignLayer);
    }

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