From 0b20c48d9872dbe284603d4fec3493fd5710afab Mon Sep 17 00:00:00 2001
From: liangyuyan <1103300295@qq.com>
Date: Tue, 1 Sep 2020 18:08:03 +0800
Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E6=B7=BB=E5=8A=A0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Controllers/GoodsController.php | 41 ++++++++++++-------
app/Admin/Controllers/StoreController.php | 7 ++--
app/Admin/bootstrap.php | 49 +++++++++++++++++++++++
app/Models/Store.php | 2 +-
resources/lang/zh-CN/goods.php | 5 ++-
5 files changed, 83 insertions(+), 21 deletions(-)
diff --git a/app/Admin/Controllers/GoodsController.php b/app/Admin/Controllers/GoodsController.php
index bd86fa5..d29b8cc 100644
--- a/app/Admin/Controllers/GoodsController.php
+++ b/app/Admin/Controllers/GoodsController.php
@@ -10,6 +10,7 @@ use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;
use App\Models\GoodsType as GoodsTypeModel;
use App\Models\Store as StoreModel;
+use Dcat\Admin\Form\NestedForm;
class GoodsController extends AdminController
{
@@ -97,29 +98,39 @@ class GoodsController extends AdminController
// 店铺
$store = StoreModel::getStoreArray();
- $form->select('goods_type_id')->options($goodsTypeList);
- $form->select('store_id')->options($store);
+ $form->select('goods_type_id')->width(4)->required()->options($goodsTypeList);
+ $form->select('store_id')->width(4)->required()->options($store);
$form->text('name')->width(4)->required()->maxLength(20);
$form->image('cover_img')->width(2)->required();
- $form->text('price');
- $form->text('original_price');
- $form->text('vip_price');
- $form->text('good_unit');
+ $form->currency('price')->width(4)->required()->floatTwo()->symbol('¥');
+ $form->currency('original_price')->width(4)->required()->floatTwo()->symbol('¥');
+ $form->currency('vip_price')->width(4)->required()->floatTwo()->symbol('¥');
- $form->text('inventory');
- $form->text('restrict_num');
- $form->text('start_num');
- $form->text('is_infinite');
+ $form->text('good_unit')->width(4)->help('如:斤,个,盒,500克,1000克,1500克等')->saveAsJson();
- $form->text('details_imgs');
- $form->text('content');
- $form->text('sort');
+ $form->switch('is_infinite');
+ $form->number('inventory')->width(2)->required()->attribute('min', 1)->default(1);
+ $form->number('restrict_num')->width(2)->attribute('min', 0)->default(0)->help('0表示不限购');
+ $form->number('start_num')->width(2)->attribute('min', 1)->default(1);
- $form->text('tags');
- $form->text('spec');
+ $form->multipleImage('details_imgs');
+ $form->textarea('content');
+ $form->number('sort')->width(2);
+ $form->tags('tags')->options(['新品','热销','新鲜'])->saveAsJson();
+ $form->table('spec', function (NestedForm $table) {
+ $table->text('规格名称')->help('如:净含量:500克,包装:12个/盒,保质期:120天等');
+ $table->text('值');
+ });
+
+ $form->saving(function (Form $form){
+ $tage = $form->input('tags');
+ var_dump($tage);
+ $data = $form->input('spec');
+ dd($data);
+ });
});
}
}
diff --git a/app/Admin/Controllers/StoreController.php b/app/Admin/Controllers/StoreController.php
index 027cf75..fa90503 100644
--- a/app/Admin/Controllers/StoreController.php
+++ b/app/Admin/Controllers/StoreController.php
@@ -129,9 +129,10 @@ class StoreController extends AdminController
$form->text('link_name')->width(2)->required();
$form->mobile('link_tel')->width(2)->required();
$form->text('address')->width(8);
- $form->text('coordinates')->width(4)
- ->placeholder('输入 经纬度,如: 108.281552,22.83731')
- ->help("通过网址 https://lbs.amap.com/console/show/picker 获取经纬度");
+ $form->map('lat','lng','地址');
+ // $form->text('coordinates')->width(4)
+ // ->placeholder('输入 经纬度,如: 108.281552,22.83731')
+ // ->help("通过网址 https://lbs.amap.com/console/show/picker 获取经纬度");
$form->image('business_license')->width(2)->required();
$form->image('zm_img')->width(2)->required();
$form->image('fm_img')->width(2)->required();
diff --git a/app/Admin/bootstrap.php b/app/Admin/bootstrap.php
index 40cf396..ecf55c0 100644
--- a/app/Admin/bootstrap.php
+++ b/app/Admin/bootstrap.php
@@ -5,6 +5,7 @@ use Dcat\Admin\Grid;
use Dcat\Admin\Form;
use Dcat\Admin\Grid\Filter;
use Dcat\Admin\Show;
+use Dcat\Admin\Form\Field;
/**
* Dcat-admin - admin builder based on Laravel.
@@ -24,3 +25,51 @@ use Dcat\Admin\Show;
* Admin::js('/packages/prettydocs/js/main.js');
*
*/
+
+// 地图
+Form\Field\Map::collectAssets();
+
+// 官方例子,验证字符长度
+Field\Text::macro('len', function (int $length, ?string $error = null) {
+ // 前端验证逻辑扩展
+ Admin::script(
+ <<<'JS'
+Dcat.validator.extend('len', function ($el) {
+ console.log($el.val().length , $el.attr('data-len'));
+ return $el.val().length != $el.attr('data-len');
+});
+JS
+ );
+
+ // 同时添加后端验证逻辑,这个可以看需要
+ $this->rules('size:'.$length);
+
+ return $this->attribute([
+ 'data-len' => $length,
+ 'data-len-error' => str_replace(
+ [':attribute', ':len'],
+ [$this->label, $length],
+ $error ?: "只能输入:len个字符"
+ ),
+ ]);
+});
+
+/* 验证最多包含两位小数的浮点数,可不带小数 */
+Field\Text::macro('floatTwo', function (int $bit = 2, ?string $error = null) {
+ // 前端验证逻辑扩展
+ Admin::script(
+ <<<'JS'
+Dcat.validator.extend('floatTwo', function ($el) {
+ return !(/^(([1-9]{1}\d*)|(0{1}))(\.\d{0,2})?$/.test($el.val()));
+});
+JS
+ );
+
+ // 同时添加后端验证逻辑,这个可以看需要
+ // $this->rules('size:'.$length);
+
+ return $this->attribute([
+ 'data-floatTwo' => '^(([1-9]{1}\d*)|(0{1}))(\.\d{0,2})?$',
+ 'data-floatTwo-error' => "只能输入数字(最多包含两位小数)"
+ ]);
+});
diff --git a/app/Models/Store.php b/app/Models/Store.php
index 86c1f2b..6662ddb 100644
--- a/app/Models/Store.php
+++ b/app/Models/Store.php
@@ -80,7 +80,7 @@ class Store extends Model
$array = [];
if(count($list) > 0){
foreach ($list as $value) {
- $array[$value->id] = $value->type_name;
+ $array[$value->id] = $value->name;
}
}
diff --git a/resources/lang/zh-CN/goods.php b/resources/lang/zh-CN/goods.php
index fd222a0..8b871be 100644
--- a/resources/lang/zh-CN/goods.php
+++ b/resources/lang/zh-CN/goods.php
@@ -6,7 +6,7 @@ return [
],
'fields' => [
'name' => '商品名称',
- 'type_id' => '商品所属分类',
+ 'goods_type_id' => '商品所属分类',
'store_id' => '所属商家',
'cover_img' => '封面图',
'cover_img_url' => '封面图',
@@ -19,11 +19,12 @@ return [
'sort' => '排序',
'restrict_num' => '限购份数',
'start_num' => '起售份数',
- 'is_infinite' => '是否开启无限库存',
+ 'is_infinite' => '开启无限库存',
'good_unit' => '商品单位',
'tags' => '标签',
'details_imgs' => '详情图片',
'spec' => '规格',
+ 'unit_number' => '单位前的数'
],
'options' => [
],