使用light7库无线滚动加载

 
  


界面:



点击查询后执行的js 先查出5条数据 php代码 controller

	public function wlselect(){
		$mc = I('mc','');
		$lx = I('lx',1);
		$begin_rq = I('begin_rq','');
		$end_rq = I('end_rq','');
		$page = I('page',1);
		$num = I('num',5);

	

		$sql = '';
		if($lx == 1){
			if($mc != '' and $mc!= '所有客户'){
				$sql .= " and khmc = '$mc' ";
			}
			if($begin_rq != '' and $end_rq != ''){
				$sql .= " and riqi between '$begin_rq' and '$end_rq' ";
			}
			
			$wl = D('Bj')->wlbj($sql,$num,$page,'wlxsgzbj');

			$this->fz($wl,'khwlbj',$sql);
}
}

//根据参数(查询语句)封装数据并返回
	public function fz($sql,$lx,$tj){
		$result = M()->query($sql);
		switch ($lx) {
			case 'khwlbj':
				$sqlcount = "select count(id)count from wlxsgzbj where 1=1 $tj ";
				$count = M()->query($sqlcount);
				$count = $count[0]['count'];
				break;
			
			default:
				# code...
				break;
		}
		if($result){
			$json = $result;
			$json['length'] = count($result);
			$json['count'] = $count;
			$json['status'] = 1;
		}else{
			$json['status'] = 0;
		}
		//$json['sql'] = $sql;
		$this->ajaxReturn($json,'json');
	}


model 使用的sql server数据库
/**
	 * 物料报价
	 */
	public function wlbj($data,$num,$page,$table){
		$sql = "SELECT id,mc,wlmc,jg,lsjg,zgj,zdj,rq,gg,ysmc
				FROM
				    (
				        SELECT ROW_NUMBER() OVER (ORDER BY id) AS RowNumber,id,gg,khmc as mc,wlmc,jg,lsjg,zgj,zdj,convert(char(10),riqi,120) as rq,ysmc FROM $table where 1=1 $data
				    )   as A  
				WHERE RowNumber between $page and $num";
		return $sql;
	}


/*
 * 物料报价
 */
function wlbj() {
	//删除所有子元素
	removeAllChild('wlbj_content');
	if ($('#lx').val() == '1') {
		var mc = $(".inkhmc").val();
	} else if ($('#lx').val() == '2') {
		var mc = $(".inghsmc").val();
	} else if ($('#lx').val() == '3') {
		var mc = $(".injgsmc").val();
	}
	var lx = $("#lx").val();
	var begin_rq = $("[name='begin_rq']").val();
	var end_rq = $("[name='end_rq']").val();
	var url = getUrl(location.href);
	pagenum = 1;
	num = 5;
	$.showIndicator();
	disbtn();
	$.getJSON(
		url, {
			mc: mc,
			lx: lx,
			begin_rq: begin_rq,
			end_rq: end_rq
		},
		function(json) {
			if (json.status == 1) {
				//	如果总数大于5 则开启滚动加载
				if (json.count > 5) {
					lastIndex = 5;
					$.attachInfiniteScroll($('.infinite-scroll'));
					maxItems = json.count;
				}
				$.hideIndicator();
				btn();
				for (var i = 0; i < json.length; i++) {
					$('.list-container').append("
:" + json[i]['mc'] + ":" + json[i]['rq'] + "
:" + json[i]['wlmc'] + "历史价:" + parseFloat(json[i]['lsjg']) + "元
:" + json[i]['gg'] + "最高价:" + parseFloat(json[i]['zgj']) + "元
:" + json[i]['ysmc'] + "最低价:" + parseFloat(json[i]['zdj']) + "元
:" + parseFloat(json[i]['jg']) + "元
"); } } if (json.status == 0) { $.hideIndicator(); btn(); $.toast("未找到相应的记录"); } }); }


无限滚动js

$(document).on("pageInit", "#baojia-wl", function(pageId, $page) {
    // 上次加载的序号
	lastIndex = 5;
	// 加载flag
	var loading = false;
	var url = ThinkPHP['MODULE'] + '/Bj/wlselect';

	
	function addItems() {
		pagenum += 5;
		num += 5;
		
		if ($('#lx').val() == '1') {
			var mc = $(".inkhmc").val();
		} else if ($('#lx').val() == '2') {
		var mc = $(".inghsmc").val();
		} else if ($('#lx').val() == '3') {
			var mc = $(".injgsmc").val();
		}
		var lx = $("#lx").val();
		var begin_rq = $("[name='begin_rq']").val();
		var end_rq = $("[name='end_rq']").val();
		var url = getUrl(location.href);

$.getJSON(url, {mc: mc,lx: lx,page: pagenum,num: num,begin_rq: begin_rq,end_rq: end_rq},function(json) {if (json.status == 1) {for (var i = 0; i < json.length; i++) {$('.list-container').append("
:" + json[i]['mc'] + ":" + json[i]['rq'] + "
:" + json[i]['wlmc'] + "历史价:" + parseFloat(json[i]['lsjg']) + "元
:" + json[i]['gg'] + "最高价:" + parseFloat(json[i]['zgj']) + "元
:" + json[i]['ysmc'] + "最低价:" + parseFloat(json[i]['zdj']) + "元
:" + parseFloat(json[i]['jg']) + "元
");}}});}// 注册'infinite'事件处理函数$(document).on('infinite', '.infinite-scroll-bottom', function() {// 如果正在加载,则退出if (loading) return;$('.infinite-scroll-preloader').show();// 设置flagloading = true;// 模拟1s的加载过程setTimeout(function() {// 重置加载flagloading = false;if (lastIndex >= maxItems) {// 加载完毕,则注销无限加载事件,以防不必要的加载$.detachInfiniteScroll($('.infinite-scroll'));// 删除加载提示符$('.infinite-scroll-preloader').hide();$.toast("已到达最底部");return;}// 添加新条目addItems();// 更新最后加载的序号lastIndex += 5;}, 1000);});}
 
  

你可能感兴趣的:(使用light7库无线滚动加载)