From 34ada257ea9c28e71bd0c3e8e9bded4e2562971e Mon Sep 17 00:00:00 2001 From: zhao Date: Thu, 13 Feb 2020 12:15:35 +0800 Subject: [PATCH] user search --- app/admin/controller/User.php | 12 ++++++++---- view/admin/user/list.html | 23 ++++++++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/app/admin/controller/User.php b/app/admin/controller/User.php index 1a0f91d..ee7ce21 100644 --- a/app/admin/controller/User.php +++ b/app/admin/controller/User.php @@ -26,15 +26,19 @@ class User extends AdminController public function list() { if(Request::isAjax()){ - $user = Db::name('user')->where(['delete_time'=>0])->select(); + $data = Request::only(['id','name','email','sex']); + $map = array_filter($data); + $user = Db::name('user')->where(['delete_time'=>0])->where($map)->order('id desc')->select(); $count = $user->count(); $res = []; - if($user){ - $res = ['code'=>0,'msg'=>'','count'=>$count]; + if($count){ foreach($user as $k => $v){ $data = ['id'=>$v['id'],'username'=>$v['name'],'avatar'=>$v['user_img'],'phone'=>$v['phone'],'email'=>$v['email'],'sex'=>$v['sex'],'ip'=>$v['last_login_ip'],'jointime'=>date("Y-m-d",$v['create_time']),'check'=>$v['status'],'auth'=>$v['auth']]; - $res['data'][] = $data; + //$res['data'][] = $data; + $res = ['code'=>0,'msg'=>'','count'=>$count,'data'=>[$data]]; } + } else { + $res = ['code'=>-1,'msg'=>'没有查询结果!']; } return json($res); } diff --git a/view/admin/user/list.html b/view/admin/user/list.html index e8bc49d..bc1466a 100644 --- a/view/admin/user/list.html +++ b/view/admin/user/list.html @@ -15,7 +15,7 @@
- +
@@ -96,6 +96,27 @@ //监听搜索 form.on('submit(LAY-user-front-search)', function(data){ var field = data.field; + console.log(field); + + //提交 Ajax 成功后,静态更新表格中的数据 + $.ajax({ + type:"post", + url:"{:url('admin/user/list')}", + data:{"id":field.id,"name":field.name,"email":field.email,"sex":field.sex}, + daType:"json", + success:function (data){ + if (data.code == 0) { + + } else { + layer.open({ + tiele:'搜索失败', + content:data.msg, + icon:5, + anim:6 + }); + } + } + }); //执行重载 table.reload('LAY-user-manage', {