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.
86 lines
2.0 KiB
86 lines
2.0 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Models\Category;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Layout\Content;
|
|
use Dcat\Admin\Layout\Row;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use Dcat\Admin\Tree;
|
|
|
|
class CategoryController extends AdminController
|
|
{
|
|
public function index(Content $content)
|
|
{
|
|
return $content->header('产品分类')
|
|
->body(function (Row $row) {
|
|
$tree = new Tree(new Category);
|
|
$tree->expand();
|
|
$tree->query(function ($model) {
|
|
//agent_id为0是系统分类,其它是代理商分类
|
|
return $model->where('agent_id', 0);
|
|
});
|
|
$row->column(12, $tree);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new Category(), function (Grid $grid) {
|
|
$grid->column('id')->sortable();
|
|
$grid->column('pid');
|
|
$grid->column('name');
|
|
$grid->column('sort');
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->equal('id');
|
|
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new Category(), function (Show $show) {
|
|
$show->field('id');
|
|
$show->field('pid');
|
|
$show->field('name');
|
|
$show->field('sort');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new Category(), function (Form $form) {
|
|
$options = Category::selectOptions(fn($query) => $query->where('agent_id', 0));
|
|
|
|
$form->display('id');
|
|
$form->select('pid')->options($options)->required();
|
|
$form->text('name')->required();
|
|
$form->text('sort')->default(255);
|
|
})->saving(function (Form $form) {
|
|
//后台管理员的agent_id为0
|
|
$form->agent_id = 0;
|
|
});
|
|
}
|
|
}
|