Authored by hf

code review by hf: fixes some bugs to help detail page

@@ -14,6 +14,8 @@ var chosePanel = require('./chose-panel'), @@ -14,6 +14,8 @@ var chosePanel = require('./chose-panel'),
14 var $cartContent = $('.cart-content'); 14 var $cartContent = $('.cart-content');
15 15
16 var navHammer, 16 var navHammer,
  17 + advanceBuyHammer,
  18 + freebieHammer,
17 cartType = $('#cartType').val(); 19 cartType = $('#cartType').val();
18 20
19 var hasChecked = $('.cart-content:not(.hide) .icon-cb-checked').length > 0 ? true : false; //是否有选中商品 21 var hasChecked = $('.cart-content:not(.hide) .icon-cb-checked').length > 0 ? true : false; //是否有选中商品
@@ -47,6 +49,8 @@ if ($('.cart-nav').length > 0) { @@ -47,6 +49,8 @@ if ($('.cart-nav').length > 0) {
47 //切换普通商品和预售商品购物车显示 49 //切换普通商品和预售商品购物车显示
48 $cartContent.toggleClass('hide'); 50 $cartContent.toggleClass('hide');
49 51
  52 + hasChecked = $('.cart-content:not(.hide) .icon-cb-checked').length > 0 ? true : false;
  53 +
50 //trigger lazyload 54 //trigger lazyload
51 $(window).trigger('scroll'); 55 $(window).trigger('scroll');
52 }); 56 });
@@ -56,13 +60,27 @@ if ($('.cart-nav').length > 0) { @@ -56,13 +60,27 @@ if ($('.cart-nav').length > 0) {
56 }, 3000); 60 }, 3000);
57 } 61 }
58 62
59 -$('.advance-buy').on('touchend', function() {  
60 - window.location.href = '/cart/index/advanceBuy?cartType=' + cartType;  
61 -}); 63 +if ($('.advance-buy').length > 0) {
  64 + advanceBuyHammer = new Hammer(document.getElementsByClassName('advance-buy')[0]);
  65 + advanceBuyHammer.on('tap', function(e) {
  66 + window.location.href = '/cart/index/advanceBuy?cartType=' + cartType;
  67 + });
  68 +}
62 69
63 -$('.freebie').on('touchend', function() {  
64 - window.location.href = '/cart/index/gift?cartType=' + cartType;  
65 -}); 70 +if ($('.freebie').length > 0) {
  71 + freebieHammer = new Hammer(document.getElementsByClassName('freebie')[0]);
  72 + freebieHammer.on('tap', function(e) {
  73 + window.location.href = '/cart/index/gift?cartType=' + cartType;
  74 + });
  75 +}
  76 +
  77 +//$('.advance-buy').on('touchend', function() {
  78 +// window.location.href = '/cart/index/advanceBuy?cartType=' + cartType;
  79 +//});
  80 +//
  81 +//$('.freebie').on('touchend', function() {
  82 +// window.location.href = '/cart/index/gift?cartType=' + cartType;
  83 +//});
66 84
67 $('.btn-balance').on('touchend', function() { 85 $('.btn-balance').on('touchend', function() {
68 if ($('.low-stocks').length > 0) { 86 if ($('.low-stocks').length > 0) {
@@ -78,8 +96,6 @@ $('.btn-balance').on('touchend', function() { @@ -78,8 +96,6 @@ $('.btn-balance').on('touchend', function() {
78 }); 96 });
79 97
80 $('.chose').on('touchend', function() { 98 $('.chose').on('touchend', function() {
81 -  
82 - //var id = $(this).closest('.gift-advance-good').data('id');  
83 chosePanel.show(); 99 chosePanel.show();
84 }); 100 });
85 101
@@ -70,7 +70,6 @@ function show(html, cb) { @@ -70,7 +70,6 @@ function show(html, cb) {
70 init(); 70 init();
71 } 71 }
72 $('.chose-panel').show(); 72 $('.chose-panel').show();
73 - $('body').css('overflow', 'hidden');  
74 $num = $('#good-num'); 73 $num = $('#good-num');
75 cbFn = cb; 74 cbFn = cb;
76 } 75 }
@@ -78,7 +77,6 @@ function show(html, cb) { @@ -78,7 +77,6 @@ function show(html, cb) {
78 //隐藏当前Panel 77 //隐藏当前Panel
79 function hide() { 78 function hide() {
80 $('.chose-panel').hide(); 79 $('.chose-panel').hide();
81 - $('body').css('overflow', 'auto');  
82 } 80 }
83 81
84 //修改加入购物车的文字和背景 82 //修改加入购物车的文字和背景
@@ -208,11 +206,11 @@ $yohoPage.on('touchstart', '.color-list .block', function() { @@ -208,11 +206,11 @@ $yohoPage.on('touchstart', '.color-list .block', function() {
208 curColorIndex = index; 206 curColorIndex = index;
209 $('#good-num').val(1); 207 $('#good-num').val(1);
210 208
211 - // 设置按钮的样式和文字  
212 - updateConformButtonClassAndText();  
213 -  
214 // 修改颜色时修改商品图片 209 // 修改颜色时修改商品图片
215 changeGoodImgWhenClickColor(); 210 changeGoodImgWhenClickColor();
  211 +
  212 + // 设置按钮的样式和文字
  213 + updateConformButtonClassAndText();
216 }).on('touchstart', '.size-list .block', function() { 214 }).on('touchstart', '.size-list .block', function() {
217 var $this = $(this), 215 var $this = $(this),
218 index, 216 index,
@@ -232,11 +230,12 @@ $yohoPage.on('touchstart', '.color-list .block', function() { @@ -232,11 +230,12 @@ $yohoPage.on('touchstart', '.color-list .block', function() {
232 $allChoseItems.find('.num .left-num').html(''); 230 $allChoseItems.find('.num .left-num').html('');
233 $('#left-num').val(0); 231 $('#left-num').val(0);
234 hasChooseSize = false; 232 hasChooseSize = false;
  233 + curSizeIndex = null;
  234 + $curSizeBlock = null;
235 235
236 // 当前尺码不是选中状态,选中时 236 // 当前尺码不是选中状态,选中时
237 } else { 237 } else {
238 hasChooseSize = true; 238 hasChooseSize = true;
239 -  
240 curGoodNum = $this.data('num'); 239 curGoodNum = $this.data('num');
241 240
242 // 之前选中的尺码去掉勾选样式 241 // 之前选中的尺码去掉勾选样式
@@ -253,18 +252,21 @@ $yohoPage.on('touchstart', '.color-list .block', function() { @@ -253,18 +252,21 @@ $yohoPage.on('touchstart', '.color-list .block', function() {
253 $('#left-num').val(0); 252 $('#left-num').val(0);
254 } 253 }
255 254
  255 + if (curGoodNum === 0 && hasChooseColor) {
  256 + $this.addClass('zero-stock');
  257 + }
  258 + curSizeIndex = index;
  259 + $curSizeBlock = $this;
256 } 260 }
257 261
258 $this.toggleClass('chosed'); 262 $this.toggleClass('chosed');
259 - curSizeIndex = index;  
260 - $curSizeBlock = $this;  
261 $('#good-num').val(1); 263 $('#good-num').val(1);
262 264
263 - // 设置按钮的样式和文字  
264 - updateConformButtonClassAndText();  
265 -  
266 // 重置颜色块的样式 265 // 重置颜色块的样式
267 resetColorZeroStock($siblingBlock); 266 resetColorZeroStock($siblingBlock);
  267 +
  268 + // 设置按钮的样式和文字
  269 + updateConformButtonClassAndText();
268 }); 270 });
269 271
270 $yohoPage.on('touchstart', '.btn-minus', function() { 272 $yohoPage.on('touchstart', '.btn-minus', function() {
@@ -281,7 +283,7 @@ $yohoPage.on('touchstart', '.btn-minus', function() { @@ -281,7 +283,7 @@ $yohoPage.on('touchstart', '.btn-minus', function() {
281 return; 283 return;
282 } 284 }
283 if (num < 0) { 285 if (num < 0) {
284 - tip.show('您选择的数量不能为~'); 286 + tip.show('您选择的数量不能为负数~');
285 return; 287 return;
286 } 288 }
287 289
@@ -295,7 +297,6 @@ $yohoPage.on('touchstart', '.btn-minus', function() { @@ -295,7 +297,6 @@ $yohoPage.on('touchstart', '.btn-minus', function() {
295 return; 297 return;
296 } 298 }
297 299
298 -  
299 if (num - 0 === leftNum || 0 === leftNum) { 300 if (num - 0 === leftNum || 0 === leftNum) {
300 return; 301 return;
301 } 302 }
@@ -23,7 +23,8 @@ var dispatchModeHammer, @@ -23,7 +23,8 @@ var dispatchModeHammer,
23 payType, 23 payType,
24 priceTmpl = Handlebars.compile($('#tmpl-price').html()), 24 priceTmpl = Handlebars.compile($('#tmpl-price').html()),
25 queryString = $.queryString(), 25 queryString = $.queryString(),
26 - orderInfo = order.orderInfo; 26 + orderInfo = order.orderInfo,
  27 + isSubmiting;
27 28
28 lazyLoad(); 29 lazyLoad();
29 30
@@ -127,6 +128,9 @@ function submitOrder() { @@ -127,6 +128,9 @@ function submitOrder() {
127 var invoiceText = $invoice.find('[name="invoice-title"]').val() || orderInfo('invoiceText'), 128 var invoiceText = $invoice.find('[name="invoice-title"]').val() || orderInfo('invoiceText'),
128 msg = $('#msg').find('input').val() || orderInfo('msg'); 129 msg = $('#msg').find('input').val() || orderInfo('msg');
129 130
  131 + if (isSubmiting) {
  132 + return false;
  133 + }
130 if (orderInfo('invoice')) { 134 if (orderInfo('invoice')) {
131 if (!invoiceText) { 135 if (!invoiceText) {
132 tip.show('请输入发票抬头'); 136 tip.show('请输入发票抬头');
@@ -144,6 +148,7 @@ function submitOrder() { @@ -144,6 +148,7 @@ function submitOrder() {
144 } 148 }
145 } 149 }
146 loading.showLoadingMask(); 150 loading.showLoadingMask();
  151 + isSubmiting = true;
147 $.ajax({ 152 $.ajax({
148 method: 'POST', 153 method: 'POST',
149 url: '/cart/index/orderSub', 154 url: '/cart/index/orderSub',
@@ -184,6 +189,7 @@ function submitOrder() { @@ -184,6 +189,7 @@ function submitOrder() {
184 }).fail(function() { 189 }).fail(function() {
185 tip.show('网络出错'); 190 tip.show('网络出错');
186 }).always(function() { 191 }).always(function() {
  192 + isSubmiting = false;
187 loading.hideLoadingMask(); 193 loading.hideLoadingMask();
188 }); 194 });
189 } 195 }
@@ -250,3 +256,7 @@ $('.pay-mode').on('click', 'li', function() { @@ -250,3 +256,7 @@ $('.pay-mode').on('click', 'li', function() {
250 payType = $this.data('pay-type'); 256 payType = $this.data('pay-type');
251 submitOrder(); 257 submitOrder();
252 }); 258 });
  259 +
  260 +$('form').on('submit', function() {
  261 + return false;
  262 +});
@@ -5,15 +5,6 @@ @@ -5,15 +5,6 @@
5 margin-left: 34rem / $pxConvertRem; 5 margin-left: 34rem / $pxConvertRem;
6 height: 160rem / $pxConvertRem; 6 height: 160rem / $pxConvertRem;
7 border-bottom: 1px solid #e0e0e0; 7 border-bottom: 1px solid #e0e0e0;
8 -  
9 - &:last-child {  
10 - border-bottom: none;  
11 - }  
12 - }  
13 -  
14 -  
15 - .advance-block .gift-advance-good:last-child {  
16 - border-bottom: none;  
17 } 8 }
18 9
19 .advance-block:last-child .gift-advance-good:last-child { 10 .advance-block:last-child .gift-advance-good:last-child {
@@ -111,6 +111,11 @@ @@ -111,6 +111,11 @@
111 .price { 111 .price {
112 font-size: 0.6rem; 112 font-size: 0.6rem;
113 color: $cartRed; 113 color: $cartRed;
  114 + display: inline;
  115 + .sale-price{
  116 + color: #b0b0b0;
  117 + text-decoration: line-through;
  118 + }
114 } 119 }
115 120
116 .count { 121 .count {
@@ -140,10 +140,11 @@ @@ -140,10 +140,11 @@
140 140
141 > li { 141 > li {
142 box-sizing: border-box; 142 box-sizing: border-box;
143 - height: 90rem / $pxConvertRem;  
144 - line-height: 90rem / $pxConvertRem; 143 + height: 80rem / $pxConvertRem;
  144 + line-height: 80rem / $pxConvertRem;
145 margin-bottom: 10rem / $pxConvertRem; 145 margin-bottom: 10rem / $pxConvertRem;
146 padding: 0 20rem / $pxConvertRem; 146 padding: 0 20rem / $pxConvertRem;
  147 + background: #f1f1f1;
147 148
148 &:last-child { 149 &:last-child {
149 margin-bottom: 0; 150 margin-bottom: 0;
@@ -49,7 +49,7 @@ @@ -49,7 +49,7 @@
49 .not-use { 49 .not-use {
50 display: block; 50 display: block;
51 width: pxToRem(560px); 51 width: pxToRem(560px);
52 - margin: pxToRem(30px) auto; 52 + margin: pxToRem(30px) auto 0;
53 text-align: center; 53 text-align: center;
54 font-size: pxToRem(32px); 54 font-size: pxToRem(32px);
55 line-height: 2.5; 55 line-height: 2.5;
@@ -41,10 +41,12 @@ @@ -41,10 +41,12 @@
41 </p> 41 </p>
42 </div> 42 </div>
43 <p class="row"> 43 <p class="row">
44 - <span class="price">  
45 - ¥{{price}}  
46 - </span>  
47 - 44 + <p class="price">
  45 + <span class="market-price">¥{{price}}</span>
  46 + {{#if isAdvanceBuy}}
  47 + <span class="sale-price">¥{{salesPrice}}</span>
  48 + {{/if}}
  49 + </p>
48 {{#if isVipPrice}} 50 {{#if isVipPrice}}
49 <span class="vip"> 51 <span class="vip">
50 VIP 52 VIP
@@ -555,8 +555,8 @@ class CartModel @@ -555,8 +555,8 @@ class CartModel
555 $notAvailableRes = self::searchCoupon($uid, $val['couponCode']); 555 $notAvailableRes = self::searchCoupon($uid, $val['couponCode']);
556 // 处理可用的优惠券 556 // 处理可用的优惠券
557 if ($val['isValidity'] === 'N' || (isset($notAvailableRes['code']) && $notAvailableRes['code'] !== 200)) { 557 if ($val['isValidity'] === 'N' || (isset($notAvailableRes['code']) && $notAvailableRes['code'] !== 200)) {
558 -// $val['notAvailable'] = true;  
559 - continue; 558 + $val['notAvailable'] = true;
  559 + // continue;
560 } 560 }
561 $result[] = $val; 561 $result[] = $val;
562 } 562 }