Authored by biao

购物车中赠品或者加价购的商品增加编辑功能. code review by 张振

... ... @@ -99,6 +99,17 @@ function checkColorSizeNum() {
return true;
}
//禁用数字编辑
function disableNumEdit() {
var $numBtn = $('.chose-panel').find('.num .btn>.iconfont');
//添加disabled样式
$numBtn.hasClass('disabled') ? null : $numBtn.addClass('disabled');
$yohoPage.off('touchstart', '.btn-minus');
$yohoPage.off('touchstart', '.btn-plus');
}
function show(html, cb) {
var scrollPosition = [
... ... @@ -116,8 +127,7 @@ function show(html, cb) {
if (html) {
$chosePanel.html(html);
if ($('#promotionId').val() !== '') {
$yohoPage.off('touchstart', '.btn-minus');
$yohoPage.off('touchstart', '.btn-plus');
disableNumEdit();
}
init();
}
... ... @@ -497,4 +507,5 @@ exports.init = init;
exports.show = show;
exports.remove = removePannel;
exports.setEditModeWithSknId = setEditModeWithSknId;
exports.disableNumEdit = disableNumEdit;
... ...
... ... @@ -16,6 +16,9 @@ var dialog = require('../me/dialog'),
var $selectAllBtn = $('.balance .checkbox'),
requesting = false;
//上次编辑的商品skn
var previousEditSkn;
ellipsis.init();
lazyLoad({
... ... @@ -86,11 +89,12 @@ $('.cart-goods').on('touchstart', '.checkbox', function() {
*
* @param {Bool} isSelected. 所要编辑的商品是否被选中
*
* @return false;
* @param {Bool} isEditNum. 所要编辑的商品是否被选中
*
* @return false or undefined
*
*/
function showEditPannelWithSku(html, id, isSelected) {
function showEditPannelWithSku(html, id, isSelected, isEditNum) {
if (html.length < 2) {
tip.show('出错啦!');
return false;
... ... @@ -100,22 +104,48 @@ function showEditPannelWithSku(html, id, isSelected) {
chosePanel.remove();
$(html).appendTo('#mainCart');
chosePanel.init();
chosePanel.setEditModeWithSknId(id, isSelected);
chosePanel.show();
return false;
if (!isEditNum) {
chosePanel.disableNumEdit();
}
chosePanel.show();
}
$('.icon-edit').on('touchstart', function(e) {
var $this = $(this),
skn = $this.closest('.shopping-cart-good').data('skn');
var $checkBox,
$tag;
var id,
count,
canEditNum;
//如果点击的是上次编辑的商品,直接显示chose-pannel
if (skn === previousEditSkn) {
chosePanel.show();
return;
}
previousEditSkn = skn;
$checkBox = $this.closest('.info').siblings('.checkbox');
$tag = $this.closest('.deps').siblings('.few-tag');
var skn = $this.closest('.shopping-cart-good').data('skn'),
id = $this.closest('.shopping-cart-good').data('id'),
id = $this.closest('.shopping-cart-good').data('id');
count = $this.data('count');
//加价购或者赠品不能编辑数量
canEditNum = $tag.hasClass('gift-tag') || $tag.hasClass('plus-tag') ? false : true;
e.stopPropagation();
loading.showLoadingMask();
... ... @@ -128,7 +158,7 @@ $('.icon-edit').on('touchstart', function(e) {
buy_num: count
},
success: function(res) {
showEditPannelWithSku(res, id, $checkBox.hasClass('icon-cb-checked'));
showEditPannelWithSku(res, id, $checkBox.hasClass('icon-cb-checked'), canEditNum);
},
error: function() {
tip.show('网络异常');
... ...