...
|
...
|
@@ -245,25 +245,57 @@ var Cart = { |
|
|
},
|
|
|
|
|
|
// 编辑商品的颜色和尺寸
|
|
|
editColorOrSize: function(productId) {
|
|
|
editColorOrSize: function(productId, skn, defaultColor, defaultSize) {
|
|
|
var template;
|
|
|
var index = 0;
|
|
|
var colors;
|
|
|
var colorsLen;
|
|
|
var color;
|
|
|
|
|
|
Util.ajax({
|
|
|
url: '/shopping/cart/product/' + productId + '/edit',
|
|
|
success: function(res) {
|
|
|
if (res.code === '0') {
|
|
|
// helpers start
|
|
|
hbs.registerHelper('multiple', function(num1, num2) {
|
|
|
num1 = typeof num1 === 'number' ? num1 : parseFloat(num1, 10);
|
|
|
num2 = typeof num2 === 'number' ? num2 : parseFloat(num2, 10);
|
|
|
// 前端处理后的集合
|
|
|
var filterSet = [];
|
|
|
var defaultImg;
|
|
|
var editTarget = $('#edit_' + productId);
|
|
|
|
|
|
if (num1 && num2) {
|
|
|
return num1 * num2;
|
|
|
} else {
|
|
|
console.error('multiplication needs two number parameters');
|
|
|
}
|
|
|
// 选择
|
|
|
var selectColor;
|
|
|
|
|
|
// sku
|
|
|
var newProductSku;
|
|
|
var oldProductSku;
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: '/product/item/getProductInfo',
|
|
|
data: {
|
|
|
productId: productId,
|
|
|
skn: skn
|
|
|
},
|
|
|
success: function(res) {
|
|
|
// 没有res.code
|
|
|
if (res.colors) {
|
|
|
// 获取成功
|
|
|
colors = res.colors;
|
|
|
colorsLen = colors.length;
|
|
|
for (index; index < colorsLen; index++) {
|
|
|
color = colors[index];
|
|
|
|
|
|
// 迭代每一种颜色
|
|
|
filterSet.push({
|
|
|
proId: res.id,
|
|
|
color: color.color,
|
|
|
sizes: color.sizes,
|
|
|
pic: color.thumbs[0],
|
|
|
selectable: color.total > 0,
|
|
|
colorName: color.name
|
|
|
});
|
|
|
if (color.color === defaultColor) {
|
|
|
defaultImg = color.thumbs[0];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// helpers start
|
|
|
hbs.registerHelper('isEqual', function(v1, v2, options) {
|
|
|
if (v1 === v2) {
|
|
|
return options.fn(this);
|
...
|
...
|
@@ -271,16 +303,6 @@ var Cart = { |
|
|
return options.inverse(this);
|
|
|
});
|
|
|
|
|
|
hbs.registerHelper('showStorage', function(leftNumber) {
|
|
|
leftNumber = typeof num1 === 'number' ? leftNumber : parseFloat(leftNumber, 10);
|
|
|
|
|
|
if (leftNumber <= 3 && leftNumber >= 0) {
|
|
|
return '仅剩' + leftNumber + '件';
|
|
|
} else if (leftNumber < 0) {
|
|
|
return '库存不足';
|
|
|
}
|
|
|
});
|
|
|
|
|
|
hbs.registerHelper('image', function(url, width, height, mode) {
|
|
|
mode = parseInt(mode, 10) ? mode : 2;
|
|
|
url = url || '';
|
...
|
...
|
@@ -291,16 +313,64 @@ var Cart = { |
|
|
|
|
|
template = hbs.compile($('#edit-color-size-tpl').html());
|
|
|
|
|
|
$('#edit_' + productId).append(
|
|
|
|
|
|
editTarget.append(
|
|
|
template({
|
|
|
colors: res.colors,
|
|
|
sizes: res.sizes,
|
|
|
defaultColor: res.defaultColor,
|
|
|
defaultSize: res.defaultSize,
|
|
|
defaultImg: res.defaultImg
|
|
|
colors: filterSet,
|
|
|
defaultColor: defaultColor,
|
|
|
defaultSize: defaultSize,
|
|
|
defaultImg: defaultImg
|
|
|
})
|
|
|
);
|
|
|
|
|
|
oldProductSku = editTarget.find('.current-sizes .current').attr('data-sku');
|
|
|
|
|
|
editTarget.delegate('#confirm', 'click', function(e) {
|
|
|
e.preventDefault();
|
|
|
Util.ajax({
|
|
|
url: '/shopping/cart/updateProduct',
|
|
|
type: 'PUT',
|
|
|
data: {
|
|
|
swapData: JSON.stringify([{
|
|
|
buy_number: '1',
|
|
|
selected: 'Y',
|
|
|
new_product_sku: newProductSku,
|
|
|
old_product_sku: oldProductSku
|
|
|
}])
|
|
|
},
|
|
|
success: function(newCartData) {
|
|
|
editTarget.find('.edit-color-size').remove();
|
|
|
Util.refreshCart(newCartData);
|
|
|
}
|
|
|
});
|
|
|
return false;
|
|
|
}).delegate('#cancel', 'click', function(e) {
|
|
|
e.preventDefault();
|
|
|
editTarget.find('.edit-color-size').remove();
|
|
|
return false;
|
|
|
}).delegate('.edit-color-size', 'click', function(e) {
|
|
|
e.preventDefault();
|
|
|
return false;
|
|
|
}).delegate('.color-item', 'click', function(e) {
|
|
|
e.preventDefault();
|
|
|
selectColor = $(this);
|
|
|
if (!selectColor.hasClass('current-color')) {
|
|
|
selectColor.addClass('current-color').siblings().removeClass('current-color');
|
|
|
selectColor.parent().siblings('.current-sizes').hide().removeClass('current-sizes');
|
|
|
editTarget.find('#' + selectColor.attr('data-target')).show().addClass('current-sizes')
|
|
|
.end()
|
|
|
.find('.right img').attr({
|
|
|
src: selectColor.attr('data-imageurl'),
|
|
|
title: selectColor.attr('data-title')
|
|
|
})
|
|
|
.end()
|
|
|
.find('.selected-color').text(selectColor.attr('data-title'));
|
|
|
}
|
|
|
return false;
|
|
|
}).delegate('.current-sizes .size-item', 'click', function() {
|
|
|
$(this).addClass('current').siblings('.current').removeClass('current');
|
|
|
newProductSku = $(this).attr('data-sku');
|
|
|
});
|
|
|
},
|
|
|
fail: function() {
|
|
|
new _alert('此商品无法编辑颜色和尺寸').show();
|
...
|
...
|
|