FittingRoomController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\FittingRoom;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. use App\Admin\Renderable\AttireTable; // 筛选表格弹框
  9. class FittingRoomController extends AdminController
  10. {
  11. /**
  12. * Make a grid builder.
  13. *
  14. * @return Grid
  15. */
  16. protected function grid()
  17. {
  18. return Grid::make(new FittingRoom(['account','attire']), function (Grid $grid) {
  19. $grid->column('id')->sortable();
  20. $grid->column('account.uid','用户UID');
  21. $grid->column('account.username','用户名称')->display(function($v) {
  22. return "<a href='/admin/accounts?id={$this->account_id}' target='_blank'>{$v}</a>";
  23. });
  24. $grid->column('attire.name', '装扮名称');
  25. $grid->column('attire.img_1', '正面图片')->image(config("filesystems.disks.cosv5.url"), 100, 100);
  26. $grid->column('attire.img_2', '背面图片')->image(config("filesystems.disks.cosv5.url"), 100, 100);
  27. $grid->column('attire.cate', '类别');
  28. $grid->column('curr_save')->using(['否','是'])->label();
  29. $grid->column('curr_upload')->using(['否','是'])->label();
  30. $grid->column('created_at');
  31. $grid->column('updated_at');
  32. //
  33. $grid->enableDialogCreate();
  34. $grid->setDialogFormDimensions('40%', '50%');
  35. $grid->withBorder();
  36. $grid->actions(function (Grid\Displayers\Actions $actions) {
  37. $actions->quickEdit(true);
  38. $actions->disableEdit();
  39. $actions->disableView();
  40. });
  41. $grid->model()->orderByDesc("id");
  42. //
  43. $grid->filter(function ($filter) {
  44. // 展开过滤器
  45. $filter->panel();
  46. $filter->expand();
  47. $filter->withoutInputBorder();
  48. // 在这里添加字段过滤器
  49. // $filter->equal('id')->width(2);
  50. $filter->where('aid', function ($query) {
  51. $query->whereHas('account', function ($query) {
  52. $query->where('uid', $this->input);
  53. });
  54. }, '用户UID')->width(2);
  55. $filter->equal('account_id','用户名称')->select(\App\Models\Account::pluck('username','id'))->width(2);
  56. $filter->equal('attire_id', '装扮')
  57. ->selectTable(AttireTable::make()) // 设置渲染类实例,并传递自定义参数
  58. ->title('装扮列表')
  59. ->dialogWidth('50%') // 弹窗宽度,默认 800px
  60. ->model(\App\Models\Attire::class, 'id', 'name')->width(2); // 设置编辑数据显示
  61. // $filter->equal('attire.cate', '类别')->select($this->cates)->width(2); // 设置编辑数据显示
  62. });
  63. });
  64. }
  65. /**
  66. * Make a show builder.
  67. *
  68. * @param mixed $id
  69. *
  70. * @return Show
  71. */
  72. protected function detail($id)
  73. {
  74. return Show::make($id, new FittingRoom(), function (Show $show) {
  75. $show->field('id');
  76. $show->field('account_id');
  77. $show->field('name');
  78. $show->field('cate');
  79. $show->field('img_1');
  80. $show->field('img_2');
  81. $show->field('curr_save');
  82. $show->field('curr_upload');
  83. $show->field('created_at');
  84. $show->field('updated_at');
  85. });
  86. }
  87. /**
  88. * Make a form builder.
  89. *
  90. * @return Form
  91. */
  92. protected function form()
  93. {
  94. return Form::make(new FittingRoom(), function (Form $form) {
  95. // $form->display('id');
  96. $form->select('account_id')->options(\App\Models\Account::pluck('username','id'));
  97. $form->selectTable('attire_id', '装扮') // 设置渲染类实例,并传递自定义参数
  98. ->title('装扮列表')
  99. ->dialogWidth('50%') // 弹窗宽度,默认 800px
  100. ->from(AttireTable::make())
  101. ->model(\App\Models\Attire::class, 'id', 'name')
  102. // ->rules('unique:fitting_rooms,attire_id,$selfId,id', ['unique' => '已经在礼盒中了,请选择其它的'])
  103. ->required();
  104. $form->switch('curr_save');
  105. $form->switch('curr_upload');
  106. // $form->display('created_at');
  107. // $form->display('updated_at');
  108. });
  109. }
  110. }