Authored by xuqi

num plus/minus

... ... @@ -401,14 +401,6 @@ const modifyProductNum = (options) => {
// }
}
});
// 增加
if (increaseNum && (buyNumber + increaseNum) > storageNumber) {
return {
code: '1000',
message: '商品库存不足'
};
}
} else if (goodType === 'ordinary') {
// 检查库存量
// 同步
... ... @@ -438,14 +430,6 @@ const modifyProductNum = (options) => {
// }
}
});
// 增加
if (increaseNum && (buyNumber + increaseNum) > storageNumber) {
return {
code: '1000',
message: '商品库存不足'
};
}
}
// 异步
... ...
... ... @@ -5,7 +5,7 @@
<div class="num">
<input type="text" class="input" value={{buy_number}} readonly="readonly" />
</div>
<div class="plus action {{#isEqual left_number 0}}disable{{/isEqual}}">
<div class="plus action">
<span class="iconfont">&#xe61f;</span>
</div>
<div class="warning">
... ...
... ... @@ -72,10 +72,7 @@ var Stepper = {
goodType;
var steppers = $('.stepper'),
$input,
currNum,
minus,
plus;
$input;
// 数量为1的不能再减少
steppers.find('input').each(function() {
... ... @@ -88,50 +85,22 @@ var Stepper = {
// 减少
steppers.on('click', '.minus', function() {
$target = $(this);
$input = $target.next().find('input');
currNum = $input.val();
plus = $input.parent().next();
if (!$target.hasClass('disable') && !$target.parents('.cart-pro-list').hasClass('invalid-pros')) {
sku = $.parseJSON($target.parents('ul').children().first().attr('data-product_info')).product_sku;
goodType = $target.parent().attr('data-producttype');
_this.decrease(goodType, sku, currNum, function(num, changed) {
if (num === 1) {
$input.val(1);
$target.addClass('disable');
} else {
$input.val(num);
}
// 如果plus被灰化了
if (changed && plus.hasClass('disable')) {
plus.removeClass('disable');
}
});
_this.decrease(goodType, sku, $target.next().find('input').val());
}
});
// 增加
steppers.on('click', '.plus', function() {
$target = $(this);
$input = $target.prev().find('input');
currNum = $input.val();
minus = $input.parent().prev();
if (!$target.hasClass('disable') && !$target.parents('.cart-pro-list').hasClass('invalid-pros')) {
sku = $.parseJSON($target.parents('ul').children().first().attr('data-product_info')).product_sku;
goodType = $target.parent().attr('data-producttype');
_this.increase(goodType, sku, currNum, function(num, changed, overflow) {
if (overflow) {
$target.addClass('disable');
}
$input.val(num);
// 如果minus被灰化了
if (changed && minus.hasClass('disable')) {
minus.removeClass('disable');
}
});
_this.increase(goodType, sku);
}
});
}
... ...
... ... @@ -62,7 +62,7 @@
<div class="num">
<input type="text" class="input" value={{buy_number}} readonly />
</div>
<div class="plus action {{#isEqual left_number 0}}disable{{/isEqual}}">
<div class="plus action">
<span class="iconfont">&#xe61f;</span>
</div>
<div class="warning">
... ... @@ -129,7 +129,7 @@
<div class="num">
<input type="text" class="input" value={{buy_number}} readonly />
</div>
<div class="plus action {{#isEqual left_number 0}}disable{{/isEqual}}">
<div class="plus action">
<span class="iconfont">&#xe61f;</span>
</div>
<div class="warning">
... ... @@ -160,47 +160,47 @@
<li class="chk" data-product_info='{"goods_type": "invalid", "buy_number": {{buy_number}}, "selected": "{{selected}}", "product_sku": "{{product_sku}}", "promotion_id": 0}'>
<span class="iconfont warning">&#xe625;</span>
</li>
<li>
<a href="javascript:void(0)">
<img src="{{image goods_images 100 134}}" alt="{{product_name}}">
</a>
</li>
<li class="pro-info">
<a class="brand-name" href="/product/shop/{{brand_domain}}" target="_blank">{{brand_name}}</a>
<div class="pro-name"><a href="javascript:void(0)">{{product_name}}</a></div>
<div>
{{#if color_name}}
<span class="mr20">颜色: {{color_name}}</span>
{{/if}}
{{#if size_name}}
<span>尺寸: {{size_name}}</span>
{{/if}}
</div>
</li>
<li class="price-num">
<span class="price sale-price">¥ {{round sales_price 2}}</span>
<div class="stepper" data-productType={{goods_type}}>
<div class="minus action {{#isEqual buy_number 1}}disable{{/isEqual}}">
<span class="iconfont">&#xe621;</span>
</div>
<div class="num">
<input type="text" class="input" value={{buy_number}} readonly />
</div>
<div class="plus action {{#isEqual left_number 0}}disable{{/isEqual}}">
<span class="iconfont">&#xe61f;</span>
</div>
<div class="warning">
{{showStorage left_number}}
</div>
</div>
</li>
<li class="total-price-action">
<span class="price item-total-price">¥ {{round (multiple sales_price buy_number) 2}}</span>
<div class="actions">
<div class="remove-item action" data-product_id={{product_id}}><span class="iconfont">&#xe614;</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div class="send-to-favorite action" data-product_id={{product_id}}>移入收藏夹</div>
</div>
</li>
<li>
<a href="javascript:void(0)">
<img src="{{image goods_images 100 134}}" alt="{{product_name}}">
</a>
</li>
<li class="pro-info">
<a class="brand-name" href="/product/shop/{{brand_domain}}" target="_blank">{{brand_name}}</a>
<div class="pro-name"><a href="javascript:void(0)">{{product_name}}</a></div>
<div>
{{#if color_name}}
<span class="mr20">颜色: {{color_name}}</span>
{{/if}}
{{#if size_name}}
<span>尺寸: {{size_name}}</span>
{{/if}}
</div>
</li>
<li class="price-num">
<span class="price sale-price">¥ {{round sales_price 2}}</span>
<div class="stepper" data-productType={{goods_type}}>
<div class="minus action {{#isEqual buy_number 1}}disable{{/isEqual}}">
<span class="iconfont">&#xe621;</span>
</div>
<div class="num">
<input type="text" class="input" value={{buy_number}} readonly />
</div>
<div class="plus action">
<span class="iconfont">&#xe61f;</span>
</div>
<div class="warning">
{{showStorage left_number}}
</div>
</div>
</li>
<li class="total-price-action">
<span class="price item-total-price">¥ {{round (multiple sales_price buy_number) 2}}</span>
<div class="actions">
<div class="remove-item action" data-product_id={{product_id}}><span class="iconfont">&#xe614;</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div class="send-to-favorite action" data-product_id={{product_id}}>移入收藏夹</div>
</div>
</li>
</ul>
{{/each}}
</div>
... ...