diff --git a/app/Admin/Actions/Grid/v3/GoodsSpec.php b/app/Admin/Actions/Grid/v3/GoodsSpec.php new file mode 100644 index 0000000..951602f --- /dev/null +++ b/app/Admin/Actions/Grid/v3/GoodsSpec.php @@ -0,0 +1,36 @@ +getKey(); + + $modal = Modal::make() + ->xl() + ->title($this->title) + ->body(GoodsSpecForm::make()->setKey($id)) + ->button($this->title); + + return $modal; + } + + public function parameters() + { + + return [ + + ]; + } +} diff --git a/app/Admin/Controllers/v3/GoodsController.php b/app/Admin/Controllers/v3/GoodsController.php index 0ec3698..130a439 100644 --- a/app/Admin/Controllers/v3/GoodsController.php +++ b/app/Admin/Controllers/v3/GoodsController.php @@ -4,6 +4,7 @@ namespace App\Admin\Controllers\v3; use App\Admin\Actions\Grid\v3\GoodsCopy; use App\Admin\Actions\Grid\v3\GoodsImage; +use App\Admin\Actions\Grid\v3\GoodsSpec; use App\Admin\Common\Auth; use App\Admin\Repositories\v3\Goods; use Dcat\Admin\Admin; @@ -78,7 +79,7 @@ class GoodsController extends AdminController $grid->sort->sortable(); $grid->on_sale->switch(); - $grid->actions([new GoodsCopy(),new GoodsImage()]); + $grid->actions([new GoodsCopy(),new GoodsImage(),new GoodsSpec()]); $grid->filter(function (Grid\Filter $filter) use($storeList, $categoryList, $goodsCategoryList, $marketList){ $filter->equal('id'); $filter->like('name'); diff --git a/app/Admin/Forms/v3/GoodsSpecForm.php b/app/Admin/Forms/v3/GoodsSpecForm.php new file mode 100644 index 0000000..05b4fb2 --- /dev/null +++ b/app/Admin/Forms/v3/GoodsSpecForm.php @@ -0,0 +1,87 @@ +error('商品不存在!'); + } + // if(!empty($tags)){ + // $tagsArr = []; + // if(!empty($tags)){ + // foreach($tags as $kt => $tag){ + // if(empty($tag)){ + // unset($tags[$kt]); + // continue; + // } + // $tagsArr[] = $tag; + // } + // }; + // $goods->tags = json_encode($tagsArr); + // } + if(!empty($spec)){ + $goods->spec = $spec; + $edit = true; + } + if($edit && $goods->save()){ + return $this->error('修改成功!'); + } + + return $this->error('未做任何修改或者修改失败!'); + } + + /** + * Build a form here. + */ + public function form() + { + $id = $this->getKey(); + $goods = GoodsModel::select('name','tags','spec')->find($id); + $goodName = empty($goods->name)?'':$goods->name; + // $tags = empty($goods->tags)?[]:$goods->tags; + $spec = empty($goods->spec)?[]:$goods->spec; + $this->hidden('goods_id')->value($id); + $this->display('name','商品名称')->value($goodName); + // $this->tags('tags','标签')->options(['新品','热销','新鲜'])->value($tags); + $this->table('spec', function (NestedForm $table) { + $table->text('spec_key')->required()->help('如:净含量:500克,保质期:120天,包装:12个/盒等'); + $table->text('spec_value')->required(); + })->value($spec); + } + + /** + * The data of the form. + * + * @return array + */ + public function default() + { + return []; + } + +}