<script type="text/javascript">
$(document).ready(function() {
getCustomerList(1,10);//默认:第一页,每页十条数据
});
function changePage(){
var curr=$("#currPage").val();
var size=$("#size").val();
var r=/^[0-9]*[1-9][0-9]*$/;//正整数匹配
if(!r.test(curr))
curr=1;
if(!r.test(size))
size=10;
getCustomerList(curr,size);
}
// 删除客户信息
function delCust(id,msg) {
if (window.confirm("确认删除" + msg + "?")){
$.ajax({
type:"post",
url:"cust.do?operate=doDelCust",
data:{id:id},
dataType:"json",
error:function(data){
getCustomerList($("#currPage").val(),$("#size").val());
creatBgDiv(data);
}
});
}
}
</script>
<tr id="divCustomerList"><td colspan="7"><center><img src="/CRMPro/images/loading.gif"/><strong>数据获取中.....</strong></center></td></tr>
<!-- 数据模板 -->
<tr id="divCustomerTemp" style="display:none;">
<td class="list_data_number"><span id="No"><!-- 序号 --></span></td>
<td class="list_data_text"><span id="custNo"><!-- 客户编号 --></span></td>
<td class="list_data_text"><span id="custName"><!-- 客户名称 --></span></td>
<td class="list_data_ltext"><span id="custRegion"><!--客户地区 --></span></td>
<td class="list_data_text"><span id="custManagerName"><!--客户经理--></span></td>
<td class="list_data_text"><span id="custLevelLabel"><!--客户等级--></span></td>
<td class="list_data_op">
<a id="imgEdit" ><img title="编辑" alt="编辑" src="/CRMPro/images/bt_edit.gif" class="op_button" /></a>
<a id="imgLinkMan"><img title="联系人" alt="联系人" src="/CRMPro/images/bt_linkman.gif" class="op_button" /></a>
<a id="imgActivities"><img title="交往记录" alt="交往记录" src="/CRMPro/images/bt_acti.gif" class="op_button" /></a>
<a id="imgOrders"><img title="历史订单" alt="历史订单" src="/CRMPro/images/bt_orders.gif" class="op_button" /></a>
<a id="imgDel"><img title="删除" alt="删除" src="/CRMPro/images/bt_del.gif" class="op_button" /></a>
</td>
</tr>
<tr>
<th colspan="100" class="pager">
<div class="pager" id="divPageCount" >
共<span id="count"></span>条记录
每页<input id="size" size="2" οnkeyup='changePage()' />条
第<input id="currPage" size="2" οnkeyup='changePage()'/>页/
共<span id="total"></span>页
<span id="divPageNav"></span>
</div>
</th>
</tr>
function getCustomerList(currPage,pageSize) {
$.get("cust.do?operate=doSearch",
{currPage :currPage,pageSize : pageSize,custNo:$("#custNo").val(),custName:$("#custName").val(),custRegion:$("#custRegion").val(),custManagerName:$("#custManagerName").val(),custLevelLabel:$("#custLevelLabel").val()},
function(data) {
var totalPages = parseInt((parseInt(data.count) + parseInt(pageSize) - 1) / pageSize); //
if(totalPages==0)
totalPages=1;
if(currPage>totalPages){
currPage=totalPages
getChanceList(currPage,pageSize);
}
$("#divCustomerList").text("");
$("#divPageNav").text("");
if(data.list!=null){
if(data.count!=0){
$.each(data.list, function(i, n) {
var element = $("#divCustomerTemp").clone();
element.find("#No").text(i+1);
element.find("#custNo").text(n.custNo);
element.find("#custName").text(n.custName);
element.find("#custRegion").text(n.custRegion);
element.find("#custManagerName").text(n.custManagerName);
element.find("#custLevelLabel").text(n.custLevelLabel);
element.find("#imgEdit").attr({href:"cust.do?operate=toCustEdit&custNo="+n.custNo});
element.find("#imgLinkMan").attr({href:"cust.do?operate=toLinkMan&custNo="+n.custNo+"&custName="+n.custName});
element.find("#imgActivities").attr({href:"cust.do?operate=toActivities&custNo="+n.custNo+"&custName="+n.custName});
element.find("#imgOrders").attr({href:"cust.do?operate=toOrders&custName="+n.custName+"&custNo="+n.custNo});
element.find("#imgDel").attr({href:"javascript:delCust('"+n.custNo+"','“客户名称:"+n.custName+"”');"});
element.show();
$("#divCustomerList").append(element);
});
$("#count").text(data.count);
$("#total").text(totalPages);
$("#currPage").val(parseInt(currPage));
$("#size").val(parseInt(pageSize));
initePageNav(parseInt(currPage),parseInt(pageSize),parseInt(totalPages), data.count, "getCustomerList", "divPageNav");
}else{
$("#divPageCount").hide();
$("#divCustomerList").html("<td colspan='7'><center>??。。。。。。。暂无数据。。。。。。。</center></td>");
}
}
},"json");
}
/*生成视频集合分页导航 (当前页),(每页元素量) ,(总页数)(数据总量),(换页方法),(元素容器)*/
function initePageNav(currentPage,pageSize,totalPages, totalCount, ajaxMethod, target) {
$("#divPageCount").show();
var output = '';
if (currentPage <= 0) currentPage = 1;
if (totalPages > 1) {
if (currentPage != 1) //处理首页连接
output += "<a href=/"javascript:" + ajaxMethod + "(1," + pageSize + ")/"style='border: none; background: none;' >首页</a>";
output += " ";
if (currentPage > 1)//处理上一页的连接
output += "<a href=/"javascript:" + ajaxMethod + "(" + (currentPage - 1) + "," + pageSize + ")/"style='border: none; background: none;'>上一页</a>";
else
output += "<span class='disabled'>上一页</span>";
output += " | <span class='page'>";
var currint = 5;
for (var i = 0; i <= 10; i++) {//一共最多显示10个页码,前面5个,后面5个
//alert(currentPage+"/"+totalPages);
if ((currentPage + i - currint) >= 1 && (currentPage + i - currint) <= totalPages)
if (currint == i) {//当前页处理
output += "<span class='current'>" + currentPage + "</span>";
output += " ";
}
else {//一般页处理
output += "<a href=/"javascript:" + ajaxMethod + "(" + (currentPage + i - currint) + "," + pageSize + ")/">" + (currentPage + i - currint) + "</a>";
output += " ";
}
}
if (currentPage < totalPages) //处理下一页的链接
output += "</span>| <a href=/"javascript:" + ajaxMethod + "(" + (currentPage + 1) + "," + pageSize + ")/"style='border: none; background: none;'>下一页</a>";
else
output += "</span>| <span class='disabled'>下一页</span>";
output += " ";
if (currentPage != totalPages)
output += "<a href=/"javascript:" + ajaxMethod + "(" + (totalPages) + "," + pageSize + ")/"style='border: none; background: none;'>末页</a>";
}
if (totalCount > 0) {
$("#" + target).text("");
$("#" + target).append(output);
}
}