ajax之分页

来源:互联网 发布:纪录片知乎 编辑:程序博客网 时间:2024/05/22 02:25

前台页面:

<%@ page contentType="text/html; charset=GBK"%><%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%><%@ taglib uri="/WEB-INF/tld/utiltags.tld" prefix="util"%><script type="text/javascript"src="<%=request.getContextPath()%>/js/common.js"></script><script language="javascript"src="<%=request.getContextPath()%>/js/xmlcommon.js"></script><script type="text/javascript"src="<%=request.getContextPath()%>/css/tabber.js"></script><script language="javascript"src="<%=request.getContextPath()%>/js/calendar.js"></script><link rel="stylesheet"href="<%=request.getContextPath()%>/css/example.css" TYPE="text/css"MEDIA="screen" /><link rel="stylesheet"href="<%=request.getContextPath()%>/css/style.css" type="text/css" /><script language="javascript"src="<%=request.getContextPath()%>/js/jquery-1.3.2.min.js"></script><head><util:message /><meta http-equiv="Content-Type" content="text/html; charset=GBK"><title>电话销售系统</title></head><body><form name="form1" method="post" action=""><table width="99%" border="0" align="center" cellpadding="0"cellspacing="0"><tr><td width="22" height="32"background="<%=request.getContextPath()%>/images/main/frame_q.jpg"> </td><tdbackground="<%=request.getContextPath()%>/images/main/frame_w.jpg"class="MainTitle"><!-- 呼入控制数据设置 --> 呼入屏蔽设置</td><td width="22" height="32"background="<%=request.getContextPath()%>/images/main/frame_e.jpg"> </td></tr><tr><tdbackground="<%=request.getContextPath()%>/images/main/frame_a.jpg"> </td><td valign="top" bgcolor="#EFEFEF"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td> </td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"bgcolor="#EFEFEF"><tr><td class="SecondTitle">.:设置查询:.</td></tr><tr><td bgcolor="#999999"><table name="tableA" border="0" cellspacing="1" cellpadding="1"width="100%"><tr width="100%"><td width="14%" align="right" class="general-td">数据来源:</td><td align="left" class="general-td"><selectname="dataSource" class="selectCtrl" id="dataSource"><option value="">全部</option><option value="1" <c:if test='${result.blackListDTO.dataSource == "1"}'>selected</c:if>>电销系统</option><option value="2" <c:if test='${result.blackListDTO.dataSource == "2"}'>selected</c:if>>承保系统</option></select></td><td width="14%" align="right" class="general-td">类型:</td><td align="left" class="general-td"><selectname="type" class="selectCtrl" id="type"><option value="">全部</option><option value="1-1" <c:if test='${result.blackListDTO.type == "1-1"}'>selected</c:if>>黑名单(电销)</option><option value="1-2" <c:if test='${result.blackListDTO.type == "1-2"}'>selected</c:if>>黑名单(承保)</option><option value="2" <c:if test='${result.blackListDTO.type == "2"}'>selected</c:if>>号码屏蔽</option></select></td></tr><tr width="100%"><td width="14%" align="right" class="general-td">类型明细:</td><td align="left" class="general-td"><selectname="typeDetail" class="selectCtrl" id="typeDetail"><option value="">全部</option><c:forEach var="blackList"items="${result.blackListRemarkList}"><option value='<c:out value="${blackList.paramId}"/>' <c:if test="${result.blackListDTO.typeDetail == blackList.paramId}">selected</c:if>><c:out value="${blackList.paramValue}" /></option></c:forEach><option value="hc" <c:if test='${result.blackListDTO.typeDetail == "hc"}'>selected</c:if>>呼出</option><option value="dx" <c:if test='${result.blackListDTO.typeDetail == "dx"}'>selected</c:if>>短信</option></select></td><td width="14%" align="right" class="general-td">是否屏蔽:</td><td align="left" class="general-td"><selectname="isExcluded" class="selectCtrl" id="isExcluded"><option value="">全部</option><option value="1" <c:if test='${result.blackListDTO.isExcluded == "1"}'>selected</c:if>>是</option><option value="0" <c:if test='${result.blackListDTO.isExcluded == "0"}'>selected</c:if>>否</option></select></td></tr><tr width="100%"><td colspan="4" align="right" class="general-td"><inputname="efdag3" type="button" class="btn" value="查询"onclick="searchCallInControlDataList();"></td></tr></table></td></tr></table><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td> </td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"bgcolor="#EFEFEF"><tr><td class="SecondTitle">.:查询结果:.</td></tr><tr><td bgcolor="#999999"><table name="tableB" border="0" cellspacing="1" cellpadding="1"width="100%"><tr width="100%"><td width="10%" align="center" bgcolor="#DFE0E4" class="title-td">选择<input type="checkbox" name="checkAll" id="checkAll" onclick="gotoCheckAll(this);"></td><td width="10%" align="center" bgcolor="#DFE0E4"class="title-td">数据来源</td><td width="10%" align="center" bgcolor="#DFE0E4"class="title-td">类型</td><td width="10%" align="center" bgcolor="#DFE0E4"class="title-td">类型明细</td><td width="10%" align="center" bgcolor="#DFE0E4"class="title-td">是否屏蔽</td><td width="10%" align="center" bgcolor="#DFE0E4"class="title-td">最新操作时间</td></tr><c:forEach var="black" items="${result.blackList}"><tr width="100%">    <td style="display:none;"><input type="hidden" name="id" value='<c:out value="${black.id}"/>'></td><td width="7%" align="center" class="general-td"><inputtype="checkbox" name="toBeEdited"></td><td width="7%" align="center" class="general-td" id="dataSource1" style="color:<c:if test='${empty black.isExcluded}'>red;</c:if>"><c:if test="${black.dataSource == 1}">电销系统</c:if><c:if test="${black.dataSource == 2}">承保系统</c:if></td><td width="6%" align="center" class="general-td" id="type1"style="color:<c:if test='${empty black.isExcluded}'>red;</c:if>"><c:if test='${black.type == "1-1" || black.type == "1-2"}'>黑名单</c:if><c:if test='${black.type == "2"}'>号码屏蔽</c:if></td><td width="9%" align="center" class="general-td" id="tyepDetail1"style="color:<c:if test='${empty black.isExcluded}'>red;</c:if>"><c:forEach var="blackList" items="${result.blackListRemarkList}"><c:if test='${blackList.paramId == black.typeDetail}'><c:out value="${blackList.paramValue}" /></c:if></c:forEach></td><td align="center" class="general-td"><c:if test="${black.isExcluded == 1}">是</c:if><c:if test="${black.isExcluded == 0}">否</c:if></td><td align="center" class="general-td"><c:out value="${black.updatedDate}"/></td></tr></c:forEach><tr><td align="right" class="general-td" colspan="9"><inputname="efdag2" type="button" class="btn" value="修改" onclick="edit();"></td></tr><tr><td class="general-td" colspan="9"><table id="table1" align="center" width="500" border="0"cellpadding="0" cellspacing="0"><tr><td id="td1" align="center" valign="middle"><inputtype="hidden" name="pageTotal" id="pageTotal1"value='<c:out value="${result.totalPage}" />'> <span> 共 <c:outvalue="${result.totalPage}" />  页 </span> <input type=button name="prevPage1" value="上一页" id="prevPage1"onClick="gotoPrevPage1()" class="btn2"> <input id="nextPage1"type=button name="nextPage1" value="下一页"onclick="gotoNextPage1();" class="btn2"> <input id="jump1"type=button name="jump1" value="跳至" onclick="gotoJump1()"class="btn2"> <span> 第 <input id="pageNo1"name="pageNo" style="text-align: center"value='<c:out value="${result.pageNo}" />'class="inputbg3"></span> 页</td></tr></table></td></tr></table></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"bgcolor="#EFEFEF"><tr><td class="SecondTitle">.:临时数据处理:.</td></tr><tr><td bgcolor="#999999"><table name="tableA" border="0" cellspacing="1" cellpadding="1"width="100%"><tr width="100%"><td width="14%" align="center" class="general-td">电话号码:</td><td width="38%" align="left" class="general-td"><input id="phoneNo"maxlength="15" name="phoneNo" type="text" class="inputbg"></td></tr><tr width="100%"><td colspan="4" align="right" class="general-td"><input id="query2"name="efdag3" type="button" class="btn" value="查询"onclick="searchCallInControlDataListByPhoneNo(this);"></td></tr></table></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"bgcolor="#EFEFEF"><tr><td bgcolor="#999999"><table name="tableA" border="0" cellspacing="1" cellpadding="1"width="100%"><tr width="100%" id="insert"><td width="10%" align="center" bgcolor="#DFE0E4"class="title-td">电话号码</td><td width="10%" align="center" bgcolor="#DFE0E4"class="title-td">数据来源</td><td width="10%" align="center" bgcolor="#DFE0E4"class="title-td">类型</td><td width="10%" align="center" bgcolor="#DFE0E4"class="title-td">类型明细</td><td width="10%" align="center" bgcolor="#DFE0E4"class="title-td">状态</td><td width="10%" align="center" bgcolor="#DFE0E4"class="title-td">创建时间</td><td width="10%" align="center" bgcolor="#DFE0E4"class="title-td">更新时间</td><td width="10%" align="center" bgcolor="#DFE0E4"class="title-td">操作</td></tr><tr><td class="general-td" colspan="9"><table id="table1" align="center" width="500" border="0"cellpadding="0" cellspacing="0"><tr><td style="display:none;"><input type="hidden" id="hiddenPageNo2"></td><td id="td1" align="center" valign="middle"> 共 <span id="pageTotal2">0</span> 页 <input type=button name="prevPage2" value="上一页" id="prevPage2"onClick="searchCallInControlDataListByPhoneNo(this)" class="btn2" disabled="disabled"> <inputtype=button name="nextPage2" value="下一页" id="nextPage2"onClick="searchCallInControlDataListByPhoneNo(this)" class="btn2" disabled="disabled"> <input id="jump2"type=button name="jump2" value="跳至" onclick="searchCallInControlDataListByPhoneNo(this)"class="btn2" disabled="disabled"> 第  <span> <input name="pageNo2" style="text-align: center" value="0" class="inputbg3" id="pageNo2">    </span>     页    </td></tr></table></td></tr></table></td></tr></table></td></tr></table></form></body><script type="text/javascript">var pageNo = $("#pageNo1").val();var dataSource = $("#dataSource").val();var type = $("#type").val();var typeDetail = $("#typeDetail").val();var isExcluded = $("#isExcluded").val(); if($("#pageTotal1").val() <= "1"){$("#prevPage1").attr("disabled","disabled");$("#nextPage1").attr("disabled","disabled");$("#jump1").attr("disabled","disabled");}else{if(pageNo == $("#pageTotal1").val()){$("#nextPage1").attr("disabled","disabled");}else if(pageNo == "1"){$("#prevPage1").attr("disabled","disabled");}}function gotoPrevPage1(){   pageNo = parseInt($("#pageNo1").val());   if(pageNo > 1)   {    pageNo=pageNo-1; window.location.href="<%=request.getContextPath()%>/callInControlData.goto.do?dataSource="    +dataSource+"&type="+type+"&typeDetail="+typeDetail+"&isExcluded="+isExcluded+"&pageNo="+pageNo;   } }function gotoNextPage1(){  pageNo = parseInt($("#pageNo1").val()); if(pageNo < $("#pageTotal1").val()) {pageNo = parseInt(pageNo) + 1;window.location.href="<%=request.getContextPath()%>/callInControlData.goto.do?dataSource="    +dataSource+"&type="+type+"&typeDetail="+typeDetail+"&isExcluded="+isExcluded+"&pageNo="+pageNo; }}function gotoJump1(){var temp = pageNo;pageNo = $("#pageNo1").val();if(isNaN(pageNo) || parseInt(pageNo) > $("#pageTotal1").val() || parseInt(pageNo) < 1){alert("您输入的页数不存在!");return false;}window.location.href="<%=request.getContextPath()%>/callInControlData.goto.do?dataSource="    +dataSource+"&type="+type+"&typeDetail="+typeDetail+"&isExcluded="+isExcluded+"&pageNo="+pageNo;}function searchCallInControlDataList(){dataSource = $("#dataSource").val();type = $("#type").val();typeDetail = $("#typeDetail").val();isExcluded = $("#isExcluded").val();window.location.href = "<%=request.getContextPath()%>/callInControlData.goto.do?dataSource="    +dataSource+"&type="+type+"&typeDetail="+typeDetail+"&isExcluded="+isExcluded;}function edit(){var toBeEdited = $('input[name="toBeEdited"]:checked');if(toBeEdited.length == 0){alert("请至少选择一条记录!");return;}var ids = new Array();for(var i = 0 ; i < toBeEdited.length ; i++){var _ids = toBeEdited.parent().prev().children();ids.push(_ids[i].value);}window.location.href="<%=request.getContextPath()%>/callInControlData.goto.do?flag=edit&ids="+ids;}function gotoCheckAll(obj){if(obj.checked){$('input[name="toBeEdited"]').attr("checked","checked");}else{$('input[name="toBeEdited"]').attr("checked","");}}function searchCallInControlDataListByPhoneNo(obj){var pageNo;if(obj.id == "query2"){pageNo = "1"; }else if(obj.id == "prevPage2"){pageNo = parseInt($("#hiddenPageNo2").val())-1;if(pageNo == 1){$("#prevPage2").attr("disabled","disabled");}}else if(obj.id == "nextPage2"){pageNo = parseInt($("#hiddenPageNo2").val())+1;if(pageNo == parseInt($("#pageTotal2").html())){$("#nextPage2").attr("disabled","disabled");}}else if(obj.id == "jump2"){if(isNaN($("#pageNo2").val()) || $("#pageNo2").val() < 1 || $("#pageNo2").val() > $("#pageTotal2").html()){alert("您输入的页数不存在!");return;}else{pageNo = $("#pageNo2").val();}}$.ajax({url:"<%=request.getContextPath()%>/callInControlData.goto.do",data:{flag:"queryByPhone",phoneNo:$("#phoneNo").val(),pageNo:pageNo},dataType:"json",type:"post",success:function(data){$("#pageTotal2").html(Math.ceil(data[0].pageTotal/10));if($("#pageTotal2").html() != 0){$("#pageNo2").val(pageNo);$("#hiddenPageNo2").val(pageNo);if($("#pageTotal2").html() > 1){if(pageNo != 1){$("#prevPage2").attr("disabled","");if(pageNo != $("#pageTotal2").html()){$("#nextPage2").attr("disabled","");}}else{$("#nextPage2").attr("disabled","");$("#jump2").attr("disabled","");}}}var dataSource = "";var type = "";var typeDetail = "";var validFlag = "";$('tr[name="dataInserted"]').remove();for(var i = 0 ; i < data[0].blackList.length ; i++){if(data[0].blackList[i].dataSource == "1"){dataSource = "电销系统";}else if(data[0].blackList[i].dataSource == "2"){dataSource = "承保系统";}if(data[0].blackList[i].type == "1-1" || data[0].blackList[i].type == "1-2"){type = "黑名单";}else if(data[0].blackList[i].type == "2"){type = "号码屏蔽";}if(data[0].blackList[i].validFlag == "1"){validFlag = "有效";}else if(data[0].blackList[i].validFlag == "0"){validFlag = "无效";}for(var j = 0 ;j < data[0].blackListRemarkList.length ; j++){if(data[0].blackList[i].typeDetail == data[0].blackListRemarkList[j].paramId){typeDetail = data[0].blackListRemarkList[j].paramValue;break;}}$('<tr width="100%" name="dataInserted">'+'<td align="center" class="general-td">'+data[0].blackList[i].phoneNo+'</td>'+'<td align="center" class="general-td">'+dataSource+'</td>'+'<td align="center" class="general-td">'+type+'</td>'+'<td align="center" class="general-td">'+typeDetail+'</td>'+'<td align="center" class="general-td">'+validFlag+'</td>'+'<td align="center" class="general-td">'+data[0].blackList[i].createdDate+'</td>'+'<td align="center" class="general-td">'+data[0].blackList[i].updatedDate+'</td>'+'<td align="center" class="general-td"><input type="button" value="解锁呼入" class="btn"></td>'+'</tr>').insertAfter($("#insert"));}},error:function(data){alert("系统异常,请联系管理员!");}});}</script>

后台java:

package com.tpaic.callCenter.web.controller.comeInControlData;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import net.sf.json.JSONArray;import org.apache.java.lang.Bytes;import org.springframework.web.servlet.ModelAndView;import com.tpaic.callCenter.biz.util.SqlNamesUtil;import com.tpaic.callCenter.dto.CodeTableDTO;import com.tpaic.callCenter.dto.blackList.BlackListDTO;import com.tpaic.callCenter.util.StringUtil;import com.tpaic.callCenter.web.controller.common.AbstractCommonController;import com.tpaic.callCenter.web.util.CommonUtils;import com.tpaic.callCenter.web.util.ServiceRequestId;/** * @author ex_zhangkenan * 呼入控制数据设置 */public class CallInControlDataGotoController extends AbstractCommonController{private String editView;public String getEditView() {return editView;}public void setEditView(String editView) {this.editView = editView;}protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {Map<String,Object> resultMap = new HashMap<String,Object>();String flag = request.getParameter("flag");if(flag == null){//查询电销系统黑名单原因列表@SuppressWarnings("unchecked")List<Object> blackListRemarkList = (List<Object>) this.getDispatch().dispatchRequest(CommonUtils.getAggregatedSearchDTO(SqlNamesUtil.CODETABLE_SEARCH_CODETYPE, "blackListRemark"),ServiceRequestId.AGGREGATED_SEARCH_ACTION);resultMap.put("blackListRemarkList", blackListRemarkList);//查询电销系统blacklist表String pageNo = request.getParameter("pageNo");String dataSource = request.getParameter("dataSource");String type = request.getParameter("type");String typeDetail = request.getParameter("typeDetail");String isExcluded = request.getParameter("isExcluded");BlackListDTO blackListDTO = new BlackListDTO();if(StringUtil.isEmpty(pageNo)){blackListDTO.setPageNo(1);}else{blackListDTO.setPageNo(Integer.parseInt(pageNo));}blackListDTO.setDataSource(dataSource);blackListDTO.setType(type);blackListDTO.setTypeDetail(typeDetail);blackListDTO.setIsExcluded(isExcluded);String totalPage = (String) this.getDispatch().dispatchRequest(CommonUtils.getAggregatedSearchDTO(SqlNamesUtil.Search_Blacklist_For_Total_Page, blackListDTO,false),ServiceRequestId.AGGREGATED_SEARCH_ACTION);@SuppressWarnings("unchecked")List<BlackListDTO> blackList = (List<BlackListDTO>) this.getDispatch().dispatchRequest(CommonUtils.getAggregatedSearchDTO(SqlNamesUtil.Search_Blacklist_For_List, blackListDTO),ServiceRequestId.AGGREGATED_SEARCH_ACTION);resultMap.put("pageNo", blackListDTO.getPageNo());resultMap.put("totalPage", totalPage);resultMap.put("blackList", blackList);resultMap.put("blackListDTO", blackListDTO);return new ModelAndView(this.getSuccessView(), "result", resultMap);}else if(flag.equals("edit")){String ids = request.getParameter("ids");@SuppressWarnings({ "unchecked" })List<BlackListDTO> blackList = (List<BlackListDTO>) this.getDispatch().dispatchRequest(CommonUtils.getAggregatedSearchDTO(SqlNamesUtil.Search_Blacklist_For_List_By_Ids, ids),ServiceRequestId.AGGREGATED_SEARCH_ACTION);resultMap.put("blackList", blackList);@SuppressWarnings("unchecked")List<CodeTableDTO> blackListRemarkList = (List<CodeTableDTO>) this.getDispatch().dispatchRequest(CommonUtils.getAggregatedSearchDTO(SqlNamesUtil.CODETABLE_SEARCH_CODETYPE, "blackListRemark"),ServiceRequestId.AGGREGATED_SEARCH_ACTION);resultMap.put("blackListRemarkList", blackListRemarkList);return new ModelAndView(this.getEditView(), "result", resultMap);}else if(flag.equals("save")){String ids = request.getParameter("ids");String isOrNotExcluded = request.getParameter("isOrNotExcluded");List<BlackListDTO> blackListDTO = new ArrayList<BlackListDTO>();for(int i = 0 ; i < ids.split(",").length ; i++){BlackListDTO dto = new BlackListDTO();dto.setId(ids.split(",")[i]);dto.setIsExcluded(isOrNotExcluded.split(",")[i]);blackListDTO.add(dto);}String data = "1";Map<String,Object> map = new HashMap<String, Object>();map.put("blackListDTO", blackListDTO);try{this.getDispatch().dispatchRequest(map, ServiceRequestId.UPDATE_BLACK_LIST_FOR_ISEXCLUDED_ACTION);}catch(Exception e){data = "0";}response.getWriter().write(data);return null;}else if(flag.equals("queryByPhone")){String phoneNo = request.getParameter("phoneNo");String pageNo = request.getParameter("pageNo");BlackListDTO dto = new BlackListDTO();dto.setPhoneNo(phoneNo);dto.setPageNo(Integer.parseInt(pageNo));@SuppressWarnings("unchecked")List<BlackListDTO> blackList = (List<BlackListDTO>) this.getDispatch().dispatchRequest(CommonUtils.getAggregatedSearchDTO(SqlNamesUtil.Search_Blacklist_For_List_By_Phone, dto),ServiceRequestId.AGGREGATED_SEARCH_ACTION);String pageTotal = (String) this.getDispatch().dispatchRequest(CommonUtils.getAggregatedSearchDTO(SqlNamesUtil.Search_Blacklist_By_Phone_For_Num, phoneNo,false),ServiceRequestId.AGGREGATED_SEARCH_ACTION);@SuppressWarnings("unchecked")List<CodeTableDTO> blackListRemarkList = (List<CodeTableDTO>) this.getDispatch().dispatchRequest(CommonUtils.getAggregatedSearchDTO(SqlNamesUtil.CODETABLE_SEARCH_CODETYPE, "blackListRemark"),ServiceRequestId.AGGREGATED_SEARCH_ACTION);Map<String,Object> map = new HashMap<String, Object>();map.put("blackList", blackList);map.put("blackListRemarkList", blackListRemarkList);map.put("pageTotal", pageTotal);JSONArray jsonArray = JSONArray.fromObject(map);response.setCharacterEncoding("UTF-8");response.getWriter().write(jsonArray.toString());return null;}return new ModelAndView(this.getSuccessView(), "result", resultMap);}}
效果:


0 0