捕sss获.PNG
1. html 页面代码
<td class="td-manage">
@if($member->enable == 0)
<a style="text-decoration:none" onClick="member_start( this,'{{$member->nickname}}','{{$member->id}}')" href="javascript:;" title="停用"><i class="Hui-iconfont"></i></a>
@else
<a style="text-decoration:none" onClick="member_stop( this,'{{$member->nickname}}','{{$member->id}}')" href="javascript:;" title="停用"><i class="Hui-iconfont"></i></a>
@endif
2. ajax 代码
//用户禁用
function member_stop( obj,name,id){
layer.confirm('确认要禁用id:'+id+', 昵称:"' +name+'"的用户吗?',function (index) {
$.ajax({
type:'post',
url:'/admin/service/member/enable',
datetype:'json',
data: {
_enable:0,
id: id,
_token:"{{csrf_token()}}"
},
success:function(data){
$(obj).parents("tr").find(".td-manage").prepend(
' <a style="text-decoration:none" onClick="member_start( this,\'{{$member->nickname}}\',\'{{$member->id}}\')" href="javascript:;" title="停用"><i class="Hui-iconfont"></i></a>'
);
//
$(obj).parents('tr').find('.td-status').html('<span class="label label-defaunt radius">已停用</span>');
$(obj).remove();
layer.msg('已停用!',{icon:5,time:1000});
},
error: function(xhr, status, error) {
console.log(xhr);
console.log(status);
console.log(error);
layer.msg('ajax error', {icon:2, time:2000});
},
});
});
}
//用户解禁
function member_start(obj ,name,id){
layer.confirm('确认要解封id' +id+'昵称:“'+name+'”的用户吗?',function(index){
$.ajax({
type:'post',
url:'/admin/service/member/enable',
datatype:'json',
data:{
_enable:1,
id:id,
_token:"{{csrf_token()}}"
},
success:function(data){
$(obj).parents("tr").find(".td-manage").prepend(
' <a style="text-decoration:none" onClick="member_stop( this,\'{{$member->nickname}}\',\'{{$member->id}}\')" href="javascript:;" title="启用"><i class="Hui-iconfont"></i></a>'
);
//
$(obj).parents('tr').find('.td-status').html('');
$(obj).remove();
layer.msg('已启用!',{icon:6,time:1000});
},
error: function(xhr, status, error) {
console.log(xhr);
console.log(status);
console.log(error);
layer.msg('ajax error', {icon:2, time:2000});
},
});
});
}
3. 路由设置
Route::post('/service/member/enable', 'admin\MemberController@memberEnable');
4 .控制器
//用户的禁用和解禁
public function memberEnable( Request $request){
$m3_result = new M3Result;
$id = $request->input('id','');
$_enable = $request->input('_enable','');
$res = Member::where('id',$id)->update(['enable'=>$_enable]);
if($res)
{
if($_enable == 1)
{
$m3_result->status = 0;
$m3_result->message ="启用成功";
}else{
$m3_result->status = 0;
$m3_result->message ="禁用成功";
}
}else{
if($_enable == 1)
{
$m3_result->status = 1;
$m3_result->message ="启用失败";
}else{
$m3_result->status = 1;
$m3_result->message ="禁用失败";
}
}
return $m3_result->toJson();
}
网友评论