[phpstudy和layui]輸出表

後端代碼: 

public function claimindex()
    {
        if (request()->isPost()) {
            $limit = $this->request->post('limit', config('paginate.list_rows'), 'intval');
            $data = input('post.');
            $data['user_id']=session('roleid');
            //user_id=1爲管理員
            if($data['user_id']==7){
                $list = db('claim')
                    ->alias('c')
                    ->join('lost l', 'c.lost_id=l.id', 'right')
                    ->where('c.c_status', 0)
                    ->field('l.id,l.thing,l.name,l.create_time,l.address,l.content,c.c_name,c.c_content')
                    ->group('l.id')
                    ->order('l.create_time','DESC')
                    ->paginate($limit)
                    ->toArray();
            }
            else {
                $list = db('claim')
                    ->alias('c')
                    ->join('lost l', 'c.lost_id=l.id', 'right')
                    ->where('c.c_status', 0)
                    ->field('l.id,l.thing,l.name,l.create_time,l.address,c.c_name')
                    ->group('l.id')
                    ->order('l.create_time','DESC')
                    ->paginate($limit)
                    ->toArray();
            }
            $list = $this->tableFormat($list);
            return $this->showList($list);
        }
        else
        {
            $list = db('lost_type')->select();
            $this->assign('list', $list);
            return $this->fetch();
        }
    }

前端代碼:

layui.use(['layer', 'table', 'form'], function () {
        var form = layui.form, table = layui.table, layer = layui.layer;
        var tableIn = table.render({
            id: 'data',
            elem: '#list',
            url: '{:url("claimindex")}',
            method: 'post',
            page: true,
            cols: [[
                {checkbox: true, align: 'center'}
                , {type: 'numbers', align: 'center', title: '序號'}
                , {field: 'thing', align: 'center', title: '物品名稱'}
                , {field: 'name', align: 'center', title: '撿到人姓名'}
                , {field: 'create_time', align: 'center', title: '時間', width:200}
                , {field: 'address', align: 'center', title: '地點'}
                , {field: 'content', align: 'center', title: '撿到人的備註'}
                , {field: 'c_name', align: 'center', title: '失主的姓名'}
                , {field: 'c_content', align: 'center', title: '失主的備註'}
                , {width: 160, align: 'center', title: '操作', toolbar: '#action'}
            ]],
            limits: [10, 20, 50, 100],
            limit: 10 //每頁默認顯示的數量
        });
});

實現結果:

管理員登陸結果: 

用戶登陸結果: 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章