user search

This commit is contained in:
zhao 2020-02-13 12:15:35 +08:00
parent a85faacba8
commit 34ada257ea
2 changed files with 30 additions and 5 deletions

View File

@ -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);
}

View File

@ -15,7 +15,7 @@
<div class="layui-inline">
<label class="layui-form-label">用户名</label>
<div class="layui-input-block">
<input type="text" name="username" placeholder="请输入" autocomplete="off" class="layui-input">
<input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-inline">
@ -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', {