4
0
Fork 0
master
panliang 2022-09-21 13:31:12 +08:00
parent 6bbcf27d18
commit 275b80a1f9
4 changed files with 50 additions and 34 deletions

View File

@ -38,4 +38,9 @@ class Attr extends Field
return $this;
}
// protected function prepareInputValue($value)
// {
// return $value;
// }
}

View File

@ -21,7 +21,7 @@ class AttrForm extends Form implements LazyRenderable
public function form()
{
$this->fill(['attr' => $this->payload['attr']]);
$this->fill(['attr' => data_get($this->payload, 'attr')]);
$this->attr('attr')->header(['分组', '名称'])->keys(['name']);

View File

@ -5,11 +5,8 @@ namespace Peidikeji\Goods\Http\Admin;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\Displayers\Modal;
use Dcat\Admin\Http\Controllers\AdminController;
use Peidikeji\Goods\Form\GoodsType\AttrForm;
use Peidikeji\Goods\Form\GoodsType\PartForm;
use Peidikeji\Goods\Form\GoodsType\SpecForm;
use Dcat\Admin\Show;
use Peidikeji\Goods\Models\Goods;
use Peidikeji\Goods\Models\GoodsType;
@ -28,50 +25,62 @@ class GoodsTypeController extends AdminController
{
return Grid::make(new GoodsType(), function (Grid $grid) {
$grid->disableRowSelector();
$grid->disableViewButton();
$grid->disableEditButton();
$grid->column('name')->editable();
$grid->column('attr')->display(fn () => view('dcat-admin-goods::goods-type.grid-attr', ['value' => $this->attr]))->modal(__('dcat-admin-goods::goods-type.fields.attr'), function (Modal $modal) {
$modal->icon('');
$grid->column('attr')->display(fn () => view('dcat-admin-goods::goods-type.grid-attr', ['value' => $this->attr]));
$grid->column('spec')->display(fn () => view('dcat-admin-goods::goods-type.grid-attr', ['value' => $this->spec]));
$grid->column('part')->display(fn () => view('dcat-admin-goods::goods-type.grid-attr', ['value' => $this->part]));
});
}
return AttrForm::make()->payload(['type_id' => $this->id, 'reset' => false, 'attr' => $this->attr]);
});
$grid->column('spec')->display(fn () => view('dcat-admin-goods::goods-type.grid-attr', ['value' => $this->spec]))->modal(__('dcat-admin-goods::goods-type.fields.spec'), function (Modal $modal) {
$modal->icon('');
protected function detail($id)
{
return Show::make($id, new GoodsType(), function (Show $show) {
$show->field('name');
$show->field('attr')->view('dcat-admin-goods::goods-type.grid-attr');
$show->field('spec')->view('dcat-admin-goods::goods-type.grid-attr');
$show->field('part')->view('dcat-admin-goods::goods-type.grid-attr');
return SpecForm::make()->payload(['type_id' => $this->id, 'reset' => false, 'spec' => $this->spec]);
});
$grid->column('part')->display(fn () => view('dcat-admin-goods::goods-type.grid-attr', ['value' => $this->part]))->modal(__('dcat-admin-goods::goods-type.fields.part'), function (Modal $modal) {
$modal->icon('');
return PartForm::make()->payload(['type_id' => $this->id, 'reset' => false, 'part' => $this->part]);
});
$show->disableDeleteButton();
$show->disableEditButton();
});
}
protected function form()
{
return Form::make(new GoodsType(), function (Form $form) {
$form->text('name');
$form->block(12, function (Form\BlockForm $form) {
$form->title('基本设置');
$form->text('name')->required();
$form->showFooter();
$form->backButton();
$form->disableResetButton();
});
// $form->textarea('attr');
// $form->textarea('spec');
// $form->textarea('part');
$form->block(12, function (Form\BlockForm $form) {
$form->title('属性');
$form->attr('attr')->header(['分组', '名称'])->keys(['name']);
});
$form->block(12, function (Form\BlockForm $form) {
$form->title('规格');
$form->attr('spec')->header(['名称', '可选值'])->keys(['name']);
});
$form->block(12, function (Form\BlockForm $form) {
$form->title('配件');
$form->attr('part')->header(['名称', '可选值'])->keys(['name']);
});
$form->disableResetButton();
$form->disableCreatingCheck();
$form->disableViewCheck();
$form->disableEditingCheck();
$form->deleting(function (Form $form) {
$data = $form->model()->toArray();
foreach ($data as $item) {
$id = data_get($item, 'id');
// 下面包含商品, 阻止删除
if (Goods::where('type_id', $id)->exists()) {
return $form->response()->error('请先删除关联的商品');
}
$ids = array_column($data, 'id');
// 下面包含商品, 阻止删除
if (Goods::whereIn('type_id', $ids)->exists()) {
return $form->response()->error('请先删除关联的商品');
}
});
});

View File

@ -1,5 +1,5 @@
<div class="table-responsive p-1" id="spec-{{$name}}">
<input type="hidden" name="{{$name}}" value="{{ json_encode($value, JSON_UNESCAPED_UNICODE) }}">
<input type="hidden" name="{{$name}}" value="{{ $value ? json_encode($value, JSON_UNESCAPED_UNICODE) : '' }}">
<table class="table table-bordered table-hover">
<thead>
<tr>
@ -10,6 +10,7 @@
</tr>
</thead>
<tbody>
@if($value)
@foreach($value as $index => $item)
<tr data-id="{{ $item['name'] }}">
<td rowspan="{{count($item['values']) + 2}}" class="editable">{{ $item['name'] }}</td>
@ -35,6 +36,7 @@
</td>
</tr>
@endforeach
@endif
<tr>
<td colspan="{{ count($headers) }}">
<input type="text" class="form-control add-attr-input" placeholder="添加 {{ $headers[0] }}">
@ -70,7 +72,7 @@
element.on('click', '.add-attr-button', function () {
var value = $('.add-attr-input').val()
if (!value) {
return Dcat.swal.warning(`请填写 ${headers.name}`)
return Dcat.swal.warning(`请填写 ${headers[0]}`)
}
addGroup(value)
@ -170,7 +172,7 @@
function addGroup(id) {
var tr = element.find('.add-attr-button').parents('tr')
var html = `<tr data-id="${id}">`
html += `<td rowspan="${keys.length}" class="editable">${id}</td>`
html += `<td rowspan="2" class="editable">${id}</td>`
html += '</tr>'
html += `<tr data-pid="${id}">`
for (let i = 1; i < headers.length; i++) {