提交form表单时,修改action路径,增加参数
阅读原文时间:2021年04月22日阅读:4

代码如下,核心代码为555和556两行

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--
  Created by IntelliJ IDEA.
  User: zyf
  Date: 2019/4/11
  Time: 11:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="fe.SysException" pageEncoding="UTF-8" %>
<%@ page import="fe.report.ReportCreateServer" %>
<%@ page import="fe.report.ReportManagerServer" %>
<%@ page import="fe.res.ResourceManage" %>
<%@ page import="fe.search.SearchComponent" %>
<%@ page import="fe.sys.UserVO" %>
<%@ page import="fe.taglib39.Tag" %>
<%@ page import="fe.util.StringUtils" %>
<%@ page import="java.util.LinkedHashMap" %>
<%@ page import="java.util.Map" %>
<%@ page import="fe.util.LogUtils" %>
<%@ page import="fe.service.UserSession" %>
<%@ page import="fe.dao.DataTable" %>
<%@ page import="fe.datapool.DataPool" %>
<%@ page import="client.clientimport.ClientReportCreatServer" %>
<%@ page import="client.clientimport.ClientReportManagerServer" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="client.clientimport.ClientTag" %>
<%
    String path = request.getContextPath(); //路径
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; //http路径
    ClientReportManagerServer server = (ClientReportManagerServer) ResourceManage.getContext("clientReportManagerServer");
    //ReportManagerServer server = (ReportManagerServer) ResourceManage.getContext("reportManager");
    ReportCreateServer createServer = (ReportCreateServer) ResourceManage.getContext("reportCreate");
    ClientReportCreatServer clientReportCreatServer = (ClientReportCreatServer)ResourceManage.getContext("clientReportCreatServer");

    String selectNames = request.getParameter("selectNames") == null ? "" : request.getParameter("selectNames");
    String selectFields = request.getParameter("selectFields") == null ? "" :  request.getParameter("selectFields");
    //已选字段数组
    String[] selectNameArray = selectNames.split(",");
    String[] selectFieldArray = selectFields.split(",");


    String reportId = request.getParameter("reportId"); //报表ID
    if ((StringUtils.isNull(reportId)) && request.getAttribute("reportId") != null)
        reportId = request.getAttribute("reportId").toString();
    String cpage = request.getParameter("cpage"); //报表页码
    if (StringUtils.isNull(cpage) && request.getAttribute("cpage") != null)
        cpage = request.getAttribute("cpage").toString();

    String html = ""; //
    String filter = null; //过滤条件
    if (request.getAttribute("filter") != null) {
        filter = request.getAttribute("filter").toString();
        filter = server.getPreviewReportFilter((UserVO) session.getAttribute("User"), filter);
    }
    String css = server.getReportCss(reportId); //报表样式
    int total[] = new int[2]; //总行数及总页数
    try {
        total = server.getReportDataTotalPages(reportId, filter, (UserVO) session.getAttribute("User"));
    } catch (SysException e) {
        request.setAttribute("error", e.getMessage());
        throw e;
    } catch (Exception e) {
        LogUtils.error(e);
        request.setAttribute("error", "报表数据查询出错,请联系管理员");
        throw new SysException("报表数据查询出错,请联系管理员");
    }

    cpage = total[1] > 0 ? (cpage == null || "0".equals(cpage) ? "1" : cpage) : "1";

    int chartNumber = server.reportChartNumber(reportId); //图形报表数

    SearchComponent searchComponent = new SearchComponent();

    String newCell = request.getParameter("newCell"); //新增的查询条件


%>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>报表呈现</title>
    <jsp:include flush="true" page="/common/header39.jsp"/>
    <link rel="stylesheet" type="text/css" href="/css39/bg_newsample_blue.css"/>
    <style>
        .date_style .date_td_con {
        }

        .date_style .date_td_con input {
            border: 1px solid #aaa;
            height: 26px;
            width: 120px;
            margin-left: 6px;
            padding-right: 5px;
            background-position-x: 110px;
        }

        .select_box_con2 {
            padding-right: 5px;
        }

        .date_style > div.date_td_con {
            margin-left: 3px !important;
            /*width: 236px !important;*/
            width: 94% !important;
        }

        .date_style > div.date_td_con > div > input#value_T_AA_WO05- {
            width: 100%;
            margin-left: 0px;
            background-position-x: 99%;
        }

        .date_style > div.date_td_con > div > input#value_T_AA_WO04- {
            width: 100%;
            margin-left: 0px;
            background-position-x: 99%;
        }

        .rebut-box {
            width: 300px;
            margin: 0 auto;
            padding: 8px 0;
            overflow: hidden;
        }

        .rebut-box a {
            margin: 0 2px;
        }

        .rebut-box a:hover {
            position: relative;
            top: 1px;
        }
    </style>
    <%
        if (css != null) {
    %>
    <link href="/feReport/css/<%=css%>?v=100011" rel="stylesheet" type="text/css"/>
    <%
        }
    %>


    <script type="text/javascript" charset="utf-8" src="/js39/flyrise.height.config.js"></script>
    <script type="text/javascript">
        var searchHtmls = new Array();
    </script>
</head>

<body>
<iframe id="downloadwindow" name="downloadwindow" style="display:none;" src=""></iframe>
<div class="wrap">
    <div class="content">
        <!-- Begin::按钮TOOLBAR -->
        <div class="toolbar_width" style="height:50px; width:100%; border-bottom:1px solid #ccc;">
            <ul class="toolbar_list">
                <%
                    if (chartNumber > 0) { //有图表
                %>
                <li>
                    <a href="javascript:showChart(<%=reportId%>);" class="styleLightBgColor styleHoverBgColor"
                       tabindex="-1" id='SYS_BUTTON_add'>图表查看</a>
                </li>
                <li class="toolbar_line_bg">
                        <%
                }else{
            %>
                <li>
                    <%
                        }
                    %>
                    <a tabindex="-1" class="styleLightBgColor styleHoverBgColor" id='SYS_BUTTON_Pdf'
                       onclick="exp_print_choose('pdf');">Pdf打开</a>
                </li>
                <li class="toolbar_line_bg">
                    <a tabindex="-1" class="styleLightBgColor styleHoverBgColor" id='SYS_BUTTON_Excel'
                       onclick="exp_print_choose('excel');">Excel打开</a>
                </li>
                <li class="toolbar_line_bg">
                    <a tabindex="-1" class="styleLightBgColor styleHoverBgColor" id='SYS_BUTTON_Print'
                       onclick="exp_print_choose('<%=reportId%>');">打印报表</a>
                </li>
            </ul>
        </div>
        <!-- End::按钮TOOLBAR -->
        <%
            int iCondition = 0; //查询条件个数
            String finds[] = server.getReportFind(reportId); //报表数据(选择字段RI04,是否查询RI21,字段中文名RI05,数据类型RI39,表名RI02,字段格式RI20,格式的隐藏值RI58)
            String searchFields = ""; //?
            if (finds != null && finds.length > 1) {
                String fields[] = finds[0].split("`"); //字段列表
                String ifCondition[] = finds[1].split("`"); //是否查询条件 1-是查询条件
                String fieldNames[] = null;
                if (finds.length > 2 && finds[2] != null) {
                    fieldNames = finds[2].split("`");
                }
                String fty[] = null; //字段类型 (DATE / NUMBER / ……)
                if (finds.length > 3 && finds[3] != null)
                    fty = finds[3].split("`");
                String foramts[] = null; //格式 (C, DYYYY-MM-DD, [100000] ……)
                if (finds.length > 5 && finds[5] != null)
                    foramts = finds[5].split("`");
                String ri58[] = null;
                if (finds.length > 6 && finds[6] != null)
                    ri58 = finds[6].split("`");
        %>
        <form action="/client/clientReport/retireReport/clientSearch.jsp" id="searchForm" method="post">
            <div class="search_bg" id="sendApproveDivNew">
                <div class="graph_search" id="searchdivs">
                    <input type="hidden" name="reportId" value="<%=reportId%>">
                    <input type="hidden" name="cpage" value="<%=cpage%>">
                    <input type="hidden" name="filter" id="filter" value="<%=filter == null ? "" : filter%>">
                    <input type="hidden" name="finds" value="<%=finds[0]%>">
                    <input type="hidden" name="newCell" id="newCell" value="<%=newCell == null ? "" : newCell%>">
                    <input type="hidden" name="dataType" value="<%=server.getReportFieldSet(reportId).getString("dataType")%>">
                   <%-- <input type="hidden" name="selectFields" value="1,1">
                    <input type="hidden" name="selectNames" value="2,2">--%>

                    <!-- Begin::查询条件 -->
                    <table width="100%" border="0" cellspacing="1" cellpadding="1" id="filterTable">
                        <tr id="tr0">
                            <%
                                int nc = newCell != null && !"".equals(newCell) ? Integer.parseInt(newCell) + 1 : 0;
                                int i = 0; //
                                int km = 0; //
                                int totalItems = fields.length + nc; //共有多少字段
                                int firstCondition = 0;
                                String firstFields = null;
                                while (km < totalItems) {
                                    if (km >= fields.length) { //?
                                        i = firstCondition;
                                    } else {
                                        i = km;
                                    }
                                    if ("1".equals(ifCondition[i])) {//设置要查询
                                        if (iCondition == 0) {
                                            firstCondition = km;
                                            firstFields = fields[km];
                                        }
                                        if (km < fields.length)
                                            searchFields = searchFields + "`" + fields[i];
                                        String tit = "未知项";
                                        if (fieldNames != null)
                                            tit = fieldNames[i];
                                        String filterType = (km >= fields.length ? "_" + (km - fields.length) : ""); //?
                            %>
                            <td style="width:20px">&nbsp;</td>
                            <td id="id_<%=fields[i] + filterType%>"
                                    <%="".equals(filterType) ? "" : "filterType=" + (km - fields.length)%>
                                align="<%=iCondition % 2 == 0 ? "right" : "left"%>"
                                style="height:30px;">
                                <table width="100%">
                                    <tr>
                                        <!-- Begin::字段下拉 -->
                                        <td class="combo_style select_box_con2" style="width: 111px;">
                                            <%
                                                Map fieldMap = new LinkedHashMap();
                                                Tag tag = new Tag(); //样式
                                                ClientTag clientTag = new ClientTag();
                                                int gi = -1;
                                                String defaultValue = "";
                                                for (int j = i; j < fields.length; j++) {
                                                    String tm = "未知项";
                                                    if (fieldNames != null)
                                                        tm = fieldNames[j];
                                                    if (j >= ifCondition.length || !"1".equals(ifCondition[j])) //非查询条件
                                                        continue;
                                                    String fd = request.getParameter("field_" + fields[i] + filterType);
                                                    boolean flat = false;
                                                    if (fd != null) {
                                                        if (fields[j].equals(fd)) {
                                                            flat = true;
                                                            gi = j;
                                                            defaultValue = fd;
                                                        }
                                                    } else {
                                                        if (fields[i].equals(fields[j])) {
                                                            flat = true;
                                                            gi = j;
                                                            defaultValue = fields[i];
                                                        }
                                                    }
                                                    fieldMap.put(fields[j], tm);
                                                }
                                                fieldMap.put("field", "field_" + fields[i] + filterType);
                                                fieldMap.put("defauleHideValue", defaultValue);
                                                fieldMap.put("defauleShowValue", fieldMap.get(defaultValue));
                                                fieldMap.put("onchange", "showData(this)");
                                                fieldMap.put("change", "showData(this)");
                                                //out.print(tag.getCustomCombo(fieldMap));
                                                out.print(clientTag.getCustomCombo(fieldMap));
                                                fieldMap.clear();
                                                String tfd = request.getParameter("type_" + fields[i] + filterType);
                                                String ffd = request.getParameter("format_" + fields[i] + filterType);
                                            %>

                                        </td>
                                        <!-- End::字段下拉 -->

                                        <!-- Begin::操作符下拉 -->
                                        <td align="left" style="width: 82px;" class="combo_style">

                                            <input type="hidden" name="type_<%=fields[i] + filterType%>"
                                                   value="<%=tfd != null && !"".equals(tfd.trim()) ? tfd : (fty != null ? fty[i] : "")%>">
                                            <input type="hidden" name="format_<%=fields[i] + filterType%>"
                                                   value="<%=ffd != null && !"".equals(ffd.trim()) ? ffd : (foramts != null && !"".equals(foramts[i].trim()) ? foramts[i] : "")%>">
                                            <%
                                                String oper = request.getParameter("oper_" + fields[i] + filterType);
                                                if (oper == null)
                                                    oper = "=";
                                                Map operMap = new LinkedHashMap();
                                                operMap.put("=", "等于");
                                                operMap.put("like", "包含");
                                                operMap.put("not like", "不包含");
                                                operMap.put("<>", "不等于");
                                                operMap.put(">", "大于");
                                                operMap.put(">=", "大于等于");
                                                operMap.put("<", "小于");
                                                operMap.put("<=", "小于等于");
                                                operMap.put("null", "为空");
                                                operMap.put("not null", "不为空");
                                                operMap.put("field", "oper_" + fields[i] + filterType);
                                                operMap.put("defauleHideValue", oper);
                                                operMap.put("defauleShowValue", operMap.get(oper));
                                                out.print(tag.getCustomCombo(operMap));
                                                operMap.clear();
                                            %>
                                        </td>
                                        <!-- End::操作符下拉 -->

                                        <!-- Begin::值输入或选择 -->
                                        <td align="left">
                                                <%
                                                String v = request.getParameter("value_" + fields[i] + filterType);
                                                char a = foramts[gi].charAt(0);
                                                tag.setName("value_" + fields[i] + filterType);
                                                if (v != null && foramts[i].charAt(0) == 'D' && v.length() > foramts[i].length())
                                                    v = v.substring(0, foramts[i].length() - 1);
                                                String htmls = "";
                                                if (a == '[') {
                                                    tag.setFormat("C");
                                                    tag.setPrompt(foramts[gi]);
                                                    htmls = tag.getOrganizeTreeTag() + "<input type=\"hidden\" name=\"orgType\">";
                                                } else if (a == 'D') {
                                                    tag.setFormat(foramts[gi]);
                                                    htmls = tag.getDateTag() + "<input type=\"hidden\" name=\"dateType\">";
                                                } else if (a != 'C' && a != 'N' && a != 'P') {
                                                    tag.setFormat("C");
                                                    tag.setPrompt(foramts[gi]);
                                                    DataTable dt = DataPool.getDataTable(foramts[gi]);
                                                    if(dt != null && dt.getTotalRow() > 30){
                                                        tag.setPop(true);
                                                        request.setAttribute("current",1);
                                                        request.setAttribute("pagesize",35);
                                                    }
                                                    htmls = tag.getComboTag() + "<input type=\"hidden\" name=\"comboType\">";
                                                } else {
                                                    tag.setFormat("C");
                                                    htmls = tag.getTextTag() + "<input type=\"hidden\" name=\"textType\">";
                                                }
                                        %>
                                                <%=htmls%>

                                            <!-- End::值输入或选择 -->
                                    <td align="left">
                                        <input type="checkbox" onclick="selectField()" id="<%="a." + fields[i]%>" name="<%=tit%>" checked="true" style="margin-top: 12px;">
                                    </td>
                                    </tr>


                                </table>
                            </td>
                            <%
                                if (iCondition > 0 && iCondition % 2 == 1) { //隔开、换行
                            %>
                            <td style="width:20px"> &nbsp;</td>
                        </tr>
                        <tr>
                            <%
                                        }
                                        iCondition++;
                                    }
                                    km++;
                                }
                            %>
                        </tr>
                    </table>
                    <!-- End::查询条件 -->

                    <%
                        if (iCondition > 0) {
                    %>
                    <div class="rebut-box">
                        <a href="javascript:formSubmit(1);" class="auto_btn styleLightBgColor styleHoverBgColor"
                           title="立即查找"><span>立即查找</span></a>
                       <%-- <a href="javascript:addFilter('<%=firstFields%>');"
                           class="auto_btn styleLightBgColor styleHoverBgColor" title="增加查询条件"><span>增加查询条件</span></a>--%>
                        <a href="javascript:clearFilter('<%=firstFields%>');"
                           class="auto_btn styleLightBgColor styleHoverBgColor" title="清空查询条件"><span>清空查询条件</span></a>
                    </div>
                    <%
                        }
                    %>
                </div>
            </div>
           <%-- <div class="hiddenApproveDiv">
                <a href="javascript:changeSendApproveDiv(this);" id="hiddenApproveBar"
                   class="hiddenApproveDiv_bardown_btn" title="展开查询条件"></a>
            </div>--%>
            <input type="hidden" name="addField" value="<%=firstFields%>"/>
        </form>
        <%
            }
        %>
        <div class="graph_table" id="dataDiv" Style="WIDTH: 928px; HEIGHT: 100%; OVERFLOW-y: hidden;">
            <%
                try {
                    long startt = System.currentTimeMillis();
                    int cp = (cpage == null || "0".equals(cpage) ? 1 : Integer.parseInt(cpage));
                    UserVO user = UserSession.get(request);
                    //html = createServer.createReportInfo(reportId, cp, cp, filter, user);
                    html = clientReportCreatServer.createReportInfo(reportId, cp, cp, filter, user , selectNameArray , selectFieldArray);
                    long endt = System.currentTimeMillis();
                    LogUtils.info("报表用时:" + ((endt - startt) / 1000) + "秒");
                } catch (SysException e) {
                    request.setAttribute("error", e.getMessage());
                    throw e;
                } catch (Exception e) {
                    LogUtils.error(e);
                    request.setAttribute("error", "报表数据查询出错,请联系管理员");
                    throw new SysException("报表数据查询出错,请联系管理员");
                }
                if (html.startsWith("ERROR")) {
            %>
            <div class="graph_table">
                <div class="error">
                    <div class="error_top"></div>
                    <div class="error_mid"><%=html.replace("ERROR:", "")%>
                    </div>
                    <div class="error_bot"></div>
                </div>
            </div>
            <%
            } else {
            %>
            <%=html%>
            <%
                }
            %>
        </div>

        <ul class="bottom_page" style="position:relative;">
            <li>记录总数:<span class="red" id="totalField"><%=total[0]%></span>条</li>
            <%
                if (total[0] > 0) {
            %>
            <li><%=cpage%>/<%=total[1]%>页</li>
            <%
                if (total[1] > 1 && Integer.parseInt(cpage) > 1) {
            %>
            <li><a href="javascript:toPage(1);"><img src="/feReport/images/frist_max.gif"></a></li>
            <li><a href="javascript:toPage(2);"><img src="/feReport/images/left_per.gif"></a></li>
            <%
            } else {
            %>
            <li><img src="/feReport/images/top_gray.gif"></li>
            <li><img src="/feReport/images/privous_gray.gif"></li>
            <%
                }
            %>
            <li><select name="" onchange="toPage(5)">
                <%
                    for (int i = 1; i <= total[1]; i++) {
                %>
                <option <%=i == Integer.parseInt(cpage) ? "selected" : ""%> value="<%=i%>">第<%=i%>页</option>
                <%
                    }
                %>
            </select>&nbsp;
            </li>
            <%
                if (total[1] > 1 && Integer.parseInt(cpage) < total[1]) {
            %>
            <li><a href="javascript:toPage(3);"><img src="/feReport/images/right_next.gif"></a></li>
            <li><a href="javascript:toPage(4);"><img src="/feReport/images/last_max.gif"></a></li>
            <%
            } else {
            %>
            <li><img src="/feReport/images/next_gray.gif"></li>
            <li><img src="/feReport/images/bottom_gray.gif"></li>
            <%
                    }
                }
            %>
        </ul>
    </div>
</div>

<form action="/feReport/showChart.jsp" name="chartForm" id="chartForm">
    <input type="hidden" value="<%=reportId%>" name="reportId">
    <input type="hidden" value="<%=filter == null ? "" : filter%>" name="filter">
</form>
<%
    if (iCondition == 1) {
%>
<script>
    if (document.getElementById("tr0") != null) {
        var cell = document.getElementById("tr0").cells[1];
        if (cell != null)
            cell.align = "center";
    }
</script>
<%
    }
%>


<script type="text/javascript">

    window.onload = function displaySearch() {
        //alert("-----------");
        changeSendApproveDiv(null);
    }

    var totalField = $("#totalField");
    function formSubmit(t) {
        if (t == 1) {
            $("input[name=cpage]").val(0);
        }

        //拿到所选的字段中文名和字段名
        var selectNames = [];
        var selectFields = [];
        $(function(){
            $("#searchForm").find(":checkbox:checked").each(function(){
                var selectName = $(this).attr('name');
                console.log('-----val----' + selectName);
                selectNames.push(selectName);
                var selectField = $(this).attr('id');
                console.log('-----val----' + selectField);
                selectFields.push(selectField);
            });
        });
        selectNames = selectNames.toString();
        selectFields = selectFields.toString();
        console.log('-----selectNames----' + selectNames);
        console.log('-----selectFields----' + selectFields);
        if (selectNames.length <= 0){
            top.FETOP.Dialog.warn("查询字段不能为空,请选择字段进行报表查询");
            return false;
        }
        console.log("-----action----" + $("form:eq(0)").attr("action"));
        var newaction  = $("form:eq(0)").attr("action") + "?selectNames=" + selectNames + "&selectFields=" + selectFields;
        $("#searchForm").attr("action",newaction);
        $("#searchForm").submit();
    }
    //选择字段时变换相应的文本框
    function showData(obj) {
        obj = $(obj).prev();
        var idobj = $(obj).parent().parent().parent().parent().parent().parent().parent();
        var vid = $(idobj).attr("id").replace("id_", "");
        for (var i = 0; i < fields.length; i++) {
            if (fields[i] == $(obj).val()) {
                searchHtmls[i] = searchHtmls[i].replace(new RegExp("_" + $(obj).val(), "gm"), "_" + vid);
                $(idobj).html(searchHtmls[i]);
                break;
            }
        }
        setTagTdClass();
    }

    //分页处理
    var total =<%=total[1]%>;
    var cp =<%=cpage%>;
    function toPage(p) {
        if (total > 0) {
            if (p == 1) {
                $("input[name=cpage]").val(1);
            } else if (p == 2) {
                if (cp > 1) {
                    $("input[name=cpage]").val(cp - 1);
                }
                else {
                    $("input[name=cpage]").val(1);
                }
            } else if (p == 3) {
                if (cp >= total) {
                    $("input[name=cpage]").val(total);
                }
                else {
                    $("input[name=cpage]").val(cp + 1);
                }
            } else if (p == 4) {
                $("input[name=cpage]").val(total);
            } else {
                var evt = window.event || arguments.callee.caller.arguments[0];//兼容火狐浏览器 woky 2015.10.29
                var obj = evt.srcElement ? evt.srcElement : evt.target;//兼容火狐浏览器 woky 2015.10.29
                $("input[name=cpage]").val(obj.value);
            }
            formSubmit(2);
        }
    }
    var chartNumber =<%=chartNumber%>;
    function showChart(id) {
        if (chartNumber > 0)
        //window.location.href='/feReport/showChart.jsp?reportId=<%=reportId%>';
            document.getElementById("chartForm").submit();
        else {
            top.FETOP.Dialog.warn("没有配置统计图表");
            return;
        }
    }
    //导出打印弹出选择页码框
    function exp_print_choose(type) {
        var url = "/feReport/print_exp.jsp?type=" + type;
        if (total != null)url = url + "&total=" + total;
        Dialog.show({
            id: 'expPrintChoose',
            title: '报表下载',
            url: url,
            draggable: true,
            maxable: false,
            closable: true,
            scroll: 'no',
            width: 600,
            height: 250,
            fromWindow: window,
            closeAction: function (dialog) {
                var va = dialog.iframe.returnValue;
                if (va == null) return false;
                if (type == 'pdf') {
                    getDownloadUrl(type, va);
                } else if (type == 'excel') {
                    getDownloadUrl(type, va);
                } else {
                    showPrint(type, va);
                }
            }
        });
    }
    //导出数据
    function getDownloadUrl(type, va) {
        var res = "/FileDownload?from=report&outtype=" + type + "&expPage=" + va;
        var filter = document.getElementById("filter");
        try {
            res += "&reportId=<%=reportId%>";
            res += "&filter=" + encodeURI(filter.value); //modified by lw 需要动态加载iframe 时,get请求传递中文时,必须调用encodeURI(),处理乱码问题。
        } catch (e) {
            top.FETOP.Dialog.warn(e.message);
        }
        document.getElementById('downloadwindow').src = res;
    }

    function showPrint(reportId, va) {
        var filter = document.getElementById("filter");
        openInfo("/feReport/print.jsp?reportId=" + reportId + "&printPage=" + va + "&filter=" + encodeURI(filter.value), "veryBig", "h");//含特殊字符,用encodeURI(filter)处理,否则filter的值传递不了.
    }

    function openInfo(url, page, x) {
        var width = 0;
        var height = 0;
        if (page == 'big') {
            if (x != "v") {
                width = 750;
                height = 500;
            } else {
                width = 500;
                height = 700;
            }
        }
        else if (page == 'veryBig') {
            if (x != "v") {
                width = 1200;
                height = 600;
            } else {
                width = 600;
                height = 900;
            }
        }
        else if (page == 'middle') {
            if (x != "v") {
                width = 500;
                height = 350;
            } else {
                width = 350;
                height = 500;
            }
        }
        else if (page == 'small') {
            if (x != "v") {
                width = 400;
                height = 250;
            } else {
                width = 250;
                height = 400;
            }
        }
        else if (page == 'tiny') {
            if (x != "v") {
                width = 200;
                height = 150;
            } else {
                width = 200;
                height = 150;
            }
        }
        showx = (screen.availWidth - width) / 2;
        showy = (screen.availHeight - 10 - height) / 2;
        var r = window.open(url, "", "height=" + height + ",width=" + width + ",top=" + showy + ",left=" + showx + ",scrollbars=1");
    }
    var bdheight = 0;
    var offy = 0;
    //计算DIV的可见大小
    function resize_divBody(div) {
        if (document.all[div]) {
            var divObj = document.all[div];
            //alert(document.body.clientHeight)
            if (document.body.clientHeight && divObj != null) {
                var bodyHeight = document.body.clientHeight;
                var bodyWidth = document.body.clientWidth;
                var offsetY = getObjOffSetY("filterTable");
                var offsetX = getObjOffSetX(div);
                //alert(offsetY);
                divObj.style.width = bodyWidth - offsetX;
                divObj.style.height = bodyHeight - offsetY - 25;
                bdheight = bodyHeight;
                offy = offsetY;
            }
        }
    }

    /**
     * 获取传入对象的绝对Top坐标
     * @param objName 对象的名称
     * @author woky
     */
    function getObjOffSetY(objName) {
        var offsetY = 0;
        var obj = document.all[objName];
        if (!obj) {
            return 0;
        }
        while (obj && obj.tagName != "BODY") {
            offsetY += obj.offsetTop;
            obj = obj.offsetParent;
        }
        return offsetY;
    }

    /**
     * 获取传入对象的绝对Left坐标
     * @param objName 对象的名称
     * @author woky
     */
    function getObjOffSetX(objName) {
        var offsetX = 0;
        var obj = document.all[objName];
        if (!obj) {
            return 0;
        }
        while (obj && obj.tagName != "BODY") {
            offsetX += obj.offsetLeft;
            obj = obj.offsetParent;
        }
        return offsetX;
    }
    //resize_divBody("dataDiv");
    resizeTabHeight();

    function divWidthHieght() {
        if (document.all['dataDiv']) {
            var divObj = document.all['dataDiv'];
            if (document.body.clientHeight) {
                var bodyHeight = document.body.clientHeight;
                var bodyWidth = document.body.clientWidth;
                var offsetY = getObjOffSetY('dataDiv');
                var offsetX = getObjOffSetX('dataDiv');
                var wh = [bodyWidth - offsetX, bodyHeight - offsetY - 20];
                return wh;
            }
        }
    }


    //展开或收缩查询DIV
    var shflag = false;
    function changeSendApproveDiv(src) {

        $("#sendApproveDivNew").show();

       /* var obj = $("#hiddenApproveBar");
        var sendDivObj = $("#sendApproveDivNew");
        if (!shflag) {
            $("#sendApproveDivNew").show();
            $("#hiddenApproveBar").attr("class", "hiddenApproveDiv_bar_btn");
            $("#hiddenApproveBar").attr("title", "隐藏查询条件");
            shflag = true;
        }
        else {
            $("#sendApproveDivNew").hide();
            $("#hiddenApproveBar").attr("class", "hiddenApproveDiv_bardown_btn");
            $("#hiddenApproveBar").attr("title", "展开查询条件");
            shflag = false;
        }*/
        resizeTabHeight();
    }
    //如果没有数据添加空白行
    var reportTable = document.getElementById("report1");
    reportTable = null;
    if (reportTable != null) {
        if (reportTable.rows.length < 10) {
            var whh = divWidthHieght();
            var c = reportTable.rows.length * 30;
            while (whh != null && c < whh[1]) {
                var tr = reportTable.insertRow();
                var cn = 1;
                if (reportTable.rows.length > 0)cn = reportTable.rows[0].cells.length;

                for (var k = 0; k < reportTable.rows[0].cells.length; k++) {
                    tr.insertCell();
                }
                c = c + 30;
            }

        }
    }
    var filter =<%=filter != null && !"".equals(filter.trim()) ? 1 : 0%>;
    if (filter == 1) {
        changeSendApproveDiv(null);
    }
    var newCell =<%=newCell == null || "".equals(newCell) || "null".equals(newCell) ? "-1" : newCell%>;//记录新加条件个数
    var tr = null;//复制的行
    var firstTr = null;//被复制的行
    var bdheight = 0;
    var offy = 0;
    var flat = true;
    var lasth = 0;
    //增加查询条件
    function addFilter(firstFields) {
        var tb = document.getElementById("filterTable");
        if (tb.rows.length > 0) {
            firstTr = tb.rows[0];
            tr = tb.rows[tb.rows.length - 1];//最后一行
            if (tr.cells.length <= 0 && tb.rows.length > 1) {
                tr = tb.rows[tb.rows.length - 2];//
            }
            if (tr != null) {
                newCell = newCell + 1;
                if (tr.cells.length > 2 && tr.cells.length <= 5) {
                    var newtr = tb.insertRow();
                    processCell(newtr, firstTr, firstFields);
                    if (flat)resize_divBody("dataDiv");
                    if (bdheight / offy >= 2) {
                        flat = false;
                        //if(lasth==0)lasth=offy-40;
                        //document.getElementById("sendApproveDivNew").style.height=lasth;

                    }
                } else {
                    processCell(tr, firstTr, firstFields);
                }

                document.getElementById("newCell").value = newCell;
                //add by lw. 2014/09/05 begin
                var $newVau = $("#" + "id_" + firstFields + "_" + newCell).find("input[name=" + "value_" + firstFields + "]");
                var $newVau2 = $("#" + "id_" + firstFields + "_" + newCell).find("input[name=" + "value_" + firstFields + "-]");
                if ($newVau[0]) {
                    $newVau.val('');
                }
                if ($newVau2[0]) {
                    $newVau2.val('');
                }
                //end
            }
            resizeTabHeight();
        }
    }
    //新加条件的的名字规则是在原名字前加多序号
    function processCell(newtr, tr, firstFields) {
        var cell1 = newtr.insertCell();
        cell1.innerHTML = tr.cells[0].innerHTML;
        var cell2 = newtr.insertCell();
        cell2.innerHTML = tr.cells[1].innerHTML;
        if (newtr.cells.length <= 2)cell2.align = tr.cells[1].align;
        else cell2.align = "left";
        cell2.id = "id_" + firstFields + "_" + newCell;
        cell2.filterType = newCell;
        var child = cell2.children;
        for (var i = 0; i < child.length; i++) {
            if (child[i].name != null && child[i].type.toLowerCase() != "button") {
                child[i].name = child[i].name + "_" + newCell;
                child[i].id = child[i].id + "_" + newCell;
                if (child[i].tagName.toLowerCase() == "select") {
                    child[i].filterType = "1";
                }
            }
        }
        //获取cell2.id下的所有input 域
        if (newCell != null && newCell >= 0) {
            var inputs = document.getElementById(cell2.id).getElementsByTagName("input");
            for (var i = 0; i < inputs.length; i++) {
                var inp = inputs[i];
                if (inp.id != null && inp.id != "") {
                    var attrOnclick = $('#'+inp.id).attr('onclick');
                    var regId=new RegExp(inp.id);
                    var regName=new RegExp(inp.name);
                    if (inp.id.charAt(inp.id.length - 1) == "-") {
                        inp.id = inp.id.substr(0, inp.id.length - 1) + "_" + newCell + "-";
                        inp.name = inp.name.substr(0, inp.name.length - 1) + "_" + newCell + "-";
                    } else {
                        inp.id = inp.id + "_" + newCell;
                        inp.name = inp.name + "_" + newCell;
                    }
                    if (attrOnclick && attrOnclick.indexOf("showOrgSelect('/organizeTree/selectOrganizeTree.jsp?") > -1) {//解决报表页面组织机构增加查询条件后无法正确选择条件问题
                        attrOnclick = attrOnclick.replace(regId, inp.id).replace(regName, inp.name);
                        $('#' + inp.id).attr('onclick', attrOnclick);
                    }
                }
            }
        }
    }
    var searchFields = "<%=searchFields != null && searchFields.length() > 0 ? searchFields.substring(1) : ""%>";
    var sf = searchFields.split("`");
    var fields = new Array();
    for (var i = 0; i < sf.length; i++) {
        if (sf[i] != "") {
            fields.push(sf[i]);
            searchHtmls.push(document.getElementById("id_" + sf[i]).innerHTML);
        }
    }
    //清空查询条件
    function clearFilter(firstFields) {
        var filterTable = document.getElementById("filterTable");
        var delRows = new Array();
        if (filterTable != null) {
            var rows = filterTable.rows;
            for (var i = 0; i < rows.length; i++) {
                var mk = 0;
                var cells = rows[i].cells;
                var cs = cells.length;
                var spaceCell = new Array();
                for (var j = 0; j < cells.length; j++) {
                    if (j == 1 || j == 3) {
                        if (cells[j].filterType != null) {
                            var child = cells[j].children;
                            for (var ii = child.length - 1; ii >= 0; ii--) {
                                cells[j].removeChild(child[ii]);
                            }
                            spaceCell.push(j - 1);
                            spaceCell.push(j);
                            mk++;
                        } else {
                            $(cells[j]).find("tr td:eq(2)").find("input").val("");
                        }
                    }
                }
                for (var ck = spaceCell.length - 1; ck >= 0; ck--) {
                    rows[i].deleteCell(spaceCell[ck]);
                }
                if (mk == 2 || (cs == 2 && mk == 1)) {
                    delRows.push(i);
                }
            }
            for (var i = delRows.length - 1; i >= 0; i--) {
                filterTable.deleteRow(delRows[i]);
            }
            for (var i = 0; i < rows.length; i++) {
                var cells = rows[i].cells;
                for (var j = 0; j < cells.length; j++) {
                    if (rows.length == 2 && cells.length == 2 && j == 1 && cells[j].align == "right") {
                        cells[j].align = "center";
                    }
                }
            }
            document.getElementById("filter").value = "";
            document.getElementById("newCell").value = "";
        }
        document.getElementById("sendApproveDivNew").style.height = null;
        resize_divBody("dataDiv");
    }


</script>
<script>
    //画线---------------------
    var line_left, line_top, line_width, line_height;
    function getBounds(obj) {
        var objLeft = obj.offsetLeft;
        var objTop = obj.offsetTop;
        var objHeight = obj.offsetHeight;
        var objWidth = obj.offsetWidth;
        var objParent = obj.offsetParent;
        while (objParent.tagName.toUpperCase() != "BODY") {
            objLeft += objParent.offsetLeft;
            objTop += objParent.offsetTop;
            objParent = objParent.offsetParent;
        }
        line_width = objWidth;
        line_height = objHeight;
        line_left = objLeft;
        line_top = objTop;
    }

    /*
     *    程序效果:Javascript js 画线、画点、曲线图封装类
     *    程序设计:lxs_lingting 11-11-25
     *    邮箱:525909366@qq.com
     *    个人主页:http://www.xiaolanhu.com/
     */
    /*
     *    11-12-12 修改
     *    当横坐标差值与纵坐标差值相差太多时程虚线
     */


    //主调 set_line(x1,y1[,x2,y2,title])
    function draw_line(id) {
        this.o = document.getElementById(id);
        this.k = null;
        this.b = null;
        this.l = 0;
        this.t = 0;
        this._max = 1;//线条的粗细
        this._color = "#cccccc";//线条颜色
        this.get_offset();//获取主层位置
        this.state = true;//给予的坐标是否相对于当前层 默认为true
    }

    //获取公式参数值
    draw_line.prototype.get_gs = function (x1, y1, x2, y2) {
        this.k = (y1 - y2) / (x1 - x2);
        this.b = y1 - (y1 - y2) / (x1 - x2) * x1;
        this.k = this.k ? this.k : 0;
        this.b = this.b ? this.b : 0;
    }

    //获取y坐标 y=kx+b x=(y-b)/k
    draw_line.prototype.get_y = function (x) {
        return this.k * x + this.b;
    };

    //获取x坐标
    draw_line.prototype.get_x = function (y) {
        return (y - this.b) / this.k;
    };


    //获取主层位置
    draw_line.prototype.get_offset = function () {
        var obj = this.o;
        this.l = obj.offsetLeft, this.t = obj.offsetTop;
        if (document.all) {
            this.l += 11;
            while (obj.parentNode && obj.parentNode.tagName != "BODY") {
                obj = obj.parentNode;
                this.l += obj.offsetLeft;
                this.t += obj.offsetTop;
            }
        }
    }

    //生成点
    draw_line.prototype.set_div = function () {
        var _x = arguments[0], _y = arguments[1];
        var div = document.createElement("div");
        if (!document.all) {
            this.get_offset();
        }
        if (this.state) {
            _x += this.l;
            _y += this.t;
        }
        with (div.style) {
            line_width = this._max + "px";
            line_height = this._max + "px";
            backgroundColor = this._color;
            position = "absolute";
            overflow = "hidden";
            line_left = _x + "px";
            line_top = _y + "px";
            zIndex = 99999;
        }
        //if(arguments.length==3 && arguments[2]){
        if (arguments[2]) {
            //div.title=arguments[2];
            div.style.cursor = "pointer";
            div.style.zIndex = 100000;
            var c = div.style.backgroundColor;
            div.onmouseover = function () {
                this.style.backgroundColor = "#0000ff";
            };
            div.onmouseout = function () {
                this.style.backgroundColor = c;
            };
        }
        document.body.appendChild(div);
    }

    //循环点成线
    draw_line.prototype.set_line = function () {
        var x1, y1, x2, y2, arg = arguments;
        if (arg.length == 4) {
            x1 = arg[0];
            y1 = arg[1];
            x2 = arg[2];
            y2 = arg[3];
        } else {
            x1 = x2 = arg[0];
            y1 = y2 = arg[1];
        }
        this.get_gs(x1, y1, x2, y2);
        if (x1 == x2 && y1 == y2) {
            this.set_div(x1 - Math.floor(this._max / 2), y1 - Math.floor(this._max / 2), arg[2]);
        } else {
            if (x1 == x2) {
                for (var i = Math.min(y1, y2); i <= Math.max(y1, y2); i++) {
                    this.set_div(x1, i);
                }
            } else {
                if (x1 > x2) {
                    var _x = x1;
                    var _y = y1;
                    x1 = x2;
                    y1 = y2;
                    x2 = _x;
                    y2 = _y;
                }
                if (Math.abs(x1 - x2) > Math.abs(y1 - y2) || y1 == y2) {
                    for (var i = x1; i <= x2; i++) {
                        this.set_div(i, this.get_y(i));
                    }
                } else {
                    for (var j = Math.min(y1, y2); j <= Math.max(y1, y2); j++) {
                        this.set_div(this.get_x(j), j);
                    }
                }
            }
        }
    }
    //直角三角形的斜边长度
    function getSidelong(sideA, sideB) {
        var sidB2 = sideA * sideA + sideB * sideB;
        return Math.sqrt(sidB2);
    }

    function drawHeaderLine() {
        var dl = new draw_line("report1");
        //dl.state=false;//注释放开则给出的坐标按相对于body计算
        var table = document.getElementById("report1");
        var frow = null;
        if (table != null && table.rows.length > 0) {
            frow = table.rows[0];
        }
        var cell = null;
        if (frow != null && frow.cells.length > 0)cell = frow.cells[0];
        if (cell != null) {
            getBounds(cell);
            var rows = 1;
            if (cell.rowSpan != null && cell.rowSpan != "")rows = parseInt(cell.rowSpan);
            var cols = 1;
            if (cell.colSpan != null && cell.colSpan != "")cols = parseInt(cell.colSpan);

            var argHeight = height / rows;
            for (var i = 1; i <= rows; i++) {
                dl.set_line(-12, 0, width - 11, argHeight * i);
            }
            var argWidth = width / cols;
            for (var i = 1; i < cols; i++) {
                dl.set_line(-12, 0, argWidth * i + 10, height);
            }
        }
    }
    //drawHeaderLine();
    $(document).ready(function () {
        //处理查询字段控件样式
        setTagTdClass();
        resetwidth();
    });

    function resetwidth(){
        var table = $(".report_blue_tab");
        var tableW = table[0].scrollWidth;
        var fullWidth = document.body.offsetWidth;
        if(tableW > fullWidth) {
            var thWidth = 0;
            var header = $("tr:first", table);
            $("th", header).each(function (index) {
                var actualW = this.scrollWidth;
                if (actualW > 300) {
                    actualW = 300;
                    $("td:eq(" + index + ")", header.nextAll()).each(function () {
                        $(this).css({
                            "word-wrap": "break-word",
                            "word-break": "break-all",
                            "max-width": "300px",
                            "white-space": "normal"
                        });
                    });
                }
                thWidth += actualW;
            });
            if(thWidth > fullWidth){
                table.css("width",thWidth);
            }

        }
    }


    function setTagTdClass() {
        $("#filterTable").find("input[name=orgType]").each(function () {
            $(this).parent().attr("class", "organizetree_style");
        });
        $("#filterTable").find("input[name=dateType]").each(function () {
            $(this).parent().attr("class", "date_style");
        });
        $("#filterTable").find("input[name=comboType]").each(function () {
            $(this).parent().attr("class", "combo_style");
        });
        $("#filterTable").find("input[name=textType]").each(function () {
            $(this).parent().attr("class", "text_style");
        });
    }


    function selectField() {
       /* debugger;
        //拿到所选的字段中文名和字段名
        var selectNames = [];
        var selectFields = [];
        $(function(){
            $("#searchForm").find(":checkbox:checked").each(function(){
                var selectName = $(this).attr('name');
                console.log('-----val----' + selectName);
                selectNames.push(selectName);
                var selectField = $(this).attr('id');
                console.log('-----val----' + selectField);
                selectFields.push(selectField);
            });
        });
        selectNames = selectNames.toString();
        selectFields = selectFields.toString();
        console.log('-----selectNames----' + selectNames);
        console.log('-----selectFields----' + selectFields);
        /!*if (selectNames.length <= 0){
            top.FETOP.Dialog.warn("查询字段不能为空,请选择字段进行报表查询");
            return false;
        }*!/
        $("#selectFields").val(selectFields);
        $("#selectNames").val(selectNames);*/
    }

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