| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace App\Admin\Controllers;
- use App\Admin\Repositories\FittingRoom;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use Dcat\Admin\Http\Controllers\AdminController;
- use App\Admin\Renderable\AttireTable; // 筛选表格弹框
- class FittingRoomController extends AdminController
- {
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new FittingRoom(['account','attire']), function (Grid $grid) {
- $grid->column('id')->sortable();
- $grid->column('account.uid','用户UID');
- $grid->column('account.username','用户名称')->display(function($v) {
- return "<a href='/admin/accounts?id={$this->account_id}' target='_blank'>{$v}</a>";
- });
- $grid->column('attire.name', '装扮名称');
- $grid->column('attire.img_1', '正面图片')->image(config("filesystems.disks.cosv5.url"), 100, 100);
- $grid->column('attire.img_2', '背面图片')->image(config("filesystems.disks.cosv5.url"), 100, 100);
- $grid->column('attire.cate', '类别');
- $grid->column('curr_save')->using(['否','是'])->label();
- $grid->column('curr_upload')->using(['否','是'])->label();
- $grid->column('created_at');
- $grid->column('updated_at');
- //
- $grid->enableDialogCreate();
- $grid->setDialogFormDimensions('40%', '50%');
- $grid->withBorder();
- $grid->actions(function (Grid\Displayers\Actions $actions) {
- $actions->quickEdit(true);
- $actions->disableEdit();
- $actions->disableView();
- });
- $grid->model()->orderByDesc("id");
- //
- $grid->filter(function ($filter) {
- // 展开过滤器
- $filter->panel();
- $filter->expand();
- $filter->withoutInputBorder();
- // 在这里添加字段过滤器
- // $filter->equal('id')->width(2);
- $filter->where('aid', function ($query) {
- $query->whereHas('account', function ($query) {
- $query->where('uid', $this->input);
- });
- }, '用户UID')->width(2);
- $filter->equal('account_id','用户名称')->select(\App\Models\Account::pluck('username','id'))->width(2);
- $filter->equal('attire_id', '装扮')
- ->selectTable(AttireTable::make()) // 设置渲染类实例,并传递自定义参数
- ->title('装扮列表')
- ->dialogWidth('50%') // 弹窗宽度,默认 800px
- ->model(\App\Models\Attire::class, 'id', 'name')->width(2); // 设置编辑数据显示
- // $filter->equal('attire.cate', '类别')->select($this->cates)->width(2); // 设置编辑数据显示
-
- });
- });
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- *
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new FittingRoom(), function (Show $show) {
- $show->field('id');
- $show->field('account_id');
- $show->field('name');
- $show->field('cate');
- $show->field('img_1');
- $show->field('img_2');
- $show->field('curr_save');
- $show->field('curr_upload');
- $show->field('created_at');
- $show->field('updated_at');
- });
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- return Form::make(new FittingRoom(), function (Form $form) {
- // $form->display('id');
- $form->select('account_id')->options(\App\Models\Account::pluck('username','id'));
- $form->selectTable('attire_id', '装扮') // 设置渲染类实例,并传递自定义参数
- ->title('装扮列表')
- ->dialogWidth('50%') // 弹窗宽度,默认 800px
- ->from(AttireTable::make())
- ->model(\App\Models\Attire::class, 'id', 'name')
- // ->rules('unique:fitting_rooms,attire_id,$selfId,id', ['unique' => '已经在礼盒中了,请选择其它的'])
- ->required();
- $form->switch('curr_save');
- $form->switch('curr_upload');
- // $form->display('created_at');
- // $form->display('updated_at');
- });
- }
- }
|