Fork me on Baidu

tp6 搜索分页+layui ajax 请求

1,后端参数的接收

2,前端页面数据显示

注意传递时要带有条件参数

$page = $this->request->param('page', CommonConstant::COMMON_PAGE, 'intval');
$size = $this->request->param('size', CommonConstant::COMMON_SIZE, 'intval');
$start = trim($this->request->param('start', ''));
$end = trim($this->request->param('end', ''));
$search = $this->request->param('search', '','trim');
$userModel = (UserModel::getInstance());
if((!empty($start)) && (!empty($end))){
$userModel=$userModel->whereBetweenTime('create_time',date('Y-m-d 00:00:00',strtotime($start)),date('Y-m-d 23:59:59',strtotime($end)));
}
$result = $userModel->when($search, function ($query, $search) {
$query->where('username', 'like', "%$search%");
})->order(['admin_status' => 'asc', 'create_time' => 'desc'])
->paginate(['list_rows' => $size, 'page' => $page, 'query' =>request()->param()]);
$result = $result ?? [];
View::assign('data', $result);
View::assign('search', $search);
return view('admin/admin/admin-list');

注意query 要携带参数 要把查询的数据放到页面中

 

 

 

 

单条件带参数搜索 多条件搜索 

记录中。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

layui ajax 请求修改数据

function member_stop(obj, id) {
layer.confirm('确认要修改状态吗?', function (index) {
if($(obj).attr('title')=='正常') {
//发异步把用户状态进行更改
$.ajax({
url: "editStatus",
type: "post",
dataType: "json",
async: false,
data: {
id: id,
status: 2
},
success: function (data) {
if (data.code) {
location.href = '';
}
}
})
}else{
$.ajax({
url: "editStatus",
type: "post",
dataType: "json",
async: false,
data: {
id: id,
status: 1
},
success: function (data) {
if (data.code) {
location.href = '';
}
}
})
}
});
}

 

posted @ 2023-03-10 10:08  consideration  阅读(136)  评论(0编辑  收藏  举报