goods
parent
6bbcf27d18
commit
275b80a1f9
|
|
@ -38,4 +38,9 @@ class Attr extends Field
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// protected function prepareInputValue($value)
|
||||||
|
// {
|
||||||
|
// return $value;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class AttrForm extends Form implements LazyRenderable
|
||||||
|
|
||||||
public function form()
|
public function form()
|
||||||
{
|
{
|
||||||
$this->fill(['attr' => $this->payload['attr']]);
|
$this->fill(['attr' => data_get($this->payload, 'attr')]);
|
||||||
|
|
||||||
$this->attr('attr')->header(['分组', '名称'])->keys(['name']);
|
$this->attr('attr')->header(['分组', '名称'])->keys(['name']);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,8 @@ namespace Peidikeji\Goods\Http\Admin;
|
||||||
use Dcat\Admin\Admin;
|
use Dcat\Admin\Admin;
|
||||||
use Dcat\Admin\Form;
|
use Dcat\Admin\Form;
|
||||||
use Dcat\Admin\Grid;
|
use Dcat\Admin\Grid;
|
||||||
use Dcat\Admin\Grid\Displayers\Modal;
|
|
||||||
use Dcat\Admin\Http\Controllers\AdminController;
|
use Dcat\Admin\Http\Controllers\AdminController;
|
||||||
use Peidikeji\Goods\Form\GoodsType\AttrForm;
|
use Dcat\Admin\Show;
|
||||||
use Peidikeji\Goods\Form\GoodsType\PartForm;
|
|
||||||
use Peidikeji\Goods\Form\GoodsType\SpecForm;
|
|
||||||
use Peidikeji\Goods\Models\Goods;
|
use Peidikeji\Goods\Models\Goods;
|
||||||
use Peidikeji\Goods\Models\GoodsType;
|
use Peidikeji\Goods\Models\GoodsType;
|
||||||
|
|
||||||
|
|
@ -28,50 +25,62 @@ class GoodsTypeController extends AdminController
|
||||||
{
|
{
|
||||||
return Grid::make(new GoodsType(), function (Grid $grid) {
|
return Grid::make(new GoodsType(), function (Grid $grid) {
|
||||||
$grid->disableRowSelector();
|
$grid->disableRowSelector();
|
||||||
$grid->disableViewButton();
|
|
||||||
$grid->disableEditButton();
|
|
||||||
|
|
||||||
$grid->column('name')->editable();
|
$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) {
|
$grid->column('attr')->display(fn () => view('dcat-admin-goods::goods-type.grid-attr', ['value' => $this->attr]));
|
||||||
$modal->icon('');
|
$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]);
|
protected function detail($id)
|
||||||
});
|
{
|
||||||
$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) {
|
return Show::make($id, new GoodsType(), function (Show $show) {
|
||||||
$modal->icon('');
|
$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]);
|
$show->disableDeleteButton();
|
||||||
});
|
$show->disableEditButton();
|
||||||
$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]);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function form()
|
protected function form()
|
||||||
{
|
{
|
||||||
return Form::make(new GoodsType(), function (Form $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->block(12, function (Form\BlockForm $form) {
|
||||||
// $form->textarea('spec');
|
$form->title('属性');
|
||||||
// $form->textarea('part');
|
$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->disableCreatingCheck();
|
||||||
$form->disableViewCheck();
|
$form->disableViewCheck();
|
||||||
$form->disableEditingCheck();
|
$form->disableEditingCheck();
|
||||||
|
|
||||||
$form->deleting(function (Form $form) {
|
$form->deleting(function (Form $form) {
|
||||||
$data = $form->model()->toArray();
|
$data = $form->model()->toArray();
|
||||||
foreach ($data as $item) {
|
$ids = array_column($data, 'id');
|
||||||
$id = data_get($item, 'id');
|
// 下面包含商品, 阻止删除
|
||||||
// 下面包含商品, 阻止删除
|
if (Goods::whereIn('type_id', $ids)->exists()) {
|
||||||
if (Goods::where('type_id', $id)->exists()) {
|
return $form->response()->error('请先删除关联的商品');
|
||||||
return $form->response()->error('请先删除关联的商品');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<div class="table-responsive p-1" id="spec-{{$name}}">
|
<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">
|
<table class="table table-bordered table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@if($value)
|
||||||
@foreach($value as $index => $item)
|
@foreach($value as $index => $item)
|
||||||
<tr data-id="{{ $item['name'] }}">
|
<tr data-id="{{ $item['name'] }}">
|
||||||
<td rowspan="{{count($item['values']) + 2}}" class="editable">{{ $item['name'] }}</td>
|
<td rowspan="{{count($item['values']) + 2}}" class="editable">{{ $item['name'] }}</td>
|
||||||
|
|
@ -35,6 +36,7 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
@endif
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="{{ count($headers) }}">
|
<td colspan="{{ count($headers) }}">
|
||||||
<input type="text" class="form-control add-attr-input" placeholder="添加 {{ $headers[0] }}">
|
<input type="text" class="form-control add-attr-input" placeholder="添加 {{ $headers[0] }}">
|
||||||
|
|
@ -70,7 +72,7 @@
|
||||||
element.on('click', '.add-attr-button', function () {
|
element.on('click', '.add-attr-button', function () {
|
||||||
var value = $('.add-attr-input').val()
|
var value = $('.add-attr-input').val()
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return Dcat.swal.warning(`请填写 ${headers.name}`)
|
return Dcat.swal.warning(`请填写 ${headers[0]}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
addGroup(value)
|
addGroup(value)
|
||||||
|
|
@ -170,7 +172,7 @@
|
||||||
function addGroup(id) {
|
function addGroup(id) {
|
||||||
var tr = element.find('.add-attr-button').parents('tr')
|
var tr = element.find('.add-attr-button').parents('tr')
|
||||||
var html = `<tr data-id="${id}">`
|
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>'
|
||||||
html += `<tr data-pid="${id}">`
|
html += `<tr data-pid="${id}">`
|
||||||
for (let i = 1; i < headers.length; i++) {
|
for (let i = 1; i < headers.length; i++) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue