Browse Source

添加规格弹窗编辑

master
liangyuyan 5 years ago
parent
commit
2b88081a75
  1. 36
      app/Admin/Actions/Grid/v3/GoodsSpec.php
  2. 3
      app/Admin/Controllers/v3/GoodsController.php
  3. 87
      app/Admin/Forms/v3/GoodsSpecForm.php

36
app/Admin/Actions/Grid/v3/GoodsSpec.php

@ -0,0 +1,36 @@
<?php
namespace App\Admin\Actions\Grid\v3;
use Dcat\Admin\Grid\RowAction;
use Dcat\Admin\Widgets\Modal;
use App\Admin\Forms\v3\GoodsSpecForm;
class GoodsSpec extends RowAction
{
/**
* @return string
*/
protected $title = '管理规格';
public function render()
{
$id = $this->getKey();
$modal = Modal::make()
->xl()
->title($this->title)
->body(GoodsSpecForm::make()->setKey($id))
->button($this->title);
return $modal;
}
public function parameters()
{
return [
];
}
}

3
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\GoodsCopy;
use App\Admin\Actions\Grid\v3\GoodsImage; use App\Admin\Actions\Grid\v3\GoodsImage;
use App\Admin\Actions\Grid\v3\GoodsSpec;
use App\Admin\Common\Auth; use App\Admin\Common\Auth;
use App\Admin\Repositories\v3\Goods; use App\Admin\Repositories\v3\Goods;
use Dcat\Admin\Admin; use Dcat\Admin\Admin;
@ -78,7 +79,7 @@ class GoodsController extends AdminController
$grid->sort->sortable(); $grid->sort->sortable();
$grid->on_sale->switch(); $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){ $grid->filter(function (Grid\Filter $filter) use($storeList, $categoryList, $goodsCategoryList, $marketList){
$filter->equal('id'); $filter->equal('id');
$filter->like('name'); $filter->like('name');

87
app/Admin/Forms/v3/GoodsSpecForm.php

@ -0,0 +1,87 @@
<?php
namespace App\Admin\Forms\v3;
use App\Models\v3\GoodsBanners;
use Dcat\Admin\Widgets\Form;
use Symfony\Component\HttpFoundation\Response;
use App\Models\v3\Goods as GoodsModel;
use App\Models\v3\GoodsBanners as GoodsBannerModel;
use Dcat\Admin\Form\NestedForm;
class GoodsSpecForm extends Form
{
/**
* Handle the form request.
*
* @param array $input
*
* @return Response
*/
public function handle(array $input)
{
// 获取外部传递参数
$goodsId = $input['goods_id'];
// $tags= isset($input['tags'])?$input['tags']:[];
$spec= isset($input['spec'])?$input['spec']:[];
$edit = false;
$goods = GoodsModel::find($goodsId);
if(empty($goods)){
$this->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 [];
}
}
Loading…
Cancel
Save