Commit 18006628 by 杨树贤

批量添加主营品牌

parent 7f2699d3
...@@ -5,4 +5,5 @@ Homestead.json ...@@ -5,4 +5,5 @@ Homestead.json
/.idea /.idea
/.vscode /.vscode
/.history /.history
/vendor/_laravel_idea/*
/vendor/_laravel_idea /vendor/_laravel_idea
...@@ -7,6 +7,7 @@ use App\Http\Controllers\Filter\SupplierFilter; ...@@ -7,6 +7,7 @@ use App\Http\Controllers\Filter\SupplierFilter;
use App\Http\Services\AdminUserService; use App\Http\Services\AdminUserService;
use App\Http\Services\CompanyService; use App\Http\Services\CompanyService;
use App\Http\Services\LogService; use App\Http\Services\LogService;
use App\Http\Services\StandardBrandService;
use App\Http\Services\SupplierAuditService; use App\Http\Services\SupplierAuditService;
use App\Http\Services\SupplierService; use App\Http\Services\SupplierService;
use App\Http\Services\SupplierStatisticsService; use App\Http\Services\SupplierStatisticsService;
...@@ -724,4 +725,12 @@ class SupplierApiController extends Controller ...@@ -724,4 +725,12 @@ class SupplierApiController extends Controller
$this->response(0, '查询成功', $supplier); $this->response(0, '查询成功', $supplier);
} }
//批量获取需要新增主营品牌信息
public function getBatchAddMainBrandsData($request)
{
$standardBrandNames = $request->input('standard_brand_names');
$result = (new StandardBrandService())->getBatchAddMainBrandsData($standardBrandNames);
$this->response(0,'ok',$result);
}
} }
...@@ -88,4 +88,11 @@ class StandardBrandService ...@@ -88,4 +88,11 @@ class StandardBrandService
} }
return $result ?: []; return $result ?: [];
} }
public function getBatchAddMainBrandsData($standardBrandNames)
{
$standardBrandNames = explode(',', trim($standardBrandNames, ','));
$standardBrandIds = StandardBrandModel::whereIn('brand_name', $standardBrandNames)->pluck('standard_brand_id')->toArray();
return $this->getBrandInitValue(implode(',',$standardBrandIds));
}
} }
\ No newline at end of file
...@@ -114,3 +114,31 @@ function getLogDomain() { ...@@ -114,3 +114,31 @@ function getLogDomain() {
} }
function arrayColumn(arr, column) {
return arr.map(function(row) {
return row[column];
});
}
//数组去重
function arrayUnique(arr) {
var res = [];
for (var i = 0, len = arr.length; i < len; i++) {
var item = arr[i];
for (var j = 0, jLen = res.length; j < jLen; j++) {
if (item == res[j]) break;
}
if (j == jLen) res.push(item);
}
return res;
}
function multiArrayUnique(arr) {
return arr.filter(function(item, index) {
const json = JSON.stringify(item);
return arr.findIndex(function(subItem) {
return JSON.stringify(subItem) === json;
}) === index;
});
}
\ No newline at end of file
...@@ -70,4 +70,6 @@ function ajax(url,data){ ...@@ -70,4 +70,6 @@ function ajax(url,data){
} }
}) })
return result; return result;
} }
\ No newline at end of file
...@@ -163,35 +163,6 @@ ...@@ -163,35 +163,6 @@
} }
}); });
// //主营品牌限制的初始化
// let mainBrandsLimitTypeObj = $('#main_brands_limit_type');
// if (supplierId) {
// let mainBrandsLimitObj = $('#main_brands_limit');
// if (mainBrandsLimitObj.val() == -1) {
// mainBrandsLimitTypeObj.val(2);
// mainBrandsLimitObj.val('');
// mainBrandsLimitObj.attr('disabled', true);
// mainBrandsLimitObj.addClass('layui-disabled');
// form.render('select');
// }
// }
{{--let supplierGroupMap = {!! json_encode(config('fixed.SupplierGroup')) !!};--}}
{{--let limitMap = {!!json_encode(config('field.SupplierGroupMainBrandsLimitMap'))!!};--}}
{{--//监听主营品牌限制的数字,不同供应商性质的数量限制不一样--}}
{{--$(document).on('change', '#main_brands_limit', function () {--}}
{{-- let supplierGroup = $('#supplier_group').val();--}}
{{-- if (!supplierGroup) {--}}
{{-- layer.msg("请先选择供应商性质", {icon: 5});--}}
{{-- $('#main_brands_limit').val('');--}}
{{-- return false;--}}
{{-- }--}}
{{-- let limit = limitMap[supplierGroup];--}}
{{-- if ($(this).val() > limit && limit !== -1) {--}}
{{-- layer.msg("供应商性质为" + supplierGroupMap[supplierGroup] + "时,主营品牌数量最大可以设置为 " + limit, {icon: 5});--}}
{{-- $('#main_brands_limit').val(limit);--}}
{{-- }--}}
{{--});--}}
//监听供应商性质选择,如果为混合分销商,那么要展示混合分销商品牌设置 //监听供应商性质选择,如果为混合分销商,那么要展示混合分销商品牌设置
form.on('select(supplier_group)', function (data) { form.on('select(supplier_group)', function (data) {
...@@ -200,39 +171,8 @@ ...@@ -200,39 +171,8 @@
} else { } else {
$('#agency_brands_div').hide(); $('#agency_brands_div').hide();
} }
// // 这里还要去判断主营品牌数量限制的切换
// // 原厂,代理商,分销平台,品牌数量不做限制;默认为“无限制”;
// // 混合分销商,现货商,代工厂,品牌数量默认为10;
// // 方案商,其他,品牌数量默认为5;
// let mainBrandsLimitObj = $('#main_brands_limit');
// let limit = limitMap[data.value];
// console.log(limit)
// if (limit === -1) {
// mainBrandsLimitObj.attr('disabled', true);
// mainBrandsLimitObj.addClass('layui-disabled');
// mainBrandsLimitTypeObj.val(2);
// } else {
// mainBrandsLimitObj.attr('disabled', false);
// mainBrandsLimitObj.removeClass('layui-disabled');
// mainBrandsLimitTypeObj.val(1);
// }
// form.render('select');
//
// mainBrandsLimitObj.val(limit === -1 ? '' : limit);
}); });
// form.on('select(main_brands_limit_type)', function (data) {
// let mainBrandsLimitObj = $('#main_brands_limit');
// if (data.value == 2) {
// mainBrandsLimitObj.attr('disabled', true);
// mainBrandsLimitObj.addClass('layui-disabled');
// } else {
// mainBrandsLimitObj.attr('disabled', false);
// mainBrandsLimitObj.removeClass('layui-disabled');
// }
// });
//如果没有直接忽略公司校验的权限,那么就要做到下面的互相disable //如果没有直接忽略公司校验的权限,那么就要做到下面的互相disable
@if (!checkPerm('IgnoreCompanyCheck')) @if (!checkPerm('IgnoreCompanyCheck'))
//修改供应商名称,那么公司税号就禁用,反之亦然 //修改供应商名称,那么公司税号就禁用,反之亦然
...@@ -335,6 +275,44 @@ ...@@ -335,6 +275,44 @@
let brandInitValue = {!! json_encode($brand_init_value?:[])!!}; let brandInitValue = {!! json_encode($brand_init_value?:[])!!};
brandSelector.setValue(brandInitValue); brandSelector.setValue(brandInitValue);
//批量新增主营品牌
$('#batchAddMainBrands').click(function () {
layer.open({
title: "批量增加主营品牌",
area: ['600px', '400px'],
type: 1,
content: $('#batchAddMainBrandsDiv')
});
});
$('#confirmBatchAddMainBrands').click(function () {
let standardBrandNames = $('#batchAddMainBrandsTextarea').val();
//请求接口获取返回的数据,并且合并目前选择的主营品牌,重新渲染xm-select
let res = ajax('/api/supplier/getBatchAddMainBrandsData', {standard_brand_names: standardBrandNames});
let data = res.data;
let brandNames = arrayColumn(data, 'brand_name').join(',')
$('#batchAddMainBrandsBlockQuote').text(brandNames);
if (data.length === 0) {
layer.msg('没有匹配到有效的标准品牌',{icon:5});
return false;
}else{
brandInitValue = brandInitValue.concat(data);
brandInitValue = multiArrayUnique(brandInitValue);
brandSelector.setValue(brandInitValue);
$('#main_brands').val(arrayColumn(brandInitValue, 'brand_id').join(','));
$('#batchAddMainBrandsTextarea').val('');
$('#batchAddMainBrandsBlockQuote').text('');
layer.msg('批量添加主营品牌成功',{icon:6});
}
});
$('#closeBatchAddMainBrands').click(function () {
$('#batchAddMainBrandsTextarea').val('');
$('#batchAddMainBrandsBlockQuote').text('');
layer.closeAll();
});
//代理品牌的渲染 //代理品牌的渲染
let agencyBrandOption = getBrandOption('agency_brand_selector', 'agency_brands'); let agencyBrandOption = getBrandOption('agency_brand_selector', 'agency_brands');
let agencyBrandSelector = xmSelect.render(agencyBrandOption); let agencyBrandSelector = xmSelect.render(agencyBrandOption);
......
...@@ -219,23 +219,21 @@ ...@@ -219,23 +219,21 @@
<input type="hidden" name="main_brands" value="" <input type="hidden" name="main_brands" value=""
id="main_brands"> id="main_brands">
</div> </div>
<a style="color: #009688;" id="batchAddMainBrands">+批量增加主营品牌</a>
<div id="batchAddMainBrandsDiv" style="padding-left: 30px;padding-top: 30px;padding-right: 30px;display: none">
<div class="layui-col-md12">
<textarea rows="7" placeholder="标准品牌名称,多个用英文逗号隔开" class="layui-textarea"
id="batchAddMainBrandsTextarea"></textarea>
<blockquote class="layui-elem-quote" id="batchAddMainBrandsBlockQuote"></blockquote>
<span style="color: red" id="invalid_${name}_name_list"></span>
</div>
<div class="layui-col-md12">
<button class="layui-btn layui-btn-sm" type="button" id="confirmBatchAddMainBrands">验证并且添加</button>
<button class="layui-btn layui-btn-sm layui-btn-primary" type="button" id="closeBatchAddMainBrands">关闭</button>
</div>
</div>
</div> </div>
{{-- <div class="layui-col-md4">--}}
{{-- <label class="layui-form-label" style="width: 100px">主营品牌数量: </label>--}}
{{-- <div class="layui-input-inline" style="width: 150px">--}}
{{-- <input type="text" name="main_brands_limit" id="main_brands_limit"--}}
{{-- placeholder="请输入主营品牌数量限制" class="layui-input" value="">--}}
{{-- </div>--}}
{{-- <div class="layui-inline">--}}
{{-- <select id="main_brands_limit_type" lay-filter="main_brands_limit_type" name="main_brands_limit_type">--}}
{{-- <option value="1">自定义</option>--}}
{{-- <option value="2">无限制</option>--}}
{{-- </select>--}}
{{-- </div>--}}
{{-- </div>--}}
</div> </div>
{{--选择“混合分销商”时,在主营品牌下面新增一栏“代理品牌”;代理品牌取值同主营品牌一样--}}
<div class="layui-form-item" id="agency_brands_div" style="display: none"> <div class="layui-form-item" id="agency_brands_div" style="display: none">
<label class="layui-form-label"> <label class="layui-form-label">
<span class="require">*</span> <span class="require">*</span>
......
...@@ -223,20 +223,20 @@ ...@@ -223,20 +223,20 @@
<input type="hidden" name="main_brands" value="" <input type="hidden" name="main_brands" value=""
id="main_brands" value="{{$supplier['main_brands'] or ''}}"> id="main_brands" value="{{$supplier['main_brands'] or ''}}">
</div> </div>
<a style="color: #009688;" id="batchAddMainBrands">+批量增加主营品牌</a>
<div id="batchAddMainBrandsDiv" style="padding-left: 30px;padding-top: 30px;padding-right: 30px;display: none">
<div class="layui-col-md12">
<textarea rows="7" placeholder="标准品牌名称,多个用英文逗号隔开" class="layui-textarea"
id="batchAddMainBrandsTextarea"></textarea>
<blockquote class="layui-elem-quote" id="batchAddMainBrandsBlockQuote"></blockquote>
<span style="color: red" id="invalid_${name}_name_list"></span>
</div>
<div class="layui-col-md12">
<button class="layui-btn layui-btn-sm" type="button" id="confirmBatchAddMainBrands">验证并且添加</button>
<button class="layui-btn layui-btn-sm layui-btn-primary" type="button" id="closeBatchAddMainBrands">关闭</button>
</div>
</div>
</div> </div>
{{-- <div class="layui-col-md4">--}}
{{-- <label class="layui-form-label" style="width: 100px">主营品牌数量: </label>--}}
{{-- <div class="layui-input-inline" style="width: 150px">--}}
{{-- <input type="text" name="main_brands_limit" id="main_brands_limit"--}}
{{-- placeholder="请输入主营品牌数量限制" class="layui-input" value="{{$supplier['main_brands_limit'] or ''}}">--}}
{{-- </div>--}}
{{-- <div class="layui-inline">--}}
{{-- <select id="main_brands_limit_type" name="main_brands_limit_type" lay-filter="main_brands_limit_type">--}}
{{-- <option value="1">自定义</option>--}}
{{-- <option value="2">无限制</option>--}}
{{-- </select>--}}
{{-- </div>--}}
{{-- </div>--}}
</div> </div>
{{--选择“混合分销商”时,在主营品牌下面新增一栏“代理品牌”;代理品牌取值同主营品牌一样--}} {{--选择“混合分销商”时,在主营品牌下面新增一栏“代理品牌”;代理品牌取值同主营品牌一样--}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment