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 .= ''; } return $html; })->width(300); $grid->column('tech_param')->display(function (){ $html = ''; foreach ($this->tech_param as $key => $item){ $html .= "技术参数
"; } return $html; }); $grid->column('cad_model')->display(function (){ $html = ''; foreach ($this->cad_model as $key => $item){ $html .= "CAD模型
"; } return $html; }); $grid->column('cad_design')->display(function (){ $html = ''; foreach ($this->cad_design as $key => $item){ $html .= "CAD设计
"; } return $html; }); $grid->column('su_model')->display(function (){ $html = ''; foreach ($this->su_model as $key => $item){ $html .= "SU模型
"; } return $html; }); $grid->column('other')->display(function (){ $html = ''; foreach ($this->other as $key => $item){ $html .= "{$item['name']}
"; } return $html; }); $grid->column('is_opened')->switch(); $grid->column('sort')->editable(); $grid->column('created_at'); $grid->column('spec','规格')->display(function (){ $url = '/admin/product/'.$this->id.'/spec'; return "规格管理"; }); $grid->filter(function (Grid\Filter $filter) { $filter->panel(); $filter->equal('cate_id')->select(function (){ return ProductCategory::select(['id','name'])->get()->pluck('name','id')->toArray(); })->width(2); $filter->like('name')->width(2); }); $grid->batchActions([new BatchProduct()]); $grid->disableViewButton(); $grid->export() ->titles([ 'name' => '产品名称', 'cate_name' => '产品分类', 'cover_img' => '产品截面图', 'cases' => '案例', 'tech_param' => '技术参数文件', 'cad_model' => 'CAD模型文件', 'cad_design' => 'CAD设计文件', 'su_model' => 'SU模型文件', 'other' => '其他文件', 'is_opened' => '上架状态', 'sort' => '排序(越大越靠前)', 'specs' => '规格', ])->rows(function ($rows){ foreach ($rows as $index => &$row) { $specs = []; foreach ($row['specs'] as $spec){ $arr = []; foreach ($spec['specs'] as $item){ $arr[] = "{$item['name']}(¥{$item['price']})"; } $specs[] = $spec['name'].':('.implode(",",$arr).')'; } $row['cate_name'] = $row['cate']['name']; $row['cases'] = implode(",",$row['cases']); $row['tech_param'] = implode(",",$row['tech_param']); $row['cad_model'] = implode(",",$row['cad_model']); $row['cad_design'] = implode(",",$row['cad_design']); $row['su_model'] = implode(",",$row['su_model']); $row['other'] = implode(',', $row['other']); $row['is_opened'] = config('global.bool_status')[$row['is_opened']]; $row['specs'] = implode(",",$specs); } return $rows; }) ->xlsx() ->disableExportSelectedRow(); }); } /** * 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(Product::with(['specs']), function (Form $form) { $form->display('id'); $cates = ProductCategory::select(['id','name'])->where('is_opened',1)->get()->toArray(); /* @var Form $form*/ $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)->sortable(); $form->table('tech_param', function (Form\NestedForm $table) { $table->url('url','链接')->required(); }); $form->table('cad_model', function (Form\NestedForm $table) { $table->url('url','链接')->required(); }); $form->table('cad_design', function (Form\NestedForm $table) { $table->url('url','链接')->required(); }); $form->table('su_model', function (Form\NestedForm $table) { $table->url('url','链接')->required(); }); $form->table('other', function (Form\NestedForm $table) { $table->text('name','名称')->required(); $table->url('url','链接')->required(); }); $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(); }); } }