vr-shopxo-source/public/static/admin/default/js/goods.js

804 lines
31 KiB
JavaScript
Raw Normal View History

2022-08-19 12:29:06 +00:00
// 规格容器
var $spec_table = $('table.specifications-table');
2019-09-21 16:35:17 +00:00
/**
* 笛卡尔积生成规格
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-09-22T00:33:48+0800
* @desc description
* @param {[array]} arr1 [要进行笛卡尔积的二维数组]
* @param {[array]} arr2 [最终实现的笛卡尔积组合,可不写]
*/
2019-09-22 02:07:33 +00:00
function SpecCartesian(arr1, arr2)
2019-09-21 16:35:17 +00:00
{
// 去除第一个元素
var result = [];
var temp_arr = arr1;
var first = temp_arr.splice(0, 1);
if((arr2 || null) == null)
{
arr2 = [];
}
// 判断是否是第一次进行拼接
if(arr2.length > 0)
{
for(var i in arr2)
{
for(var k in first[0].value)
{
result.push(arr2[i]+','+first[0].value[k]);
}
}
} else {
for(var i in first[0].value)
{
result.push(first[0].value[i]);
}
}
// 递归进行拼接
if(arr1.length > 0)
{
2019-09-22 02:07:33 +00:00
result = SpecCartesian(arr1, result);
2019-09-21 16:35:17 +00:00
}
// 返回最终笛卡尔积
return result;
}
2018-12-28 10:58:37 +00:00
$(function()
{
2019-07-21 15:51:47 +00:00
// 表单初始化
FromInit('form.form-validation-specifications-extends');
2018-12-28 10:58:37 +00:00
// 商品导航
$('.goods-nav li a').on('click', function()
{
2019-11-13 12:51:43 +00:00
// 样式
2018-12-28 10:58:37 +00:00
$('.goods-nav li a').removeClass('goods-nav-active');
$(this).addClass('goods-nav-active');
2019-11-13 12:51:43 +00:00
// 滚动
$(window).smoothScroll({position: $($(this).data('value')).offset().top});
2019-09-11 13:06:04 +00:00
});
// 商品导航收缩
$('.goods-nav li.nav-shrink-submit').on('click', function()
{
if($(this).find('i').hasClass('am-icon-angle-double-right'))
{
$(this).find('i').removeClass('am-icon-angle-double-right');
$(this).find('i').addClass('am-icon-angle-double-left');
$(this).parents('.goods-nav').addClass('goods-nav-retract');
$('.goods-nav-retract').animate({right:'-110px'}, 500, function()
{
$('.goods-nav-retract li.nav-shrink-submit').animate({width: '50px', left:'-80px'});
2019-09-11 13:06:04 +00:00
});
} else {
$(this).find('i').removeClass('am-icon-angle-double-left');
$(this).find('i').addClass('am-icon-angle-double-right');
$(this).parents('.goods-nav').removeClass('goods-nav-retract');
$('.goods-nav').animate({right:'-0px'});
$('.goods-nav li.nav-shrink-submit').animate({width: '100%', left:'0px'});
}
});
2018-12-28 10:58:37 +00:00
// 规格列添加
$('.specifications-nav-title-add').on('click', function()
{
2022-08-19 12:29:06 +00:00
var spec_max = $spec_table.data('spec-add-max-number') || 3;
2018-12-28 10:58:37 +00:00
if($('.specifications-table th.table-title').length >= spec_max)
{
2022-08-19 12:29:06 +00:00
Prompt($spec_table.data('spec-max-error'));
2018-12-28 10:58:37 +00:00
return false;
}
// title
var index = parseInt(Math.random()*1000001);
html = '<th class="table-title table-title-'+index+'">';
2020-11-29 01:47:00 +00:00
html += '<i class="am-close title-nav-remove" data-index="'+index+'">&times;</i>';
2022-08-19 12:29:06 +00:00
html += '<input type="text" name="specifications_name_'+index+'" placeholder="'+$spec_table.data('spec-type-name')+'" class="am-radius" data-validation-message="'+$spec_table.data('spec-type-message')+'" required />';
2018-12-28 10:58:37 +00:00
html += '</th>';
$('.title-start').before(html);
// value
html = '<td class="table-value table-value-'+index+'">';
2022-08-19 12:29:06 +00:00
html += '<input type="text" name="specifications_value_'+index+'[]" placeholder="'+$spec_table.data('spec-value-name')+'" class="am-radius" data-validation-message="'+$spec_table.data('spec-value-message')+'" required />';
2018-12-28 10:58:37 +00:00
html += '</td>';
$('.value-start').before(html);
});
// 规格列移除
$(document).on('click', '.specifications-table .title-nav-remove', function()
{
var index = $(this).data('index');
$('.table-title-'+index).remove();
$('.table-value-'+index).remove();
if($('.specifications-table th.table-title').length <= 0)
{
// 防止用户操作删除了第一条数据、首行移除指定class
($('.specifications-table tr.line-not-first').length >= $('.specifications-table tr').length)
{
2022-08-19 12:29:06 +00:00
$spec_table.find('tbody tr:first').removeClass('line-not-first');
}
// 移除多余的规格行
2018-12-28 10:58:37 +00:00
$('.specifications-table tr.line-not-first').remove();
}
});
// 添加一行规格值
$('.specifications-line-add').on('click', function()
{
if($('.specifications-table th.table-title').length <= 0)
{
2022-08-19 12:29:06 +00:00
Prompt($spec_table.data('spec-empty-data-tips') || '请先添加规格');
2018-12-28 10:58:37 +00:00
return false;
}
2019-07-21 15:51:47 +00:00
var index = parseInt(Math.random()*1000001);
2022-08-19 12:29:06 +00:00
var html = $spec_table.find('tbody tr:last').prop('outerHTML');
$spec_table.append(html);
$spec_table.find('tbody tr:last').attr('class', 'line-'+index+' line-not-first');
$spec_table.find('tbody tr:last').attr('data-line-tag', '.line-'+index);
2018-12-28 10:58:37 +00:00
// 值赋空
2022-08-19 12:29:06 +00:00
$spec_table.find('tbody tr:last').find('input').each(function(k, v)
2018-12-28 10:58:37 +00:00
{
$(this).attr('value', '');
});
});
// 规格行复制
$(document).on('click', '.specifications-table .line-copy', function()
{
// 是否存在规格名称
if($('.specifications-table th.table-title').length <= 0)
{
2022-08-19 12:29:06 +00:00
Prompt($spec_table.data('spec-empty-data-tips') || '请先添加规格');
return false;
}
// 开始复制
2019-07-21 15:51:47 +00:00
var index = parseInt(Math.random()*1000001);
2018-12-28 10:58:37 +00:00
var $parent = $(this).parents('tr');
$parent.find('input').each(function(k, v)
{
$(this).attr('value', $(this).val());
});
$parent.after($parent.prop('outerHTML'));
2022-08-19 12:29:06 +00:00
$spec_table.find('tbody tr:last').attr('class', 'line-'+index+' line-not-first');
$spec_table.find('tbody tr:last').attr('data-line-tag', '.line-'+index);
2018-12-28 10:58:37 +00:00
});
// 规格行移除
$(document).on('click', '.specifications-table .line-remove', function()
{
// 不能全部移除,至少需要保留一行
if($('.specifications-table tbody tr').length <= 1)
{
2022-08-19 12:29:06 +00:00
Prompt($spec_table.data('spec-min-tips-message') || '至少需要保留一行规格值');
return false;
}
// 移除操作
2018-12-28 10:58:37 +00:00
$(this).parents('tr').remove();
// 规格列判断
2018-12-28 10:58:37 +00:00
if($('.specifications-table tbody tr').length <= 1)
{
$('.specifications-table th.table-title').remove();
$('.specifications-table td.table-value').remove();
$('.spec-images-list ul.spec-images-content').html('');
2018-12-28 10:58:37 +00:00
}
});
// 添加规格图片
$('.specifications-line-images-add').on('click', function()
{
2019-09-23 09:30:05 +00:00
// 是否存在规格
2018-12-28 10:58:37 +00:00
if($('.specifications-table th.table-title').length <= 0)
{
2022-08-19 12:29:06 +00:00
Prompt($spec_table.data('spec-empty-data-tips' || '请先添加规格'));
2018-12-28 10:58:37 +00:00
return false;
}
// 开始添加
var index = parseInt(Math.random()*1000001);
var temp_class = 'spec-images-items-'+index;
var html = '<li class="spec-images-items '+temp_class+'">';
2022-08-19 12:29:06 +00:00
html += '<input type="text" name="spec_images_name['+index+']" placeholder="'+$spec_table.data('spec-type-name')+'" class="am-radius am-text-center" data-validation-message="'+$spec_table.data('spec-type-message')+'" required />'
2018-12-28 10:58:37 +00:00
html += '<ul class="plug-file-upload-view spec-images-view-'+index+'" data-form-name="spec_images['+index+']" data-max-number="1" data-dialog-type="images">';
html += '<li>';
2022-08-19 12:29:06 +00:00
html += '<input type="text" name="spec_images['+index+']" data-validation-message="'+$spec_table.data('spec-images-message')+'" required />';
2019-04-18 17:15:30 +00:00
html += '<img src="'+__attachment_host__+'/static/admin/default/images/default-images.jpg" />';
2018-12-28 10:58:37 +00:00
html += '<i>×</i>';
html += '</li>';
html += '</ul>';
2022-08-19 12:29:06 +00:00
html += '<div class="plug-file-upload-submit" data-view-tag="ul.spec-images-view-'+index+'">+'+$spec_table.data('spec-images-name')+'</div>';
2018-12-28 10:58:37 +00:00
html += '</li>';
$('.spec-images-list ul.spec-images-content').append(html);
2018-12-28 10:58:37 +00:00
});
// 规格图片删除
$('.spec-images-list ul.spec-images-content').on('click', 'ul.plug-file-upload-view li i', function()
2018-12-28 10:58:37 +00:00
{
$(this).parents('li.spec-images-items').remove();
});
2019-09-23 09:30:05 +00:00
// 规格图片自动添加
$('.specifications-line-images-auto-add').on('click', function()
{
// 是否存在规格
var spec_count = $('.specifications-table th.table-title').length || 0;
if(spec_count <= 0)
{
2022-08-19 12:29:06 +00:00
Prompt($spec_table.data('spec-empty-data-tips') || '请先添加规格');
2019-09-23 09:30:05 +00:00
return false;
}
// 获取第一列规格名称
var data = [];
var index = parseInt($(this).find('input').val()) || 1;
if(index <= 0)
{
index = 1;
}
if(index > spec_count)
{
index = spec_count;
}
index -= 1;
$('.specifications-table tbody tr').each(function(k, v)
{
var value = $(this).find('td').eq(index).find('input').val() || null;
if(value != null && data.indexOf(value) == -1)
{
data.push(value);
}
});
if(data.length <= 0)
{
2022-08-19 12:29:06 +00:00
Prompt($spec_table.data('spec-empty-fill-tips') || '请先填写规格');
return false;
}
2019-09-23 09:30:05 +00:00
// 获取已存在规格图片
var data_old = [];
$('.spec-images-list ul.spec-images-content li.spec-images-items').each(function(k, v)
2019-09-23 09:30:05 +00:00
{
var value = $(this).find('input').val() || null;
if(value == null)
2019-09-23 09:30:05 +00:00
{
$(this).remove();
} else if(data_old.indexOf(value) == -1)
{
data_old.push(value);
}
});
2019-09-23 09:30:05 +00:00
// 循环添加
for(var i in data)
{
// 开始添加,不存在则不添加
if(data_old.indexOf(data[i]) == -1)
2019-09-23 09:30:05 +00:00
{
var index = parseInt(Math.random()*1000001);
var temp_class = 'spec-images-items-'+index;
var html = '<li class="spec-images-items '+temp_class+'">';
2022-08-19 12:29:06 +00:00
html += '<input type="text" name="spec_images_name['+index+']" value="'+data[i]+'" placeholder="'+$spec_table.data('spec-type-name')+'" class="am-radius am-text-center" data-validation-message="'+$spec_table.data('spec-type-message')+'" required />'
html += '<ul class="plug-file-upload-view spec-images-view-'+index+'" data-form-name="spec_images['+index+']" data-max-number="1" data-dialog-type="images">';
html += '<li>';
2022-08-19 12:29:06 +00:00
html += '<input type="text" name="spec_images['+index+']" data-validation-message="'+$spec_table.data('spec-images-message')+'" required />';
html += '<img src="'+__attachment_host__+'/static/admin/default/images/default-images.jpg" />';
html += '<i>×</i>';
html += '</li>';
html += '</ul>';
2022-08-19 12:29:06 +00:00
html += '<div class="plug-file-upload-submit" data-view-tag="ul.spec-images-view-'+index+'">+'+$spec_table.data('spec-images-name')+'</div>';
html += '</li>';
$('.spec-images-list ul.spec-images-content').append(html);
2019-09-23 09:30:05 +00:00
}
}
2019-09-23 09:30:05 +00:00
// 原始图片规格不存在指定规格列中则移除
for(var i in data_old)
{
if(data.indexOf(data_old[i]) == -1)
2019-09-23 09:30:05 +00:00
{
$('.spec-images-list ul.spec-images-content li.spec-images-items').each(function(k, v)
2019-09-23 09:30:05 +00:00
{
var value = $(this).find('input').val() || null;
if(value == data_old[i])
2019-09-23 09:30:05 +00:00
{
$(this).remove();
}
});
2019-09-23 09:30:05 +00:00
}
}
});
// 自动添加图片规格input输入值处理
$('.specifications-line-images-auto-add input').on('blur', function()
{
var value = parseInt($(this).val()) || 1;
if(value <= 0)
{
value = 1;
}
2019-09-23 09:31:30 +00:00
var spec_count = $('.specifications-table th.table-title').length || 1;
2019-09-23 09:30:05 +00:00
if(value > spec_count)
{
value = spec_count;
}
$(this).val(value);
});
// 自动添加图片规格input禁止冒泡
$('.specifications-line-images-auto-add input').on('click', function()
{
return false;
});
2019-09-22 14:19:24 +00:00
// 规格批量操作-开启
var $spec_modal = $('#spec-modal-all-operation');
2019-09-23 14:39:36 +00:00
$('.specifications-table thead th i.am-icon-edit').on('click', function()
2019-09-22 14:19:24 +00:00
{
$spec_modal.modal({
width: 200,
2019-09-23 14:39:36 +00:00
height: 100,
closeViaDimmer: false
2019-09-22 14:19:24 +00:00
});
$spec_modal.attr('data-index', $(this).parent().index());
$spec_modal.find('.am-input-group input').val('');
});
// 规格批量操作-确认
$spec_modal.find('.am-input-group button').on('click', function()
{
var index = $spec_modal.attr('data-index') || 0;
var value = $spec_modal.find('.am-input-group input').val() || '';
$('.specifications-table tbody tr').each(function(k, v)
{
$(this).find('td').eq(index).find('input').val(value);
});
$spec_modal.modal('close');
});
2019-09-24 05:56:08 +00:00
// 规格高级批量操作-弹层
var $spec_popup_all_operation = $('#spec-popup-all-operation');
$('.specifications-nav-set-all').on('click', function()
{
// 获取规格标题
var title = [];
$('.specifications-table th.table-title').each(function(k, v)
{
var value = $(this).find('input').val() || null;
if(value != null && title.indexOf(value) == -1)
{
title.push(value);
}
});
if(title.length < $('.specifications-table th.table-title').length)
{
2022-08-19 12:29:06 +00:00
Prompt($spec_table.data('spec-type-message') || '请填写规格名称');
2019-09-24 05:56:08 +00:00
return false;
}
// 获取规格值
var data = [];
for(var i in title)
{
data[i] = [];
$('.specifications-table tbody tr').each(function(k, v)
{
var value = $(this).find('td').eq(i).find('input').val() || null;
if(value != null && data[i].indexOf(value) == -1)
{
data[i].push(value);
}
});
}
// 拼接html
var html = '';
for(var i in data)
{
html += '<div class="am-form-group">';
html += '<label class="block">'+title[i]+'</label>';
2022-08-19 12:29:06 +00:00
html += '<select class="chosen-select am-radius" data-placeholder="'+$spec_table.data('spec-all-name')+'">';
html += '<option value="">'+$spec_table.data('spec-all-name')+'</option>';
2019-09-24 05:56:08 +00:00
for(var k in data[i])
{
html += '<option value="'+data[i][k]+'">'+data[i][k]+'</option>';
}
html += '</select>';
html += '</div>';
}
var $spec_container = $spec_popup_all_operation.find('.am-popup-bd .spec-title-container');
$spec_container.html(html);
if(data.length > 0)
{
$spec_container.show();
} else {
$spec_container.hide();
}
// select组件初始化
$spec_popup_all_operation.find('.chosen-select').chosen({
inherit_select_classes: true,
enable_split_word_search: true,
search_contains: true,
2022-08-19 12:29:06 +00:00
no_results_text: lang_chosen_select_no_results_text
2019-09-24 05:56:08 +00:00
});
// 所有input赋空
$spec_popup_all_operation.find('input').val('');
});
// 规格高级批量操作-赋值
$spec_popup_all_operation.find('button.am-btn-secondary').on('click', function()
{
// 获取规格值条件
var data = [];
$spec_popup_all_operation.find('.am-popup-bd .spec-title-container select.chosen-select').each(function(k, v)
{
data.push($(this).val() || null);
});
// 获取基础值
var price = $spec_popup_all_operation.find('.am-popup-bd input.popup_all_price').val() || '';
var original_price = $spec_popup_all_operation.find('.am-popup-bd input.popup_all_original_price').val() || '';
2019-09-24 05:56:08 +00:00
var weight = $spec_popup_all_operation.find('.am-popup-bd input.popup_all_weight').val() || '';
var volume = $spec_popup_all_operation.find('.am-popup-bd input.popup_all_volume').val() || '';
2019-09-24 05:56:08 +00:00
var coding = $spec_popup_all_operation.find('.am-popup-bd input.popup_all_coding').val() || '';
var barcode = $spec_popup_all_operation.find('.am-popup-bd input.popup_all_barcode').val() || '';
// 批量设置
var data_length = data.length;
$('.specifications-table tbody tr').each(function(k, v)
{
var count = 0;
for(var i in data)
{
if(data[i] == null || data[i] == ($(this).find('td').eq(i).find('input').val() || null))
{
count++;
}
}
var index = $(this).find('.value-start').index();
if(count >= data_length)
{
$(this).find('td').eq(index).find('input').val(price);
$(this).find('td').eq(index+1).find('input').val(original_price);
$(this).find('td').eq(index+2).find('input').val(weight);
$(this).find('td').eq(index+3).find('input').val(volume);
$(this).find('td').eq(index+4).find('input').val(coding);
$(this).find('td').eq(index+5).find('input').val(barcode);
2019-09-24 05:56:08 +00:00
}
});
$spec_popup_all_operation.modal('close');
});
2019-09-22 14:19:24 +00:00
2018-12-28 10:58:37 +00:00
// 手机详情添加
$(document).on('click', '.content-app-items-add-sub', function()
{
2022-08-19 12:29:06 +00:00
var $app_content = $('#goods-nav-app .content-app-items');
var i = (($(this).attr('index') || null) == null) ? parseInt($app_content.find('li').length) : parseInt($(this).attr('index'));
2018-12-28 10:58:37 +00:00
var index = parseInt(Math.random()*1000001)+i;
2022-08-19 12:29:06 +00:00
var images_name = $app_content.data('images-name');
var content_name = $app_content.data('content-name');
// html拼接
2018-12-28 10:58:37 +00:00
var html = '<li><div>';
// 左侧
html += '<div class="content-app-left">';
2022-08-19 12:29:06 +00:00
html += '<label class="block">'+$app_content.data('images-title')+'</label>';
2018-12-28 10:58:37 +00:00
html += '<ul class="plug-file-upload-view goods-content-app-images-view-'+index+'" data-form-name="'+images_name+'_'+index+'" data-max-number="1" data-dialog-type="images">';
html += '</ul>';
2022-08-19 12:29:06 +00:00
html += '<div class="plug-file-upload-submit" data-view-tag="ul.goods-content-app-images-view-'+index+'">+'+$app_content.data('images-name')+'</div>';
2018-12-28 10:58:37 +00:00
html += '</div>';
// 右侧
html += '<div class="am-form-group content-app-right fr">';
2022-08-19 12:29:06 +00:00
html += '<label>'+$app_content.data('content-title')+'</label>';
html += '<textarea rows="3" name="'+content_name+'_'+index+'" class="am-radius" placeholder="'+$app_content.data('content-title')+'"></textarea>';
2018-12-28 10:58:37 +00:00
html += '</div>';
html += '</div>';
// 操作按钮
2022-08-19 12:29:06 +00:00
html += '<a href="javascript:;" class="am-text-xs am-text-danger content-app-items-rem-sub">'+$app_content.data('delete-name')+'</a>';
html += ' <a href="javascript:;" class="am-text-xs am-margin-left-lg drag-sort-submit">'+$app_content.data('drag-name')+'</a>';
2018-12-28 10:58:37 +00:00
html += '</li>';
2022-08-19 12:29:06 +00:00
$app_content.append(html);
$app_content.attr('index', index);
2018-12-28 10:58:37 +00:00
$(this).attr('index', i+1);
});
// 手机详情删除
$(document).on('click', '.content-app-items-rem-sub', function()
{
$(this).parent().remove();
});
// 拖拽
2021-02-01 08:54:05 +00:00
$('ul.goods-photo-view').dragsort({ dragSelector: 'li', placeHolderTemplate: '<li class="drag-sort-dotted"></li>'});
2022-08-19 12:29:06 +00:00
$('ul.content-app-items').dragsort({ dragSelector: 'a.drag-sort-submit', placeHolderTemplate: '<li class="drag-sort-dotted"></li>'});
2018-12-28 10:58:37 +00:00
2019-07-21 15:51:47 +00:00
// 规格扩展数据编辑
var $extends_popup = $('#specifications-extends-popup');
$(document).on('click', '.specifications-table .line-extend-btn', function()
{
$extends_popup.attr('data-line-extend', $(this).parents('tr').attr('data-line-tag'));
$extends_popup.find('input,select,textarea').val('');
var json = $(this).prev().val() || null;
if(json != null)
{
FormDataFill(JSON.parse(json), '#specifications-extends-popup');
}
$extends_popup.modal();
});
2019-09-11 13:06:04 +00:00
// 规格快捷操作 - 规格列添加
2019-09-11 13:06:04 +00:00
$('.quick-spec-title-add').on('click', function()
{
2022-08-19 12:29:06 +00:00
var spec_max = $spec_table.data('spec-add-max-number') || 3;
2019-09-11 13:06:04 +00:00
if($('.spec-quick table tbody tr').length >= spec_max)
{
2022-08-19 12:29:06 +00:00
Prompt($spec_table.data('spec-max-error'));
2019-09-11 13:06:04 +00:00
return false;
}
2019-09-23 05:56:03 +00:00
var index = parseInt(Math.random()*1000001);
2019-09-12 10:31:25 +00:00
var html = '<tr>';
html += '<td class="am-text-middle">';
2021-01-27 14:21:04 +00:00
html += '<i class="am-close quick-title-remove">×</i>';
2022-08-19 12:29:06 +00:00
html += '<input type="text" name="spec_base_title_'+index+'" placeholder="'+$spec_table.data('spec-type-name')+'" />';
2019-09-12 10:31:25 +00:00
html += '</td>';
html += '<td class="spec-quick-td-value am-cf">';
html += '<div class="am-fl am-margin-xs value-item am-text-left">';
2022-08-19 12:29:06 +00:00
html += '<span class="business-operations-submit quick-spec-value-add" data-index="'+index+'">+ '+$spec_table.data('spec-add-value-message')+'</span>';
2019-09-12 10:31:25 +00:00
html += '</div>';
html += '</td>';
html += '</tr>';
$('.spec-quick table tbody').append(html);
$('.spec-quick .goods-specifications').show();
});
// 添加规格值
$(document).on('click', '.spec-quick table .quick-spec-value-add', function()
{
2019-09-23 05:56:03 +00:00
var index = $(this).data('index');
2019-09-12 10:31:25 +00:00
var html = '<div class="am-fl am-margin-xs value-item">';
2022-08-19 12:29:06 +00:00
html += '<input type="text" class="am-fl" name="spec_base_value_'+index+'[]" placeholder="'+$spec_table.data('spec-value-name')+'" />';
2021-01-27 14:21:04 +00:00
html += '<i class="am-close quick-value-remove">×</i>';
2019-09-12 10:31:25 +00:00
html += '</div>';
$(this).parent().before(html);
});
// 规格快捷操作 - 规格名称移除
2019-09-12 10:31:25 +00:00
$(document).on('click', '.spec-quick table .quick-title-remove', function()
{
$(this).parents('tr').remove();
if($('.spec-quick table tbody tr').length <= 0)
{
$('.spec-quick .goods-specifications').hide();
}
});
// 规格快捷操作 - 规格值移除
2019-09-12 10:31:25 +00:00
$(document).on('click', '.spec-quick table .value-item .quick-value-remove', function()
{
$(this).parent().remove();
2019-09-11 13:06:04 +00:00
});
// 规格快捷操作 - 生成规格
2019-09-11 13:06:04 +00:00
$('.quick-spec-created').on('click', function()
{
2019-09-20 11:02:08 +00:00
var spec = [];
$('.spec-quick table tbody tr').each(function(k, v)
{
2019-09-24 08:43:01 +00:00
var title = $(this).find('td.am-text-middle input').val() || null;
if(title != null)
2019-09-20 11:02:08 +00:00
{
2019-09-24 08:43:01 +00:00
var temp_data = [];
$(this).find('td.spec-quick-td-value .value-item').each(function(ks,vs)
{
var value = $(this).find('input').val() || null;
if(value != null)
{
temp_data.push(value);
}
});
if(temp_data.length > 0)
2019-09-20 11:02:08 +00:00
{
2019-09-24 08:43:01 +00:00
spec.push({
"title": title,
"value": temp_data
});
2019-09-20 11:02:08 +00:00
}
2019-09-24 08:43:01 +00:00
}
2019-09-20 11:02:08 +00:00
});
// 是否存在规格
if(spec.length <= 0)
{
2022-08-19 12:29:06 +00:00
Prompt($spec_table.data('spec-quick-error') || '快捷操作规格为空');
2019-09-22 02:07:33 +00:00
return false;
2019-09-20 11:02:08 +00:00
}
2019-09-23 09:30:05 +00:00
// 操作确认
AMUI.dialog.confirm({
2022-08-19 12:29:06 +00:00
title: $spec_table.data('spec-quick-tips-title'),
content: $spec_table.data('spec-quick-tips-msg'),
2019-09-23 09:30:05 +00:00
onConfirm: function(options)
2019-09-22 02:07:33 +00:00
{
2019-09-23 09:30:05 +00:00
// 移除所有规格列
$('.specifications-table .title-nav-remove').trigger('click');
// 添加规格列
for(var i in spec)
{
var index = parseInt(Math.random()*1000001);
// title
html = '<th class="table-title table-title-'+index+'">';
2020-11-29 01:47:00 +00:00
html += '<i class="am-close title-nav-remove" data-index="'+index+'">&times;</i>';
2022-08-19 12:29:06 +00:00
html += '<input type="text" name="specifications_name_'+index+'" value="'+spec[i]['title']+'" placeholder="'+$spec_table.data('spec-type-name')+'" class="am-radius" data-validation-message="'+$spec_table.data('spec-type-message')+'" required />';
2019-09-23 09:30:05 +00:00
html += '</th>';
$('.title-start').before(html);
// value
html = '<td class="table-value table-value-'+index+'">';
2022-08-19 12:29:06 +00:00
html += '<input type="text" name="specifications_value_'+index+'[]" value="'+(spec[i]['value'][0] || "")+'" placeholder="'+$spec_table.data('spec-value-name')+'" class="am-radius" data-validation-message="'+$spec_table.data('spec-value-name')+'" required />';
2019-09-23 09:30:05 +00:00
html += '</td>';
$('.value-start').before(html);
}
2019-09-20 11:02:08 +00:00
2019-09-23 09:30:05 +00:00
// 自动生成规格
var data = SpecCartesian(spec);
for(var i=1; i<data.length; i++)
{
// 添加规格值
var index = parseInt(Math.random()*1000001);
2022-08-19 12:29:06 +00:00
var html = $spec_table.find('tbody tr:last').prop('outerHTML');
$spec_table.append(html);
$spec_table.find('tbody tr:last').attr('class', 'line-'+index+' line-not-first');
$spec_table.find('tbody tr:last').attr('data-line-tag', '.line-'+index);
2019-09-23 09:30:05 +00:00
// 规格值
var temp_spec = data[i].split(',');
for(var k in temp_spec)
{
// 规格值赋值
2022-08-19 12:29:06 +00:00
$spec_table.find('tbody tr:last').find('td:eq('+k+') input').val(temp_spec[k]);
2019-09-23 09:30:05 +00:00
}
}
// 清空扩展数据
$('.specifications-table .line-extend-input').val('');
2022-08-19 12:29:06 +00:00
Prompt($spec_table.data('spec-quick-success') || '生成成功', 'success');
2019-09-23 09:30:05 +00:00
},
onCancel: function(){}
});
2019-09-11 13:06:04 +00:00
});
2019-11-13 12:51:43 +00:00
// 虚拟商品编辑器初始化
2019-11-19 13:46:22 +00:00
if($('#goods-fictitious-container').length > 0)
2019-11-13 12:51:43 +00:00
{
2019-11-19 13:46:22 +00:00
UE.getEditor('goods-fictitious-container', {
2019-11-13 12:51:43 +00:00
toolbars: [['source', 'undo', 'redo', 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', '|', 'forecolor', 'backcolor', 'link', 'fontsize', 'insertorderedlist', 'insertunorderedlist']],
initialFrameHeight : 100
});
}
2020-07-01 14:46:52 +00:00
// 规格选中状态
$(document).on('click', '.specifications-table tr', function()
{
$('.specifications-table tr').removeClass('am-primary');
$(this).addClass('am-primary');
});
// 商品参数模板选择
$('.goods-template-params-select').on('change', function()
{
var value = $(this).val() || null;
if(value != null)
{
value = decodeURIComponent(value);
if(typeof(value) == 'object')
{
value = JSON.stringify(value);
}
}
$('#parameters-quick-container textarea').val(value || '');
});
// 商品规格模板数据获取、选择商品分类后异步读取
var $spec_quick = $('#specifications-quick-container');
$('select[name="category_id"]').on('change', function()
{
var value = $(this).val() || '';
$.ajax({
url: RequestUrlHandle($spec_quick.data('url')),
type: 'POST',
dataType: 'json',
timeout: 305000,
data: {"category_ids": value},
success: function(result)
{
2022-08-25 10:16:40 +00:00
// 移除现有模板
$spec_quick.find('select option').each(function(k, v)
{
if(k > 0)
{
$(this).remove();
}
});
// 循环处理得到的最新模板
if((result.data || null) != null && result.data.length > 0)
{
var html = '';
for(var i in result.data)
{
html += '<option value="'+result.data[i]['content']+'">'+result.data[i]['name']+'</option>';
}
$spec_quick.find('select').append(html);
}
2022-08-25 10:16:40 +00:00
// 更新select组件
$spec_quick.find('select').trigger('chosen:updated');
},
error: function(xhr, type)
{
Prompt(HtmlToString(xhr.responseText) || (window['lang_error_text'] || '异常错误'));
}
});
});
// 规格模板选择
$(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)
{
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)
{
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]);
}
});
2018-12-28 10:58:37 +00:00
});