海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.9 KiB

  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Common\UserStatus;
  4. use App\Models\Category;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Layout\Content;
  8. use Dcat\Admin\Layout\Row;
  9. use Dcat\Admin\Show;
  10. use Dcat\Admin\Http\Controllers\AdminController;
  11. use Dcat\Admin\Tree;
  12. class CategoryController extends AdminController
  13. {
  14. public function index(Content $content)
  15. {
  16. return $content->header('产品分类')
  17. ->body(function (Row $row) {
  18. $tree = new Tree(new Category);
  19. $tree->expand();
  20. $tree->query(function ($model) {
  21. //agent_id为0是系统分类,其它是代理商分类
  22. return $model->where('agent_id', 0);
  23. });
  24. $row->column(12, $tree);
  25. });
  26. }
  27. /**
  28. * Make a grid builder.
  29. *
  30. * @return Grid
  31. */
  32. protected function grid()
  33. {
  34. return Grid::make(new Category(), function (Grid $grid) {
  35. $grid->column('id')->sortable();
  36. $grid->column('pid');
  37. $grid->column('name');
  38. $grid->column('sort');
  39. $grid->filter(function (Grid\Filter $filter) {
  40. $filter->equal('id');
  41. });
  42. });
  43. }
  44. /**
  45. * Make a show builder.
  46. *
  47. * @param mixed $id
  48. *
  49. * @return Show
  50. */
  51. protected function detail($id)
  52. {
  53. return Show::make($id, new Category(), function (Show $show) {
  54. $show->field('id');
  55. $show->field('pid');
  56. $show->field('name');
  57. $show->field('sort');
  58. });
  59. }
  60. /**
  61. * Make a form builder.
  62. *
  63. * @return Form
  64. */
  65. protected function form()
  66. {
  67. return Form::make(new Category(), function (Form $form) {
  68. $form->display('id');
  69. $form->select('pid')->options(Category::selectOptions());
  70. $form->text('name');
  71. $form->text('sort')->default(255);
  72. });
  73. }
  74. }