Authored by biao

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

@@ -99,6 +99,17 @@ function checkColorSizeNum() { @@ -99,6 +99,17 @@ function checkColorSizeNum() {
99 return true; 99 return true;
100 } 100 }
101 101
  102 +//禁用数字编辑
  103 +function disableNumEdit() {
  104 + var $numBtn = $('.chose-panel').find('.num .btn>.iconfont');
  105 +
  106 + //添加disabled样式
  107 + $numBtn.hasClass('disabled') ? null : $numBtn.addClass('disabled');
  108 +
  109 + $yohoPage.off('touchstart', '.btn-minus');
  110 + $yohoPage.off('touchstart', '.btn-plus');
  111 +}
  112 +
102 113
103 function show(html, cb) { 114 function show(html, cb) {
104 var scrollPosition = [ 115 var scrollPosition = [
@@ -116,8 +127,7 @@ function show(html, cb) { @@ -116,8 +127,7 @@ function show(html, cb) {
116 if (html) { 127 if (html) {
117 $chosePanel.html(html); 128 $chosePanel.html(html);
118 if ($('#promotionId').val() !== '') { 129 if ($('#promotionId').val() !== '') {
119 - $yohoPage.off('touchstart', '.btn-minus');  
120 - $yohoPage.off('touchstart', '.btn-plus'); 130 + disableNumEdit();
121 } 131 }
122 init(); 132 init();
123 } 133 }
@@ -497,4 +507,5 @@ exports.init = init; @@ -497,4 +507,5 @@ exports.init = init;
497 exports.show = show; 507 exports.show = show;
498 exports.remove = removePannel; 508 exports.remove = removePannel;
499 exports.setEditModeWithSknId = setEditModeWithSknId; 509 exports.setEditModeWithSknId = setEditModeWithSknId;
  510 +exports.disableNumEdit = disableNumEdit;
500 511
@@ -16,6 +16,9 @@ var dialog = require('../me/dialog'), @@ -16,6 +16,9 @@ var dialog = require('../me/dialog'),
16 var $selectAllBtn = $('.balance .checkbox'), 16 var $selectAllBtn = $('.balance .checkbox'),
17 requesting = false; 17 requesting = false;
18 18
  19 +//上次编辑的商品skn
  20 +var previousEditSkn;
  21 +
19 ellipsis.init(); 22 ellipsis.init();
20 23
21 lazyLoad({ 24 lazyLoad({
@@ -86,11 +89,12 @@ $('.cart-goods').on('touchstart', '.checkbox', function() { @@ -86,11 +89,12 @@ $('.cart-goods').on('touchstart', '.checkbox', function() {
86 * 89 *
87 * @param {Bool} isSelected. 所要编辑的商品是否被选中 90 * @param {Bool} isSelected. 所要编辑的商品是否被选中
88 * 91 *
89 - * @return false; 92 + * @param {Bool} isEditNum. 所要编辑的商品是否被选中
  93 + *
  94 + * @return false or undefined
90 * 95 *
91 */ 96 */
92 -function showEditPannelWithSku(html, id, isSelected) {  
93 - 97 +function showEditPannelWithSku(html, id, isSelected, isEditNum) {
94 if (html.length < 2) { 98 if (html.length < 2) {
95 tip.show('出错啦!'); 99 tip.show('出错啦!');
96 return false; 100 return false;
@@ -100,22 +104,48 @@ function showEditPannelWithSku(html, id, isSelected) { @@ -100,22 +104,48 @@ function showEditPannelWithSku(html, id, isSelected) {
100 chosePanel.remove(); 104 chosePanel.remove();
101 105
102 $(html).appendTo('#mainCart'); 106 $(html).appendTo('#mainCart');
  107 +
  108 +
103 chosePanel.init(); 109 chosePanel.init();
104 chosePanel.setEditModeWithSknId(id, isSelected); 110 chosePanel.setEditModeWithSknId(id, isSelected);
105 - chosePanel.show();  
106 111
107 - return false; 112 + if (!isEditNum) {
  113 + chosePanel.disableNumEdit();
  114 + }
  115 +
  116 + chosePanel.show();
108 } 117 }
109 118
110 119
111 $('.icon-edit').on('touchstart', function(e) { 120 $('.icon-edit').on('touchstart', function(e) {
112 var $this = $(this), 121 var $this = $(this),
  122 + skn = $this.closest('.shopping-cart-good').data('skn');
  123 +
  124 + var $checkBox,
  125 + $tag;
  126 +
  127 + var id,
  128 + count,
  129 + canEditNum;
  130 +
  131 + //如果点击的是上次编辑的商品,直接显示chose-pannel
  132 + if (skn === previousEditSkn) {
  133 + chosePanel.show();
  134 + return;
  135 + }
  136 +
  137 + previousEditSkn = skn;
  138 +
  139 +
113 $checkBox = $this.closest('.info').siblings('.checkbox'); 140 $checkBox = $this.closest('.info').siblings('.checkbox');
  141 + $tag = $this.closest('.deps').siblings('.few-tag');
114 142
115 - var skn = $this.closest('.shopping-cart-good').data('skn'),  
116 - id = $this.closest('.shopping-cart-good').data('id'), 143 + id = $this.closest('.shopping-cart-good').data('id');
117 count = $this.data('count'); 144 count = $this.data('count');
118 145
  146 + //加价购或者赠品不能编辑数量
  147 + canEditNum = $tag.hasClass('gift-tag') || $tag.hasClass('plus-tag') ? false : true;
  148 +
119 e.stopPropagation(); 149 e.stopPropagation();
120 150
121 loading.showLoadingMask(); 151 loading.showLoadingMask();
@@ -128,7 +158,7 @@ $('.icon-edit').on('touchstart', function(e) { @@ -128,7 +158,7 @@ $('.icon-edit').on('touchstart', function(e) {
128 buy_num: count 158 buy_num: count
129 }, 159 },
130 success: function(res) { 160 success: function(res) {
131 - showEditPannelWithSku(res, id, $checkBox.hasClass('icon-cb-checked')); 161 + showEditPannelWithSku(res, id, $checkBox.hasClass('icon-cb-checked'), canEditNum);
132 }, 162 },
133 error: function() { 163 error: function() {
134 tip.show('网络异常'); 164 tip.show('网络异常');