$(function()
{
// 商品导航
$('.goods-nav li a').on('click', function()
{
$('.goods-nav li a').removeClass('goods-nav-active');
$(this).addClass('goods-nav-active');
})
// 规格列添加
$('.specifications-nav-title-add').on('click', function()
{
if($('.specifications-table th.table-title').length >= 5)
{
Prompt('最多添加5列规格');
return false;
}
// title
var index = parseInt(Math.random()*1000001);
html = '
';
html += '× ';
html += ' ';
html += ' ';
$('.title-start').before(html);
// value
html = '';
html += ' ';
html += ' ';
$('.value-start').before(html);
// 规格图片
SpecImagesHandle();
});
// 规格列移除
$('.specifications-table').on('click', '.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)
{
$('.specifications-table tr.line-not-first').remove();
}
// 规格图片
SpecImagesHandle();
});
// 添加一行规格值
$('.specifications-line-add').on('click', function()
{
if($('.specifications-table th.table-title').length <= 0)
{
Prompt('请先添加规格');
return false;
}
var html = $('.specifications-table').find('tbody tr:last').prop('outerHTML');
if(html.indexOf('') >= 0)
{
html = html.replace(//ig, '复制 移除 ');
}
$('.specifications-table').append(html);
$('.specifications-table').find('tbody tr:last').addClass('line-not-first');
// 值赋空
$('.specifications-table').find('tbody tr:last').find('input').each(function(k, v)
{
$(this).attr('value', '');
});
// 规格图片
SpecImagesHandle();
});
// 规格行复制
$('.specifications-table').on('click', '.line-copy', function()
{
var $parent = $(this).parents('tr');
$parent.find('input').each(function(k, v)
{
$(this).attr('value', $(this).val());
});
$parent.after($parent.prop('outerHTML'));
// 规格图片
SpecImagesHandle();
});
// 规格行移除
$('.specifications-table').on('click', '.line-remove', function()
{
$(this).parents('tr').remove();
if($('.specifications-table tbody tr').length <= 1)
{
$('.specifications-table th.table-title').remove();
$('.specifications-table td.table-value').remove();
}
// 规格图片
SpecImagesHandle();
});
// 规格首列事件
$('.spec-images-tips').on('change', 'input', function()
{
// 规格图片
SpecImagesHandle();
});
// 规格第一列输入事件
$('.specifications-table tbody tr').on('change', 'td:eq(0) input', function()
{
// 规格图片
SpecImagesHandle();
});
// 规格图片
function SpecImagesHandle()
{
if($('.spec-images-tips input').prop('checked'))
{
var temp_spec_all = {}, spec_all = [];
$('.specifications-table tbody tr').each(function(k, v)
{
var value = $(this).find('td:eq(0) input').val();
temp_spec_all[value] = value;
});
spec_all = Object.keys(temp_spec_all);
if(spec_all.length > 0)
{
for(var i in spec_all)
{
var temp_class = 'spec-images-items-'+spec_all[i];
if($('ul.spec-images-list').find('.'+temp_class).length <= 0)
{
var html = '';
html += ' '
html += '';
html += '';
html += ' ';
html += ' ';
html += ' ';
html += ' ';
html += '+上传图片
';
html += ' ';
$('ul.spec-images-list').append(html);
}
}
}
} else {
$('ul.spec-images-list').html('');
}
}
// 手机详情添加
$(document).on('click', '.content-app-items-add-sub', function()
{
var $content_tag = $('.content-app-items');
var i = (($(this).attr('index') || null) == null) ? parseInt($content_tag.find('li').length) : parseInt($(this).attr('index'));
var index = parseInt(Math.random()*1000001)+i;
var images_name = $content_tag.data('images-name');
var content_name = $content_tag.data('content-name');
var images_text = $content_tag.data('images-text');
var content_text = $content_tag.data('content-text');
var delete_text = $content_tag.data('delete-text');
var drag_sort_text = $content_tag.data('drag-sort-text');
var html = '';
// 左侧
html += '
';
html += '
图片 ';
html += '
';
html += '
+上传图片
';
html += '
';
// 右侧
html += '
';
html += '文本内容 ';
html += '';
html += '
';
html += '
';
// 操作按钮
html += '删除 ';
html += ' 拖拽排序 ';
html += ' ';
$content_tag.append(html);
$content_tag.attr('index', index);
$(this).attr('index', i+1);
});
// 手机详情删除
$(document).on('click', '.content-app-items-rem-sub', function()
{
$(this).parent().remove();
});
// 拖拽
$('ul.goods-photo-view').dragsort({ dragSelector: 'img', placeHolderTemplate: ' '});
$('ul.content-app-items').dragsort({ dragSelector: 'i.drag-sort-submit', placeHolderTemplate: ' '});
$('ul.goods-attribute-items').dragsort({ dragSelector: 'i.drag-sort-submit', placeHolderTemplate: ' '});
});