diff --git a/app/AdminAgent/Controllers/AgentProductController.php b/app/AdminAgent/Controllers/AgentProductController.php index 1707402..d0f032c 100644 --- a/app/AdminAgent/Controllers/AgentProductController.php +++ b/app/AdminAgent/Controllers/AgentProductController.php @@ -190,13 +190,6 @@ class AgentProductController extends AdminController } else { $form->hidden('type')->value(0); if ($form->isCreating()) { - $js = file_get_contents(resource_path('js/select-supplier-product-change.js')); - $class = str_replace('\\', '\\\\', LoadSupplierSpec::class); - $js = str_replace( - ['`{{url}}`', '`{{class}}`'], - [route(admin_api_route_name('form')), $class], - $js - ); $form->selectTable('product_id', '供应商产品') ->required() ->help('产品列表显示的是该产品的标题和图片') @@ -204,7 +197,13 @@ class AgentProductController extends AdminController ->dialogWidth('80%;min-width:825px;') ->from(SelectProduct::make(['ids' => $form->model()->product_ids])) ->model(Product::class) - ->script($js); + ->script(" + $(function () { + $('input[name=\"product_id\"]').change(function () { + $('.spec-sync').click(); + }); + }); + "); } else { $form->hidden('product_id'); $form->display('product.title'); @@ -216,19 +215,24 @@ class AgentProductController extends AdminController $form->text('supplier_name', '规格')->disable()->customFormat(fn() => $this->product_spec['name'] ?? '供应商已删除规格'); $form->date('supplier_date', '日期')->disable()->customFormat(fn() => $this->product_spec['date'] ?? '供应商已删除规格'); $form->text('supplier_stock', '供应商库存')->disable()->customFormat(fn() => $this->product_spec['stock'] ?? 0); - $form->text('supplier_price', '供应商价')->disable()->customFormat(fn() => $this->product_spec['price'] ?? 0); + $form->text('supplier_cost_price', '供应商成本价')->disable()->customFormat(fn() => $this->product_spec['cost_price'] ?? 0); + $form->text('supplier_price', '建议销售价')->disable()->customFormat(fn() => $this->product_spec['price'] ?? 0); $form->text('stock', '您的库存')->required() //如果库存大于供应商库存,则取供应商库存 ->customFormat(fn() => isset($this->product_spec['stock'], $this->stock) && $this->stock > $this->product_spec['stock'] ? $this->product_spec['stock'] : $this->stock); $form->text('original_price', '您的市场价')->required(); - $form->text('price', '您的销售价')->required(); + $form->text('price', '您的销售价')->required() + //如果代理商价格小于供应商建议售价,则取供应商售价 + ->customFormat(fn() => isset($this->product_spec['price'], $this->price) && $this->price < $this->product_spec['price'] ? $this->product_spec['price'] : $this->price); + Admin::style('.has-many-spec .add.btn{display:none;} - .has-many-spec .field_date{width:100px!important;} + .has-many-spec .field_supplier_date{width:100px!important;} .has-many-spec .col-md-12{padding:0;} .has-many-spec .form-group{margin-bottom:0;} .has-many-spec .form-group .remove{margin-top:10px;} .has-many-spec .input-group-prepend{display:none;} .has-many-spec .input-group>.form-control:not(:first-child){border-radius:.25rem;}'); + $js = file_get_contents(resource_path('js/agent-spec-edit.js')); $class = str_replace('\\', '\\\\', LoadSupplierSpec::class); $js = str_replace( diff --git a/app/AdminAgent/Forms/LoadSupplierSpec.php b/app/AdminAgent/Forms/LoadSupplierSpec.php index dabfa9e..f784ade 100644 --- a/app/AdminAgent/Forms/LoadSupplierSpec.php +++ b/app/AdminAgent/Forms/LoadSupplierSpec.php @@ -16,31 +16,26 @@ class LoadSupplierSpec extends Form implements LazyRenderable public function handle(array $input) { $id = $input['product_id']; + $spec = ProductSpec::where('product_id', $id); if (!empty($input['agent_product_id'])) { $agent_spec = AgentProductSpec::where('agent_product_id', $input['agent_product_id']) ->pluck('product_spec_id')->toArray(); - $spec = ProductSpec::where('product_id', $id) - ->whereNotIn('id', $agent_spec ?? [0]) - ->orderBy('supplier_date') - ->get([ - 'id AS product_spec_id', - 'name AS supplier_name', - 'date AS supplier_date', - 'price AS supplier_price', - 'stock AS supplier_stock', - ])->toArray(); - } else { - $spec = ProductSpec::where('product_id', $id) - ->orderBy('supplier_date') - ->get([ - 'id AS product_spec_id', - 'name AS supplier_name', - 'date AS supplier_date', - 'price AS supplier_price', - 'stock AS supplier_stock', - ])->toArray(); + if ($agent_spec) { + $spec = $spec->whereNotIn('id', $agent_spec); + } } + $spec = $spec->orderBy('name')->orderBy('supplier_date') + ->get([ + 'id AS product_spec_id', + 'name AS supplier_name', + 'date AS supplier_date', + 'original_price AS supplier_original_price', + 'price AS supplier_price', + 'cost_price AS supplier_cost_price', + 'stock AS supplier_stock', + ])->toArray(); + return $this->response()->data($spec); } diff --git a/resources/js/agent-spec-edit.js b/resources/js/agent-spec-edit.js index 3fda5e9..7c5cb8c 100644 --- a/resources/js/agent-spec-edit.js +++ b/resources/js/agent-spec-edit.js @@ -1,6 +1,7 @@ $(function () { $('.has-many-spec .add.btn') - .after('