Browse Source

浏览记录滚动加载

master
ZLW-PC\Administrator 7 years ago
parent
commit
25fce4e042
  1. 37
      app/Http/Controllers/Weixin/CollectGoodsController.php
  2. 31
      app/Http/Controllers/Weixin/UserController.php
  3. 2
      resources/views/weixin/user/index.blade.php
  4. 61
      resources/views/weixin/user/userGoodsHistory.blade.php
  5. 4
      routes/web.php

37
app/Http/Controllers/Weixin/CollectGoodsController.php

@ -0,0 +1,37 @@
<?php
namespace App\Http\Controllers\Weixin;
use App\Http\Controllers\Weixin\CommonController;
use Illuminate\Http\Request;
class CollectGoodsController extends CommonController
{
public function __construct()
{
parent::__construct();
}
//商品列表
public function goodslist(Request $request)
{
if($request->input('typeid', '') != ''){$data['typeid'] = $request->input('typeid');}
if($request->input('tuijian', '') != ''){$data['tuijian'] = $request->input('tuijian');}
if($request->input('keyword', '') != ''){$data['keyword'] = $request->input('keyword');}
if($request->input('status', '') != ''){$data['status'] = $request->input('status');}
if($request->input('is_promote', '') != ''){$data['is_promote'] = $request->input('is_promote');}
if($request->input('orderby', '') != ''){$data['orderby'] = $request->input('orderby');}
if($request->input('max_price', '') != ''){$data['max_price'] = $request->input('max_price');}else{$data['max_price'] = 99999;}
if($request->input('min_price', '') != ''){$data['min_price'] = $request->input('min_price');}else{$data['min_price'] = 0;}
//商品列表
$postdata = array(
'limit' => 10,
'offset' => 0
);
$url = env('APP_API_URL')."/goods_list";
$goods_list = curl_request($url,$postdata,'GET');
$data['goods_list'] = $goods_list['data']['list'];
return view('weixin.goods.goodslist', $data);
}
}

31
app/Http/Controllers/Weixin/UserController.php

@ -40,16 +40,41 @@ class UserController extends CommonController
public function userGoodsHistory(Request $request)
{
//商品列表
$pagesize = 10;
$offset = 0;
if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;}
$postdata = array(
'limit' => 10,
'offset' => 0,
'limit' => $pagesize,
'offset' => $offset,
'access_token' => $_SESSION['weixin_user_info']['access_token']
);
$url = env('APP_API_URL')."/user_goods_history_list";
$res = curl_request($url,$postdata,'GET');
$data['user_goods_history'] = $res['data']['list'];
return view('weixin.user.userGoodsHistory', $data);
$data['totalpage'] = ceil($res['data']['count']/$pagesize);
if(isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax']==1)
{
$html = '';
if($res['data']['list'])
{
foreach($res['data']['list'] as $k => $v)
{
$html .= '<li><a href="'.$v['goods']['goods_detail_url'].'"><span class="goods_thumb"><img alt="'.$v['goods']['title'].'" src="'.env('APP_URL').$v['goods']['litpic'].'"></span></a>';
$html .= '<div class="goods_info"><p class="goods_tit">'.$v['goods']['title'].'</p>';
$html .= '<p class="goods_price">¥<b>'.$v['goods']['price'].'</b></p>';
$html .= '<p class="goods_des fr"><span id="del_history" onclick="delconfirm(\''.route('weixin_user_goods_history_delete',array('id'=>$v['id'])).'\')">删除</span></p>';
$html .= '</div></li>';
}
}
exit(json_encode($html));
}
return view('weixin.user.userGoodsHistory', $data);
}
//浏览记录删除

2
resources/views/weixin/user/index.blade.php

@ -24,7 +24,7 @@
<div class="scgz">
<ul>
<li>
<a href="/index.php/Mobile/User/collect_list.html">
<a href="<?php echo route('weixin_user_collect_goods'); ?>">
<h2>1</h2>
<p>我的收藏</p>
</a>

61
resources/views/weixin/user/userGoodsHistory.blade.php

@ -21,6 +21,67 @@
<?php }} ?>
</ul>
</div>
<script>
$(function(){
var ajaxload = false;
var maxpage = false;
var startpage = 1;
var totalpage = <?php echo $totalpage; ?>;
var tmp_url = window.location.href;
msg = tmp_url.split("#");
tmp_url = msg[0];
$(window).scroll(function ()
{
var listheight = $(".goods_list_s").outerHeight();
if ($(document).scrollTop() + $(window).height() >= listheight)
{
if(startpage >= totalpage)
{
//$("#submit_bt_one").html("已是最后一页,没有更多数据!");
return false;
}
if(!ajaxload && !maxpage)
{
ajaxload = true;
//$("#submit_bt_one").html("努力加载中...");
var url = tmp_url;
var nextpage = startpage+1;
$.get(url,{page_ajax:1,page:nextpage},function(res)
{
if(res)
{
$(".goods_list_s").append(res);
startpage++;
if(startpage >= totalpage)
{
maxpage = true;
//$("#submit_bt_one").html("已是最后一页,没有更多数据!");
}
else
{
//$("#submit_bt_one").html("点击加载更多");
}
ajaxload = false;
}
else
{
//$("#submit_bt_one").html("请求失败,请稍候再试!");
ajaxload = false;
}
},'json');
}
}
});
})
</script>
@include('weixin.common.footer')
</body></html>

4
routes/web.php

@ -65,10 +65,14 @@ Route::group(['prefix' => 'weixin', 'namespace' => 'Weixin'], function () {
Route::get('/goodslist', 'GoodsController@goodslist')->name('weixin_goods_list'); //产品分类页
Route::get('/user', 'UserController@index')->name('weixin_user');
//浏览记录
Route::get('/user_goods_history', 'UserController@userGoodsHistory')->name('weixin_user_goods_history');
Route::get('/user_goods_history_delete', 'UserController@userGoodsHistoryDelete')->name('weixin_user_goods_history_delete');
Route::get('/user_goods_history_clear', 'UserController@userGoodsHistoryClear')->name('weixin_user_goods_history_clear');
//商品收藏
Route::get('/collect_goods', 'CollectGoodsController@index')->name('weixin_user_collect_goods');
Route::get('/cart', 'CartController@index')->name('weixin_cart');
Route::get('/user_address', 'AddressController@index')->name('weixin_user_address_list');

Loading…
Cancel
Save