添加商品创建添加规格
parent
e866f2ba51
commit
b436bbfdd7
|
|
@ -111,16 +111,6 @@ class ArticleCategoryController extends AdminController
|
||||||
$form->switch('is_recommend');
|
$form->switch('is_recommend');
|
||||||
$form->number('sort')->default(0);
|
$form->number('sort')->default(0);
|
||||||
|
|
||||||
$form->saving(function (Form $form) {
|
|
||||||
if ($form->isEditing()) {
|
|
||||||
if (!is_null($form->is_show) && (bool) $form->is_show !== $form->model()->is_show) {//如果改变显示隐藏
|
|
||||||
//影响下级分类;
|
|
||||||
$form->model()->descendants()->update(['is_show' => $form->is_show]);
|
|
||||||
//影响上级分类;能力有限无法实现
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$form->display('created_at');
|
$form->display('created_at');
|
||||||
$form->display('updated_at');
|
$form->display('updated_at');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,6 @@ class ProductSpuController extends AdminController
|
||||||
return Form::make(new ProductSpu(), function (Form $form) {
|
return Form::make(new ProductSpu(), function (Form $form) {
|
||||||
$form->display('id');
|
$form->display('id');
|
||||||
|
|
||||||
|
|
||||||
if ($form->isCreating()) {
|
if ($form->isCreating()) {
|
||||||
$form->select('one_category')->options(admin_route('api.product_categories'))->load('two_category', admin_route('api.product_categories'));
|
$form->select('one_category')->options(admin_route('api.product_categories'))->load('two_category', admin_route('api.product_categories'));
|
||||||
$form->select('two_category')->load('category_id', admin_route('api.product_categories'));
|
$form->select('two_category')->load('category_id', admin_route('api.product_categories'));
|
||||||
|
|
@ -121,6 +120,9 @@ class ProductSpuController extends AdminController
|
||||||
$form->currency('vip_price')->symbol('¥');
|
$form->currency('vip_price')->symbol('¥');
|
||||||
$form->select('attr_group')->options(ProductGroup::all()->pluck('name', 'id'));
|
$form->select('attr_group')->options(ProductGroup::all()->pluck('name', 'id'));
|
||||||
$form->selectAttr('attrs')->listen('attr_group');
|
$form->selectAttr('attrs')->listen('attr_group');
|
||||||
|
if ($form->isCreating()) {
|
||||||
|
$form->selectSpec('specs')->listen('attr_group');
|
||||||
|
}
|
||||||
|
|
||||||
$form->ignore(['one_category', 'two_category', 'attr_group']);
|
$form->ignore(['one_category', 'two_category', 'attr_group']);
|
||||||
$form->display('created_at');
|
$form->display('created_at');
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,23 @@ class SelectSpec extends Field
|
||||||
*/
|
*/
|
||||||
protected function prepareInputValue($value)
|
protected function prepareInputValue($value)
|
||||||
{
|
{
|
||||||
return $value;
|
$specs = $value;
|
||||||
|
if ($specs) {
|
||||||
|
$specs =json_decode($specs, true);
|
||||||
|
foreach ($specs as $key=> &$item) {
|
||||||
|
$item['items'] = array_filter(array_map(function ($value) {
|
||||||
|
if (!empty($value['value'])) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}, $item['specs']));
|
||||||
|
unset($item['specs']);
|
||||||
|
//如果该组无值,则删除该组
|
||||||
|
if (count($item['items']) < 1) {
|
||||||
|
unset($specs[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $specs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -30,4 +30,18 @@ class ArticleCategory extends Model
|
||||||
{
|
{
|
||||||
return $this->parent_id;
|
return $this->parent_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected static function booted()
|
||||||
|
{
|
||||||
|
parent::updated(function ($articleCategory) {
|
||||||
|
if ($articleCategory->wasChanged('is_show')) {//如果改变显示隐藏
|
||||||
|
//影响下级分类;
|
||||||
|
$articleCategory->descendants()->update(['is_show' => $articleCategory->is_show]);
|
||||||
|
//影响上级分类;能力有限无法实现
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,4 +41,9 @@ class ProductSpu extends Model
|
||||||
'sales',
|
'sales',
|
||||||
'release_at',
|
'release_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function specs()
|
||||||
|
{
|
||||||
|
return $this->hasMany(ProductSpuSpec::class, 'product_spu_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Casts\JsonArray;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class ProductSpuSpec extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'items' => JsonArray::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'product_spu_id',
|
||||||
|
'name',
|
||||||
|
'items',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
<tbody class="kv-table">
|
<tbody class="kv-table">
|
||||||
<tr v-for="(attr) in attr_group[attrIndex].attrs">
|
<tr v-for="(attr) in attr_group[attrIndex].attrs">
|
||||||
<td>
|
<td>
|
||||||
<div class="form-group ">
|
<div class="form-group " style="margin-bottom: 0 !important;">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<div class="help-block with-errors"></div>
|
<div class="help-block with-errors"></div>
|
||||||
<input name="" class="form-control" v-model="attr.name" disabled>
|
<input name="" class="form-control" v-model="attr.name" disabled>
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="form-group ">
|
<div class="form-group " style="margin-bottom: 0 !important;">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<div class="help-block with-errors"></div>
|
<div class="help-block with-errors"></div>
|
||||||
<input name="" class="form-control" v-model="attr.value">
|
<input name="" class="form-control" v-model="attr.value">
|
||||||
|
|
@ -84,7 +84,7 @@ function getTypeAttrs(group_id){
|
||||||
},
|
},
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
vm.attr_group = [];
|
vm.attr_group = [];
|
||||||
if(result.attrs.length > 0){
|
if(result.attrs && result.attrs.length > 0){
|
||||||
for(j = 0, len=result.attrs.length; j < len; j++){
|
for(j = 0, len=result.attrs.length; j < len; j++){
|
||||||
vm.attr_group.push(result.attrs[j]);
|
vm.attr_group.push(result.attrs[j]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,25 +14,42 @@
|
||||||
<label class="text-capitalize control-label" style="font-weight: bold;">@{{spec_group[specIndex].name}}</label>
|
<label class="text-capitalize control-label" style="font-weight: bold;">@{{spec_group[specIndex].name}}</label>
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<tbody class="kv-table">
|
<tbody class="kv-table">
|
||||||
<tr v-for="(spec) in spec_group[specIndex].specs">
|
<tr v-for="(spec, itemIndex) in spec_group[specIndex].specs">
|
||||||
<td>
|
<td>
|
||||||
<div class="form-group ">
|
<div class="form-group " style="margin-bottom: 0 !important;">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<div class="help-block with-errors"></div>
|
<select v-model="spec.name" class="form-control">
|
||||||
<input name="" class="form-control" v-model="spec.name" disabled>
|
<option value="NONE">未选择</option>
|
||||||
|
<option v-for="(options,id) in spec_items[specIndex]" :key="id" :value="options">@{{options}}</option>
|
||||||
|
</select>
|
||||||
|
<!-- <input name="" class="form-control" v-model="spec.name" disabled> -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="form-group ">
|
<div class="form-group " style="margin-bottom: 0 !important;">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<div class="help-block with-errors"></div>
|
|
||||||
<input name="" class="form-control" v-model="spec.value">
|
<input name="" class="form-control" v-model="spec.value">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
<td style="width: 85px;">
|
||||||
|
<div class="list-remove btn btn-white btn-sm pull-right" v-on:click="delSpecs(specIndex, itemIndex)">
|
||||||
|
<i class="feather icon-trash"> </i>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<td colspan="4">
|
||||||
|
<div class="list-add btn btn-primary btn-outline btn-sm pull-left" v-on:click="addSpecs(specIndex)">
|
||||||
|
<i class="feather icon-plus"></i> 新增
|
||||||
|
</div>
|
||||||
|
<div class="text-center"></div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -50,14 +67,35 @@
|
||||||
var vm = new Vue({
|
var vm = new Vue({
|
||||||
el: '#' + id,
|
el: '#' + id,
|
||||||
data: {
|
data: {
|
||||||
spec_group:[]
|
spec_group:[],
|
||||||
|
spec_items:[],
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
getSpecs() {
|
getSpecs() {
|
||||||
return;
|
return JSON.stringify(this.spec_group);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
addSpecs(specIndex){
|
||||||
|
this.spec_group[specIndex].specs.push(
|
||||||
|
{
|
||||||
|
name:"NONE",
|
||||||
|
value:""
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
delSpecs(specIndex, itemIndex){
|
||||||
|
console.log("123456")
|
||||||
|
if(this.spec_group[specIndex].specs[itemIndex]){
|
||||||
|
if(itemIndex >= 0){
|
||||||
|
let arr = this.spec_group[specIndex].specs;
|
||||||
|
this.spec_group[specIndex].specs = (arr.slice(0, itemIndex).concat(arr.slice(itemIndex+1,arr.length)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function getTypeSpecs(group_id){
|
function getTypeSpecs(group_id){
|
||||||
var url_path = "{{ admin_route('api.product_group_details') }}";
|
var url_path = "{{ admin_route('api.product_group_details') }}";
|
||||||
var goods_id = 0;
|
var goods_id = 0;
|
||||||
|
|
@ -73,7 +111,17 @@ function getTypeSpecs(group_id){
|
||||||
vm.spec_group = [];
|
vm.spec_group = [];
|
||||||
if(result.specs.length > 0){
|
if(result.specs.length > 0){
|
||||||
for(j = 0, len=result.specs.length; j < len; j++){
|
for(j = 0, len=result.specs.length; j < len; j++){
|
||||||
vm.spec_group.push(result.specs[j]);
|
vm.spec_group.push({
|
||||||
|
name:result.specs[j].name,
|
||||||
|
specs:[]
|
||||||
|
});
|
||||||
|
let items = [];
|
||||||
|
if(result.specs[j] && result.specs[j].specs.length > 0){
|
||||||
|
for(i = 0, llen = result.specs[j].specs.length; i <llen; i++){
|
||||||
|
items.push(result.specs[j].specs[i].name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vm.spec_items[j] = items;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue