1. js部分 自动生成显示的字段,添加
{field: 'status', title: __('黑名单操作'),operate: false, formatter: Controller.api.formatter.black, events: Controller.ladd.browser},
根据状态显示对应的按钮 formatter: Controller.api.formatter.black,
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
},
formatter: {
black: function (value, row, index) {
var num = row.status;
if(num == 0){
return'-';
}
if(num == 1){
return'<a href="javascript:;" class="btn btn-xs btn-danger btn-borrower" title="加入黑名单"><i class=""></i>加入黑名单</a>';
}
if(num == 2){
return'<a href="javascript:;" class="btn btn-xs btn-success btn-moveblack" title="移出黑名单"><i class=""></i>移出黑名单</a>';
}
},
}
},
按钮对应的js方法 events: Controller.ladd.browser 弹框,调用控制器方法
ladd: {
browser: {
'click .btn-borrower': function (e, value, row, index) {
e.stopPropagation();
var that = this;
var top = $(that).offset().top - $(window).scrollTop();
var left = $(that).offset().left - $(window).scrollLeft() - 260;
if (top + 154 > $(window).height()) {
top = top - 154;
}
if ($(window).width() < 480) {
top = left = undefined;
}
var index = Layer.confirm(
__('确认拉黑该用户?'),
{icon: 1, title: __('温馨提示'), offset: [top, left], shadeClose: true},
function () {
var table = $(that).closest('table');
var options = table.bootstrapTable('getOptions');
Backend.api.ajax("circlenote/addblack/ids/"+row.id, function(data, ret){
window.location.reload();
});
Layer.close(index);
}
);
},
'click .btn-moveblack': function (e, value, row, index) {
e.stopPropagation();
var that = this;
var top = $(that).offset().top - $(window).scrollTop();
var left = $(that).offset().left - $(window).scrollLeft() - 260;
if (top + 154 > $(window).height()) {
top = top - 154;
}
if ($(window).width() < 480) {
top = left = undefined;
}
var index = Layer.confirm(
__('确认在黑名单中移除该用户?'),
{icon: 1, title: __('温馨提示'), offset: [top, left], shadeClose: true},
function () {
var table = $(that).closest('table');
var options = table.bootstrapTable('getOptions');
Backend.api.ajax("circlenote/moveblack/ids/"+row.id, function(data, ret){
// document.execCommand('Refresh');
window.location.reload();
});
Layer.close(index);
}
);
},
},
},
2.控制器部分
//拉黑 传入要拉黑人帖子id 获取发布人id 将发布人所有的帖子设置为不显示
public function addblack($ids = "")
{
if ($ids) {
$mDb = Db::connect('db_config_fwq');
//获取发布人id
$mid=$mDb->table('app_circle_note')->where('id',$ids)->value('mid');
//dump($mid);die;
//加入黑名单
$is_black=$mDb->table('app_circle_black')->where('mid',$mid)->find();
if(!$is_black)
{
$data = ['mid' => $mid];
$mDb->table('app_circle_black')->insert($data);
}
//将发布人所有的帖子设置为不显示
$where['mid']=$mid;
$where['status']=array('neq',0);
$list = $this->model->where($where)->setField('status',2);
if ($list > 0) {
$this->success();
} else {
$this->error(__('No rows were deleted'));
}
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}
//移出黑名单 传入要拉黑人帖子id 获取发布人id 将发布人所有的帖子设置状态 2设置为1 2是拉黑的, 1,是显示 2是不显示
public function moveblack($ids = "")
{
if ($ids) {
$mDb = Db::connect('db_config_fwq');
//获取发布人id
$mid=$mDb->table('app_circle_note')->where('id',$ids)->value('mid');
//dump($mid);die;
//加入黑名单
$is_black=$mDb->table('app_circle_black')->where('mid',$mid)->find();
if($is_black)
{
$mDb->table('app_circle_black')->where('mid',$mid)->delete();
}
//将发布人所有的帖子设置为不显示
$where['mid']=$mid;
$where['status']=array('eq',2);
$list = $this->model->where($where)->setField('status',1);
if ($list > 0) {
$this->success();
} else {
$this->error(__('No rows were deleted'));
}
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}