...
|
...
|
@@ -6,24 +6,27 @@ |
|
|
*/
|
|
|
|
|
|
var Util = require('./util');
|
|
|
var $ = require('yoho-jquery');
|
|
|
|
|
|
var Stepper = {
|
|
|
// 减少商品数量
|
|
|
decrease: function(productId, currNum, callback) {
|
|
|
decrease: function(sku, currNum) {
|
|
|
if (parseInt(currNum, 10) <= 1) {
|
|
|
return callback(1);
|
|
|
//return callback(1);
|
|
|
} else {
|
|
|
Util.ajax({
|
|
|
url: '/shopping/cart/product/' + productId + '/change_num',
|
|
|
url: '/shopping/cart/product/change_num',
|
|
|
type: 'POST',
|
|
|
data: {
|
|
|
changeType: 'DECREASE',
|
|
|
changeTo: parseInt(currNum, 10) - 1
|
|
|
sku: sku
|
|
|
|
|
|
// changeTo: parseInt(currNum, 10) - 1
|
|
|
},
|
|
|
success: function(res) {
|
|
|
if (res.code === '0') {
|
|
|
return callback(res.num, res.changed);
|
|
|
}
|
|
|
Util.refreshCart(res, function() {
|
|
|
Stepper.init();
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
}
|
...
|
...
|
@@ -31,21 +34,25 @@ var Stepper = { |
|
|
},
|
|
|
|
|
|
// 增加商品数量
|
|
|
increase: function(productId, currNum, callback) {
|
|
|
increase: function(sku) {
|
|
|
Util.ajax({
|
|
|
url: '/shopping/cart/product/' + productId + '/change_num',
|
|
|
url: '/shopping/cart/product/change_num',
|
|
|
type: 'POST',
|
|
|
data: {
|
|
|
changeType: 'INCREASE',
|
|
|
changeTo: parseInt(currNum, 10) + 1
|
|
|
sku: sku
|
|
|
|
|
|
// changeTo: parseInt(currNum, 10) + 1
|
|
|
},
|
|
|
success: function(res) {
|
|
|
if (res.code === '0') {
|
|
|
return callback(res.num, res.changed);
|
|
|
} else {
|
|
|
return callback(res.num, res.changed, res.code === '1000');
|
|
|
}
|
|
|
|
|
|
// if (res.code === '0') {
|
|
|
// return callback(res.num, res.changed);
|
|
|
// } else {
|
|
|
// return callback(res.num, res.changed, res.code === '1000');
|
|
|
// }
|
|
|
Util.refreshCart(res, function() {
|
|
|
Stepper.init();
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
},
|
...
|
...
|
@@ -53,7 +60,7 @@ var Stepper = { |
|
|
init: function() {
|
|
|
var _this = this,
|
|
|
$target,
|
|
|
productId;
|
|
|
sku;
|
|
|
|
|
|
var steppers = $('.stepper'),
|
|
|
$input,
|
...
|
...
|
@@ -77,8 +84,8 @@ var Stepper = { |
|
|
plus = $input.parent().next();
|
|
|
|
|
|
if (!$target.hasClass('disable')) {
|
|
|
productId = $target.parent().attr('data-productId');
|
|
|
_this.decrease(productId, currNum, function(num, changed) {
|
|
|
sku = $.parseJSON($target.parents('ul').children().first().attr('data-product_info')).product_sku;
|
|
|
_this.decrease(sku, currNum, function(num, changed) {
|
|
|
if (num === 1) {
|
|
|
$input.val(1);
|
|
|
$target.addClass('disable');
|
...
|
...
|
@@ -103,8 +110,8 @@ var Stepper = { |
|
|
minus = $input.parent().prev();
|
|
|
|
|
|
if (!$target.hasClass('disable')) {
|
|
|
productId = $target.parent().attr('data-productId');
|
|
|
_this.increase(productId, currNum, function(num, changed, overflow) {
|
|
|
sku = $.parseJSON($target.parents('ul').children().first().attr('data-product_info')).product_sku;
|
|
|
_this.increase(sku, currNum, function(num, changed, overflow) {
|
|
|
if (overflow) {
|
|
|
$target.addClass('disable');
|
|
|
}
|
...
|
...
|
|