laravel8 layui多条件模糊搜索分页、批量删除

前台js

<div class="demoTable">
    广告标题:
    <div class="layui-inline">
        <input class="layui-input" name="title" id="title" autocomplete="off">
    </div>
    状态
    <select name="status" lay-verify="required" id="status">
        <option value=""></option>
        <option value="1">正常</option>
        <option value="2">禁用</option>
    </select>
    <button class="layui-btn" data-type="reload">搜索</button>
 //搜索
        var $ = layui.$, active = {
            reload: function () {
                var title = $('#title');
                var status = $('#status');
                url: "{{route('admin.carListAll')}}"
                dataType:'json';
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        title: title.val(),
                        status: status.val()
                    }
                });
            }
        };
        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

后台

//列表
    public function carListAll()
    {

        //接收每页显示条数和偏移量
        $page = $this->request->input('page');
        $limit = $this->request->input('limit');
        //接收要搜索的数据
        $title = $this->request->input('title');
        $status = $this->request->input('status');
        $where = [];
        if (!empty($title) || !empty($status)) {
            $where[] = ['title', 'like', "%$title%"];
            $where[] = ['status', 'like', "%$status%"];
        }
        if ($this->request->ajax()) {
            //导航列表数据
            $preList = CarouselModel::where($where)->paginate($limit, '*', 'page', $page)->toArray();
            //总条数
            $count = CarouselModel::count();
            //组装数据
            $data = [
                'data' => $preList,
                'count' => $count
            ];
            return $this->listSuccess($data,'查询成功');
        }
    }

批量删除前端

 //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;
                    //定义一个空数组
                    var arr = [];
                    data.map(function (res) {
                        arr.push(res.id)
                    })
                    //将获取到的值进行数组拼接,然后使用‘,’进行分割
                    var ids = arr.join(',');
                    //console.log(ids)
                    $.get('{{route('admin.navMoneDel')}}',{ids:ids},function (res) {
                        if (res.code == 200){
                            layer.msg(res.msg);
                            parent.location.reload();
                            return false;
                        }
                        if (res.code == 500){
                            layer.msg(res.msg);
                            parent.location.reload();
                            return false;
                        }
                    })
                    break;

批量删除后端

 //批量删除
    public function navMoneDel()
    {
        //取出需要的参数
        $arrayIds = $this->request->only('ids');
        if (empty($arrayIds)) {
            $this->error('请选择要删除的数据');
        }
        //删除
        $res = NavigationModel::whereIn('id', $arrayIds)->delete();
        if ($res) {
            return $this->success($res, '批量删除成功');
        }
        return $this->error('批量删除失败');

    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值