mirror of
https://gitee.com/zongzhige/shopxo.git
synced 2026-06-06 03:56:57 +08:00
商品参数模板新增商品分类关联
This commit is contained in:
@ -17,24 +17,24 @@ use app\service\ResourcesService;
|
||||
use app\service\GoodsService;
|
||||
use app\service\RegionService;
|
||||
use app\service\BrandService;
|
||||
use app\service\GoodsParamsService;
|
||||
use app\service\GoodsSpecService;
|
||||
|
||||
/**
|
||||
* 商品管理
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 0.0.1
|
||||
* @datetime 2016-12-01T21:51:08+0800
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2021-03-31
|
||||
* @desc description
|
||||
*/
|
||||
class Goods extends Base
|
||||
{
|
||||
/**
|
||||
* 列表
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 0.0.1
|
||||
* @datetime 2016-12-06T21:31:53+0800
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2021-03-31
|
||||
* @desc description
|
||||
*/
|
||||
public function Index()
|
||||
{
|
||||
@ -43,10 +43,11 @@ class Goods extends Base
|
||||
|
||||
/**
|
||||
* 详情
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @datetime 2019-08-05T08:21:54+0800
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2021-03-31
|
||||
* @desc description
|
||||
*/
|
||||
public function Detail()
|
||||
{
|
||||
@ -69,10 +70,11 @@ class Goods extends Base
|
||||
|
||||
/**
|
||||
* 添加/编辑页面
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 0.0.1
|
||||
* @datetime 2016-12-14T21:37:02+0800
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2021-03-31
|
||||
* @desc description
|
||||
*/
|
||||
public function SaveInfo()
|
||||
{
|
||||
@ -113,28 +115,15 @@ class Goods extends Base
|
||||
// 获取商品编辑参数
|
||||
$assign['parameters'] = GoodsService::GoodsEditParameters($data['id']);
|
||||
|
||||
// 商品规格模板
|
||||
$spec_template = GoodsSpecService::GoodsCategorySpecTemplateList(['category_ids'=>$data['category_ids']]);
|
||||
$assign['goods_spec_template_list'] = $spec_template['data'];
|
||||
// 基础模板
|
||||
$goods_base_template = GoodsService::GoodsBaseTemplate(['category_ids'=>$data['category_ids']]);
|
||||
$assign['goods_base_template'] = $goods_base_template['data'];
|
||||
}
|
||||
|
||||
// 规格扩展数据
|
||||
$goods_spec_extends = GoodsService::GoodsSpecificationsExtends($params);
|
||||
$assign['goods_specifications_extends'] = $goods_spec_extends['data'];
|
||||
|
||||
// 商品参数模板
|
||||
$data_params = [
|
||||
'm' => 0,
|
||||
'n' => 0,
|
||||
'where' => [
|
||||
['is_enable', '=', 1],
|
||||
['config_count', '>', 0],
|
||||
],
|
||||
'field' => 'id,name',
|
||||
];
|
||||
$params_template = GoodsParamsService::GoodsParamsTemplateList($data_params);
|
||||
$assign['goods_params_template_list'] = $params_template['data'];
|
||||
|
||||
// 是否拷贝
|
||||
$assign['is_copy'] = (isset($params['is_copy']) && $params['is_copy'] == 1) ? 1 : 0;
|
||||
|
||||
@ -161,10 +150,11 @@ class Goods extends Base
|
||||
|
||||
/**
|
||||
* 添加/编辑
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 0.0.1
|
||||
* @datetime 2016-12-14T21:37:02+0800
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2021-03-31
|
||||
* @desc description
|
||||
*/
|
||||
public function Save()
|
||||
{
|
||||
@ -182,10 +172,11 @@ class Goods extends Base
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 0.0.1
|
||||
* @datetime 2016-12-15T11:03:30+0800
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2021-03-31
|
||||
* @desc description
|
||||
*/
|
||||
public function Delete()
|
||||
{
|
||||
@ -203,10 +194,11 @@ class Goods extends Base
|
||||
|
||||
/**
|
||||
* 状态更新
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 0.0.1
|
||||
* @datetime 2017-01-12T22:23:06+0800
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2021-03-31
|
||||
* @desc description
|
||||
*/
|
||||
public function StatusUpdate()
|
||||
{
|
||||
@ -223,13 +215,14 @@ class Goods extends Base
|
||||
}
|
||||
|
||||
/**
|
||||
* 规格模板
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 0.0.1
|
||||
* @datetime 2017-01-12T22:23:06+0800
|
||||
*/
|
||||
public function SpecTemplate()
|
||||
* 基础模板
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2021-03-31
|
||||
* @desc description
|
||||
*/
|
||||
public function BaseTemplate()
|
||||
{
|
||||
// 是否ajax
|
||||
if(!IS_AJAX)
|
||||
@ -240,7 +233,7 @@ class Goods extends Base
|
||||
// 开始操作
|
||||
$params = $this->data_post;
|
||||
$params['admin'] = $this->admin;
|
||||
return ApiService::ApiDataReturn(GoodsSpecService::GoodsCategorySpecTemplateList($params));
|
||||
return ApiService::ApiDataReturn(GoodsService::GoodsBaseTemplate($params));
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -12,6 +12,7 @@ namespace app\admin\controller;
|
||||
|
||||
use app\admin\controller\Base;
|
||||
use app\service\ApiService;
|
||||
use app\service\GoodsService;
|
||||
use app\service\GoodsParamsService;
|
||||
|
||||
/**
|
||||
@ -85,6 +86,9 @@ class GoodsParamsTemplate extends Base
|
||||
|
||||
// 参数配置
|
||||
'parameters' => empty($data['config_data']) ? [] : $data['config_data'],
|
||||
|
||||
// 商品分类
|
||||
'goods_category_list' => GoodsService::GoodsCategoryList(['where'=>[['pid', '=', 0]]]),
|
||||
];
|
||||
|
||||
// 编辑页面钩子
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\form;
|
||||
|
||||
use app\service\GoodsService;
|
||||
|
||||
/**
|
||||
* 商品参数动态表格
|
||||
* @author Devil
|
||||
@ -23,6 +25,24 @@ class GoodsParamsTemplate
|
||||
// 基础条件
|
||||
public $condition_base = [];
|
||||
|
||||
// 商品分类
|
||||
public $goods_category_list;
|
||||
|
||||
/**
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2020-06-29
|
||||
* @desc description
|
||||
* @param [array] $params [输入参数]
|
||||
*/
|
||||
public function __construct($params = [])
|
||||
{
|
||||
// 商品分类
|
||||
$res = GoodsService::GoodsCategoryList(['where'=>[['pid', '=', 0]]]);
|
||||
$this->goods_category_list = empty($res) ? [] : array_column($res, 'name', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 入口
|
||||
* @author Devil
|
||||
@ -55,6 +75,18 @@ class GoodsParamsTemplate
|
||||
'align' => 'center',
|
||||
'width' => 80,
|
||||
],
|
||||
[
|
||||
'label' => '商品分类',
|
||||
'view_type' => 'field',
|
||||
'view_key' => 'category_id',
|
||||
'view_data' => $this->goods_category_list,
|
||||
'search_config' => [
|
||||
'form_type' => 'select',
|
||||
'where_type' => 'in',
|
||||
'data' => $this->goods_category_list,
|
||||
'is_multiple' => 1,
|
||||
],
|
||||
],
|
||||
[
|
||||
'label' => '名称',
|
||||
'view_type' => 'field',
|
||||
|
||||
@ -81,7 +81,6 @@ class GoodsSpecTemplate
|
||||
'view_data' => $this->goods_category_list,
|
||||
'search_config' => [
|
||||
'form_type' => 'select',
|
||||
'form_name' => 'category_id',
|
||||
'where_type' => 'in',
|
||||
'data' => $this->goods_category_list,
|
||||
'is_multiple' => 1,
|
||||
|
||||
@ -77,7 +77,7 @@
|
||||
<div class="am-form-group">
|
||||
<label>商品分类<span class="am-form-group-label-tips-must">至少选择一个</span></label>
|
||||
<br />
|
||||
<select name="category_id" class="am-radius chosen-select" multiple="multiple" minchecked="1" data-placeholder="请选择..." data-validation-message="请至少选择一个商品分类" required>
|
||||
<select name="category_id" class="am-radius chosen-select" multiple="multiple" minchecked="1" data-placeholder="请选择..." data-validation-message="请至少选择一个商品分类" data-base-template-url="{{:MyUrl('admin/goods/basetemplate')}}" required>
|
||||
{{if !empty($goods_category_list)}}
|
||||
{{foreach $goods_category_list as $v}}
|
||||
<option value="{{$v.id}}" {{if !empty($data['category_ids']) and in_array($v['id'], $data['category_ids'])}}selected{{/if}}>一级 - {{$v.name}}</option>
|
||||
@ -211,11 +211,11 @@
|
||||
</span>
|
||||
<div class="am-dropdown-content parameters-quick-config">
|
||||
<div class="am-margin-bottom-sm">
|
||||
<select class="am-radius chosen-select goods-template-params-select" data-placeholder="请选择模板..." data-validation-message="选择商品参数模板">
|
||||
<option value="">请选择模板...</option>
|
||||
{{if !empty($goods_params_template_list) and is_array($goods_params_template_list)}}
|
||||
{{foreach $goods_params_template_list as $v}}
|
||||
<option value="{{:urlencode(json_encode($v['config_data'], JSON_UNESCAPED_UNICODE))}}">{{$v.name}}</option>
|
||||
<select class="am-radius chosen-select" data-placeholder="商品参数模板..." data-validation-message="请选择商品参数模板">
|
||||
<option value="">商品参数模板...</option>
|
||||
{{if !empty($goods_base_template) and !empty($goods_base_template['params']) and is_array($goods_base_template['params'])}}
|
||||
{{foreach $goods_base_template.params as $v}}
|
||||
<option value="{{:urlencode(json_encode($v['config_data'], JSON_UNESCAPED_UNICODE))}}" data-origin-name="{{$v.name}}">{{$v.name}}</option>
|
||||
{{/foreach}}
|
||||
{{/if}}
|
||||
</select>
|
||||
|
||||
@ -8,12 +8,15 @@
|
||||
<p>3. 商品添加成功后,仓库管理->仓库商品中添加并配置库存</p>
|
||||
</div>
|
||||
<!-- 规格模板 -->
|
||||
<div class="am-inline-block business-operations-submit" id="specifications-quick-container" data-url="{{:MyUrl('admin/goods/spectemplate')}}">
|
||||
<select class="am-radius chosen-select goods-template-spec-select" data-placeholder="商品规格模板..." data-validation-message="请选择商品规格模板">
|
||||
<div class="am-inline-block business-operations-submit" id="specifications-quick-container"
|
||||
data-spec-template-tips="规格模板数据有误"
|
||||
data-spec-template-name-tips="相同规格名称已经存在"
|
||||
>
|
||||
<select class="am-radius chosen-select" data-placeholder="商品规格模板..." data-validation-message="请选择商品规格模板">
|
||||
<option value="">商品规格模板...</option>
|
||||
{{if !empty($goods_spec_template_list)}}
|
||||
{{foreach $goods_spec_template_list as $v}}
|
||||
<option value="{{$v.content}}">{{$v.name}}</option>
|
||||
{{if !empty($goods_base_template) and !empty($goods_base_template['spec']) and is_array($goods_base_template['spec'])}}
|
||||
{{foreach $goods_base_template.spec as $v}}
|
||||
<option value="{{$v.content}}" data-origin-name="{{$v.name}}">{{$v.name}}</option>
|
||||
{{/foreach}}
|
||||
{{/if}}
|
||||
</select>
|
||||
|
||||
@ -5,11 +5,22 @@
|
||||
<div class="content">
|
||||
<!-- form start -->
|
||||
<form class="am-form form-validation am-form-full-screen" action="{{:MyUrl('admin/goodsparamstemplate/save')}}" method="POST" request-type="ajax-reload" request-value="parent">
|
||||
<div class="am-form-group">
|
||||
<label>商品分类<span class="am-form-group-label-tips-must">必选、包含子级</span></label>
|
||||
<br />
|
||||
<select name="category_id" class="am-radius chosen-select" data-placeholder="请选择..." data-validation-message="请选择商品分类" required>
|
||||
{{if !empty($goods_category_list)}}
|
||||
<option value="">请选择...</option>
|
||||
{{foreach $goods_category_list as $v}}
|
||||
<option value="{{$v.id}}" {{if isset($data['category_id']) and $data['category_id'] eq $v['id']}}selected{{/if}}>{{$v.name}}</option>
|
||||
{{/foreach}}
|
||||
{{/if}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="am-form-group">
|
||||
<label>名称<span class="am-form-group-label-tips-must">必填</span></label>
|
||||
<input type="text" name="name" placeholder="名称" minlength="2" maxlength="30" data-validation-message="名称格式 2~30 个字符" class="am-radius" {{if !empty($data['name'])}} value="{{$data.name}}"{{/if}} required />
|
||||
</div>
|
||||
|
||||
<div class="business-form-group">
|
||||
<label class="block">参数配置<span class="am-form-group-label-tips-must">必填</span></label>
|
||||
{{include file="public/goodsparamstemplate/tips" /}}
|
||||
@ -37,7 +48,6 @@
|
||||
<span class="am-text-warning am-margin-left-sm">可直接点中参数行拖拽排序或点击上下移动</span>
|
||||
{{include file="public/goodsparamstemplate/table" /}}
|
||||
</div>
|
||||
|
||||
<div class="am-form-group">
|
||||
<label class="block">是否启用</label>
|
||||
<input name="is_enable" value="1" type="checkbox" data-off-text="否" data-on-text="是" data-size="xs" data-on-color="success" data-off-color="default" data-handle-width="50" data-am-switch {{if (isset($data['is_enable']) and $data['is_enable'] eq 1) or !isset($data['is_enable'])}}checked="true"{{/if}} />
|
||||
|
||||
@ -21,12 +21,10 @@
|
||||
<label>规格名称<span class="am-form-group-label-tips-must">必填</span></label>
|
||||
<input type="text" name="name" placeholder="规格名称" minlength="1" maxlength="30" data-validation-message="规格名称格式1~30个字符" class="am-radius" {{if !empty($data['name'])}} value="{{$data.name}}"{{/if}} required />
|
||||
</div>
|
||||
|
||||
<div class="am-form-group">
|
||||
<label>规格值<span class="am-form-group-label-tips-must">必填</span></label>
|
||||
<input type="text" name="content" placeholder="规格值(输入回车可实现多个)" minlength="1" maxlength="1000" data-validation-message="规格值格式1~1000个字符" class="am-radius" {{if !empty($data['content'])}} value="{{$data.content}}"{{/if}} required data-am-tagsinput />
|
||||
</div>
|
||||
|
||||
<div class="am-form-group">
|
||||
<label class="block">是否启用</label>
|
||||
<input name="is_enable" value="1" type="checkbox" data-off-text="否" data-on-text="是" data-size="xs" data-on-color="success" data-off-color="default" data-handle-width="50" data-am-switch {{if (isset($data['is_enable']) and $data['is_enable'] eq 1) or !isset($data['is_enable'])}}checked="true"{{/if}} />
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
namespace app\service;
|
||||
|
||||
use think\facade\Db;
|
||||
use app\service\GoodsService;
|
||||
|
||||
/**
|
||||
* 商品参数服务层
|
||||
@ -23,7 +24,7 @@ use think\facade\Db;
|
||||
class GoodsParamsService
|
||||
{
|
||||
/**
|
||||
* 列表
|
||||
* 商品分类参数模板
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
@ -31,17 +32,34 @@ class GoodsParamsService
|
||||
* @desc description
|
||||
* @param [array] $params [输入参数]
|
||||
*/
|
||||
public static function GoodsParamsTemplateList($params = [])
|
||||
public static function GoodsCategoryParamsTemplateList($params = [])
|
||||
{
|
||||
$where = empty($params['where']) ? [] : $params['where'];
|
||||
$field = empty($params['field']) ? '*' : $params['field'];
|
||||
$order_by = empty($params['order_by']) ? 'id desc' : trim($params['order_by']);
|
||||
$m = isset($params['m']) ? intval($params['m']) : 0;
|
||||
$n = isset($params['n']) ? intval($params['n']) : 10;
|
||||
// 请求类型
|
||||
$p = [
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'category_ids',
|
||||
'error_msg' => '请选择商品分类',
|
||||
],
|
||||
];
|
||||
$ret = ParamsChecked($params, $p);
|
||||
if($ret !== true)
|
||||
{
|
||||
return DataReturn($ret, -1);
|
||||
}
|
||||
|
||||
// 获取列表
|
||||
$data = Db::name('GoodsParamsTemplate')->where($where)->order($order_by)->field($field)->limit($m, $n)->select()->toArray();
|
||||
return DataReturn(MyLang('common.handle_success'), 0, self::GoodsParamsTemplateListHandle($data, $params));
|
||||
// 获取分类下所有分类id
|
||||
$data = [];
|
||||
$ids = GoodsService::GoodsCategoryParentIds($params['category_ids']);
|
||||
if(!empty($ids))
|
||||
{
|
||||
$where = [
|
||||
['category_id', 'in', $ids],
|
||||
['is_enable', '=', 1],
|
||||
];
|
||||
$data = self::GoodsParamsTemplateListHandle(Db::name('GoodsParamsTemplate')->where($where)->field('id,name,config_count')->order('id desc')->select()->toArray(), $params);
|
||||
}
|
||||
return DataReturn(MyLang('common.operate_success'), 0, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,11 +93,11 @@ class GoodsParamsService
|
||||
$v['config_data'] = empty($config[$v['id']]) ? [] : $config[$v['id']];
|
||||
|
||||
// 时间
|
||||
if(isset($v['add_time']))
|
||||
if(array_key_exists('add_time', $v))
|
||||
{
|
||||
$v['add_time'] = date('Y-m-d H:i:s', $v['add_time']);
|
||||
}
|
||||
if(isset($v['upd_time']))
|
||||
if(array_key_exists('upd_time', $v))
|
||||
{
|
||||
$v['upd_time'] = empty($v['upd_time']) ? '' : date('Y-m-d H:i:s', $v['upd_time']);
|
||||
}
|
||||
@ -101,6 +119,11 @@ class GoodsParamsService
|
||||
{
|
||||
// 请求类型
|
||||
$p = [
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'category_id',
|
||||
'error_msg' => '请选择商品分类',
|
||||
],
|
||||
[
|
||||
'checked_type' => 'length',
|
||||
'key_name' => 'name',
|
||||
@ -123,6 +146,7 @@ class GoodsParamsService
|
||||
|
||||
// 数据
|
||||
$data = [
|
||||
'category_id' => intval($params['category_id']),
|
||||
'name' => $params['name'],
|
||||
'config_count' => count($config['data']),
|
||||
'is_enable' => isset($params['is_enable']) ? intval($params['is_enable']) : 0,
|
||||
|
||||
@ -17,6 +17,7 @@ use app\service\ResourcesService;
|
||||
use app\service\BrandService;
|
||||
use app\service\RegionService;
|
||||
use app\service\WarehouseGoodsService;
|
||||
use app\service\GoodsSpecService;
|
||||
use app\service\GoodsParamsService;
|
||||
use app\service\GoodsCommentsService;
|
||||
|
||||
@ -3186,5 +3187,42 @@ class GoodsService
|
||||
];
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品基础模板
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2022-08-26
|
||||
* @desc description
|
||||
* @param [array] $params [输入参数]
|
||||
*/
|
||||
public static function GoodsBaseTemplate($params = [])
|
||||
{
|
||||
// 请求类型
|
||||
$p = [
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'category_ids',
|
||||
'error_msg' => '请选择商品分类',
|
||||
],
|
||||
];
|
||||
$ret = ParamsChecked($params, $p);
|
||||
if($ret !== true)
|
||||
{
|
||||
return DataReturn($ret, -1);
|
||||
}
|
||||
|
||||
// 规格模板
|
||||
$spec = GoodsSpecService::GoodsCategorySpecTemplateList($params);
|
||||
|
||||
// 参数模板
|
||||
$parameter = GoodsParamsService::GoodsCategoryParamsTemplateList($params);
|
||||
|
||||
return DataReturn(MyLang('common.operate_success'), 0, [
|
||||
'spec' => $spec['data'],
|
||||
'params' => $parameter['data'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -57,7 +57,7 @@ class GoodsSpecService
|
||||
['category_id', 'in', $ids],
|
||||
['is_enable', '=', 1],
|
||||
];
|
||||
$data = self::GoodsSpecTemplateListHandle(Db::name('GoodsSpecTemplate')->where($where)->field('id,name,content')->order('id desc')->select()->toArray());
|
||||
$data = self::GoodsSpecTemplateListHandle(Db::name('GoodsSpecTemplate')->where($where)->field('id,name,content')->order('id desc')->select()->toArray(), $params);
|
||||
}
|
||||
return DataReturn(MyLang('common.operate_success'), 0, $data);
|
||||
}
|
||||
|
||||
@ -233,6 +233,9 @@ ul li {
|
||||
#specifications-quick-container .chosen-container {
|
||||
min-width: 120px;
|
||||
}
|
||||
#specifications-quick-container select {
|
||||
border: 0px;
|
||||
}
|
||||
#specifications-quick-container .chosen-container-single .chosen-default,
|
||||
#specifications-quick-container .chosen-container-single .chosen-single {
|
||||
border-color: transparent !important;
|
||||
|
||||
@ -708,7 +708,7 @@ $(function()
|
||||
});
|
||||
|
||||
// 商品参数模板选择
|
||||
$('.goods-template-params-select').on('change', function()
|
||||
$('#parameters-quick-container select').on('change', function()
|
||||
{
|
||||
var value = $(this).val() || null;
|
||||
if(value != null)
|
||||
@ -722,13 +722,14 @@ $(function()
|
||||
$('#parameters-quick-container textarea').val(value || '');
|
||||
});
|
||||
|
||||
// 商品规格模板数据获取、选择商品分类后异步读取
|
||||
// 商品规格模板和参数模板数据获取、选择商品分类后异步读取
|
||||
var $spec_quick = $('#specifications-quick-container');
|
||||
var $params_quick = $('#parameters-quick-container');
|
||||
$('select[name="category_id"]').on('change', function()
|
||||
{
|
||||
var value = $(this).val() || '';
|
||||
$.ajax({
|
||||
url: RequestUrlHandle($spec_quick.data('url')),
|
||||
url: RequestUrlHandle($(this).data('base-template-url')),
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
timeout: 305000,
|
||||
@ -743,18 +744,41 @@ $(function()
|
||||
$(this).remove();
|
||||
}
|
||||
});
|
||||
// 循环处理得到的最新模板
|
||||
if((result.data || null) != null && result.data.length > 0)
|
||||
$params_quick.find('select option').each(function(k, v)
|
||||
{
|
||||
var html = '';
|
||||
for(var i in result.data)
|
||||
if(k > 0)
|
||||
{
|
||||
html += '<option value="'+result.data[i]['content']+'">'+result.data[i]['name']+'</option>';
|
||||
$(this).remove();
|
||||
}
|
||||
});
|
||||
// 循环处理得到的最新模板
|
||||
if((result.data || null) != null)
|
||||
{
|
||||
// 规格模板
|
||||
if((result.data.spec || null) != null && result.data.spec.length > 0)
|
||||
{
|
||||
var html = '';
|
||||
for(var i in result.data.spec)
|
||||
{
|
||||
html += '<option value="'+result.data.spec[i]['content']+'" data-origin-name="'+result.data.spec[i]['name']+'">'+result.data.spec[i]['name']+'</option>';
|
||||
}
|
||||
$spec_quick.find('select').append(html);
|
||||
}
|
||||
|
||||
// 参数模板
|
||||
if((result.data.params || null) != null && result.data.params.length > 0)
|
||||
{
|
||||
var html = '';
|
||||
for(var i in result.data.params)
|
||||
{
|
||||
html += '<option value="'+encodeURIComponent(JSON.stringify(result.data.params[i]['config_data']))+'" data-origin-name="'+result.data.spec[i]['name']+'">'+result.data.params[i]['name']+'</option>';
|
||||
}
|
||||
$params_quick.find('select').append(html);
|
||||
}
|
||||
$spec_quick.find('select').append(html);
|
||||
}
|
||||
// 更新select组件
|
||||
$spec_quick.find('select').trigger('chosen:updated');
|
||||
$params_quick.find('select').trigger('chosen:updated');
|
||||
},
|
||||
error: function(xhr, type)
|
||||
{
|
||||
@ -765,40 +789,43 @@ $(function()
|
||||
// 规格模板选择
|
||||
$(document).on('click', '#specifications-quick-container select option, #specifications-quick-container .chosen-container .chosen-results li.active-result', function()
|
||||
{
|
||||
var value = $spec_quick.find('select').val() || null;
|
||||
if(value == null)
|
||||
if($(this).index() > 0)
|
||||
{
|
||||
Prompt($spec_quick.data('spec-template-tips') || '规格模板数据有误');
|
||||
return false;
|
||||
}
|
||||
value = value.split(',');
|
||||
var name = $spec_quick.find('select').find('option:selected').text();
|
||||
|
||||
// 名称是否已存在
|
||||
var status = true;
|
||||
$('.spec-quick .goods-specifications table tbody tr').each(function()
|
||||
{
|
||||
var temp_name = $(this).find('td:first').find('input').val();
|
||||
if(temp_name == name)
|
||||
var value = $spec_quick.find('select').val() || null;
|
||||
if(value == null)
|
||||
{
|
||||
status = false;
|
||||
Prompt($spec_quick.data('spec-template-tips') || '规格模板数据有误');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if(!status)
|
||||
{
|
||||
Prompt(($spec_quick.data('spec-template-name-tips') || '相同规格名称已经存在')+'('+name+')');
|
||||
return false;
|
||||
}
|
||||
value = value.split(',');
|
||||
var name = $spec_quick.find('select').find('option:selected').data('origin-name');
|
||||
|
||||
// 模拟点击添加一个规格类型
|
||||
$('.quick-spec-title-add').trigger('click');
|
||||
// 填入规格名称
|
||||
$('.spec-quick .goods-specifications table tbody tr:last td:first input').val(name);
|
||||
// 加入规格值
|
||||
for(var i in value)
|
||||
{
|
||||
$('.spec-quick .goods-specifications table tbody tr:last td:last .quick-spec-value-add').trigger('click');
|
||||
$('.spec-quick .goods-specifications table tbody tr:last td:last .value-item:eq(-2) input').val(value[i]);
|
||||
// 名称是否已存在
|
||||
var status = true;
|
||||
$('.spec-quick .goods-specifications table tbody tr').each(function()
|
||||
{
|
||||
var temp_name = $(this).find('td:first').find('input').val();
|
||||
if(temp_name == name)
|
||||
{
|
||||
status = false;
|
||||
}
|
||||
});
|
||||
if(!status)
|
||||
{
|
||||
Prompt(($spec_quick.data('spec-template-name-tips') || '相同规格名称已经存在')+'('+name+')');
|
||||
return false;
|
||||
}
|
||||
|
||||
// 模拟点击添加一个规格类型
|
||||
$('.quick-spec-title-add').trigger('click');
|
||||
// 填入规格名称
|
||||
$('.spec-quick .goods-specifications table tbody tr:last td:first input').val(name);
|
||||
// 加入规格值
|
||||
for(var i in value)
|
||||
{
|
||||
$('.spec-quick .goods-specifications table tbody tr:last td:last .quick-spec-value-add').trigger('click');
|
||||
$('.spec-quick .goods-specifications table tbody tr:last td:last .value-item:eq(-2) input').val(value[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user