feat: 信息公开-招采平台分页完善

master
yin5th 2023-07-26 15:47:21 +08:00
parent 2d8e703419
commit e856ed9f30
3 changed files with 107 additions and 34 deletions

View File

@ -121,8 +121,11 @@ class Info extends Base
app('think\App')->bind(Paginator::class, DxtcPageA::class);
$list = [];
foreach ($cateList as $cate) {
$list[$cate['id']] = NoticeModel::getList($cate['id'], 2, $keyword, [], 1, $listSort, false);
foreach ($cateList as &$cate) {
// $list[$cate['id']]['total'] = NoticeModel::getList($cate['id'], 2, $keyword, [], 1, $listSort, false);
$cate['total'] = NoticeModel::where('category_id', $cate['id'])->when(!empty($keyword), function ($q) use ($keyword) {
$q->where('title', 'like', '%'.$keyword.'%');
})->count();
}
$downloadList = DownloadModel::where('category_id', Category::CATEGORY_INFO_DOWNLOAD)
@ -170,4 +173,48 @@ class Info extends Base
$this->data['categoryId'] = $category['id'];
return $this->view();
}
public function getNotice()
{
$page = input('page/d', 1);
$size = input('size/d', 2);
$cate = input('cate/d', 0);
$keyword = input('keyword/s', '');
$page = $page ?: 1;
$size = $size ?: 2;
$res = [
'total' => 0,
'page' => $page,
'size' => $size,
'data' => [],
];
if (empty($cate)) {
return $this->json(0,'success', $res);
}
$where = [];
if (!empty($keyword)) {
$where[] = ['title', 'like', '%'.$keyword.'%'];
}
$where[] = ['category_id', '=', $cate];
$q = NoticeModel::where($where);
$total = $q->count();
if ($total > 0) {
$list = $q->page($page)->limit($size)->order('sort desc')->select();
$list->each(function ($item) {
$item->create_at = date('Y.m.d', $item->create_time);
});
$res['total'] = $total;
$res['page'] = $page;
$res['size'] = $size;
$res['data'] = $list;
}
return $this->json(0, 'success', $res);
}
}

View File

@ -26,11 +26,11 @@ $(function(){
$(".header .nav .nLi h3").mouseenter(function(event) {
$(this).siblings('.listcur').show();
});
$(".header .nav .nLi").mouseleave(function(event) {
$(this).find(".listcur").hide();
});
// banner
// banner
var swiper1 = new Swiper('.banner .swiper-container', {
speed:1000,
@ -49,7 +49,7 @@ $(function(){
clickable: true,
},
});
//当banner图片大于1张时候运行
var bannerbox = $(".banner").find(".swiper-slide").length;
if(bannerbox == 1){
@ -85,7 +85,7 @@ $(function(){
return false;
});
$(".talent-top").click(function(){
$("body").on('click','.talent-top',function(){
$(this).siblings(".talent-bottom").slideToggle();
$(this).parents(".boxs").siblings().find(".talent-bottom").slideUp();
})

View File

@ -45,29 +45,61 @@
<div>
<div class="title2 mt80"><span>{$cate.title}</span></div>
<div class="talent-list pt20">
{php}$items = $list[$cate['id']];{/php}
{foreach $items as $item}
<div class="boxs">
<div class="talent-top">
<h3 class="tit">{$item.title}</h3>
<div class="text">
<div class="link">查看详情 >></div>
<div class="time">
<span><img src="__STATIC__/web/img/time.jpg" alt="">{:date('Y.m.d', $item.create_time)}</span>
</div>
</div>
<div class="int">{$item.status}</div>
</div>
<div class="talent-bottom">
<div>
{$item.content|raw}
</div>
</div>
</div>
{/foreach}
</div>
{$items->render('', 'class="pageing wow fadeIn" data-wow-duration="0.8s" data-wow-delay="0"')|raw}
<table id="cate-{$cate['id']}" lay-filter="test-{$cate['id']}"></table>
<script>
layui.use('laypage', function(){
var laypage = layui.laypage;
//执行一个laypage实例
laypage.render({
elem: 'cate-'+'{$cate.id}' //注意,这里的 test1 是 ID不用加 # 号
,count: {$cate.total ?? 0} //数据总数,从服务端得到
,limit: 2 //每页显示数量
,jump: function(obj, first){
//obj包含了当前分页的所有参数比如
// console.log(obj.curr); //得到当前页,以便向服务端请求对应页的数据。
// console.log(obj.limit); //得到每页显示的条数
if ({$cate.total ?? 0} > 0) {
$.post('/info/getNotice', {cate: '{$cate.id}', page:obj.curr, size:obj.limit, keyword: '{$keyword ?? ""}'}, function (res) {
if (res.code === 0 && res.data.total > 0) {
let html = '';
$.each(res.data.data, function (index, item) {
html += `
<div class="boxs">
<div class="talent-top">
<h3 class="tit">${item.title}</h3>
<div class="text">
<div class="link">查看详情 >></div>
<div class="time">
<span><img src="__STATIC__/web/img/time.jpg" alt="">${item.create_at}</span>
</div>
</div>
<div class="int">${item.status}</div>
</div>
<div class="talent-bottom">
<div class="cotent">
${item.content}
</div>
</div>
</div>
`;
});
$('#cate-'+'{$cate.id}').prev('.talent-list').html(html);
}
})
}
//首次不执行
if(!first){
//do something
}
}
});
});
</script>
</div>
{/foreach}
@ -93,10 +125,4 @@
<span>联系地址:{$extraBase['info_address'] ?? ''}</span>
</div>
</div>
</section>
<script>
// $('.pageing a').on('click', function () {
// console.log('sss');
// return false;
// })
</script>
</section>