123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- namespace App\Admin\Controllers;
- use App\Models\Product;
- use App\Models\ProductCategory;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use Dcat\Admin\Http\Controllers\AdminController;
- class ProductController extends AdminController
- {
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(Product::with('cate'), function (Grid $grid) {
- $grid->model()->orderByDesc('sort');
- $grid->column('id')->sortable();
- $grid->column('name')->label('info');
- $grid->column('cate_id')->display(function (){
- return $this->cate->name;
- })->label('success');
- $grid->column('cover_img')->image('',80);
- $grid->column('cases')->display(function (){
- $html = '';
- foreach ($this->cases as $case){
- $html .= '<img data-action="preview-img" src="'.$case.'"
- style="max-width:80px;max-height:80px;cursor:pointer"
- class="img img-thumbnail">';
- }
- return $html;
- });
- $grid->column('tech_param')->display(function (){
- $html = '';
- foreach ($this->tech_param as $key => $tech_param){
- $index = $key+1;
- $html .= "<a href='{$tech_param}' download target='_blank'>参数文件{$index}</a><br>";
- }
- return $html;
- });
- $grid->column('cad_model')->display(function (){
- $html = '';
- foreach ($this->cad_model as $key => $tech_param){
- $index = $key+1;
- $html .= "<a href='{$tech_param}' download target='_blank'>CAD模型{$index}</a><br>";
- }
- return $html;
- });
- $grid->column('cad_design')->display(function (){
- $html = '';
- foreach ($this->cad_design as $key => $tech_param){
- $index = $key+1;
- $html .= "<a href='{$tech_param}' download target='_blank'>CAD设计$index</a><br>";
- }
- return $html;
- });
- $grid->column('su_model')->display(function (){
- $html = '';
- foreach ($this->su_model as $key => $tech_param){
- $index = $key+1;
- $html .= "<a href='{$tech_param}' download target='_blank'>SU模型{$index}</a><br>";
- }
- return $html;
- });
- $grid->column('other')->display(function (){
- $html = '';
- foreach ($this->other as $key => $tech_param){
- $index = $key+1;
- $html .= "<a href='{$tech_param}' download target='_blank'>其他文件{$index}</a><br>";
- }
- return $html;
- });
- $grid->column('is_opened')->switch();
- $grid->column('sort')->editable();
- $grid->column('created_at');
- $grid->actions(function (Grid\Displayers\Actions $actions) {
- $id = $actions->getKey();
- // append一个操作
- $actions->append('<a href="/admin/product/'.$id.'/spec"><i class="fa fa-align-left"></i> 规格管理</a>');
- });
- $grid->filter(function (Grid\Filter $filter) {
- $filter->panel();
- $filter->like('name')->width(2);
- });
- $grid->disableViewButton();
- });
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- *
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new Product(), function (Show $show) {
- $show->field('id');
- $show->field('name');
- $show->field('cover_img');
- $show->field('cases');
- $show->field('origin_price');
- $show->field('sale_price');
- $show->field('sort');
- $show->field('is_opened');
- $show->field('tech_param');
- $show->field('cad_model');
- $show->field('cad_design');
- $show->field('su_model');
- $show->field('other');
- $show->field('created_at');
- $show->field('updated_at');
- });
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- return Form::make(new Product(), function (Form $form) {
- $form->display('id');
- $cates = ProductCategory::select(['id','name'])->where('is_opened',1)->get()->toArray();
- $form->select('cate_id')
- ->options(array_column($cates,'name','id'))
- ->required();;
- $form->text('name')->required();;;
- $form->image('cover_img')->saveFullUrl()
- ->uniqueName()->autoUpload()
- ->autoSave(false)
- ->removable(false)
- ->width(4)
- ->required();
- $form->multipleImage('cases')->saveFullUrl()
- ->uniqueName()->autoUpload()
- ->autoSave(false)
- ->removable(false)
- ->width(4);
- $form->multipleFile('tech_param')->saveFullUrl()
- ->uniqueName()->autoUpload()
- ->autoSave(false)
- ->removable(false)
- ->width(4);
- $form->multipleFile('cad_model')->saveFullUrl()
- ->uniqueName()->autoUpload()
- ->autoSave(false)
- ->removable(false)
- ->width(4);
- $form->multipleFile('cad_design')->saveFullUrl()
- ->uniqueName()->autoUpload()
- ->autoSave(false)
- ->removable(false)
- ->width(4);
- $form->multipleFile('su_model')->saveFullUrl()
- ->uniqueName()->autoUpload()
- ->autoSave(false)
- ->removable(false)
- ->width(4);
- $form->multipleFile('other')->saveFullUrl()
- ->uniqueName()->autoUpload()
- ->autoSave(false)
- ->removable(false)
- ->width(4);
- $form->radio('is_opened')->options(config('global.bool_status'))->default(1);
- $form->number('sort');
- $form->disableViewButton();
- $form->disableDeleteButton();
- $form->disableListButton();
- $form->disableEditingCheck();
- $form->disableViewCheck();
- $form->disableCreatingCheck();
- });
- }
- }
|