Authored by Lynnic

为购物车商品数量添加ajax请求 --code viewed by zhaobiao

@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 * @author: liangzhifeng<zhifeng.liang@yoho.cn> 3 * @author: liangzhifeng<zhifeng.liang@yoho.cn>
4 * @date: 2015/10/20 4 * @date: 2015/10/20
5 */ 5 */
6 - var $ = require('jquery'), 6 +var $ = require('jquery'),
7 Swiper = require('yoho.iswiper'), 7 Swiper = require('yoho.iswiper'),
8 Hammer = require('yoho.hammer'), 8 Hammer = require('yoho.hammer'),
9 lazyLoad = require('yoho.lazyload'); 9 lazyLoad = require('yoho.lazyload');
@@ -15,6 +15,8 @@ var goodsSwiper, @@ -15,6 +15,8 @@ var goodsSwiper,
15 var goodsDiscountEl = document.getElementById('goodsDiscount'), 15 var goodsDiscountEl = document.getElementById('goodsDiscount'),
16 goodsDiscountHammer = goodsDiscountEl && new Hammer(goodsDiscountEl); 16 goodsDiscountHammer = goodsDiscountEl && new Hammer(goodsDiscountEl);
17 17
  18 +var $cart = $('.cart-bar');
  19 +
18 require('./desc'); 20 require('./desc');
19 require('./comments-consults'); 21 require('./comments-consults');
20 22
@@ -67,6 +69,16 @@ if (goodsDiscountHammer) { @@ -67,6 +69,16 @@ if (goodsDiscountHammer) {
67 }); 69 });
68 } 70 }
69 71
  72 +//购物车商品数量
  73 +$.ajax({
  74 + type: 'GET',
  75 + url: '/cart/index/count',
  76 + success: function(data) {
  77 + if (data.code === 200) {
  78 + $cart.find('.num-tag').html(data.data.cart_goods_count).removeClass('hide');
  79 + }
  80 + }
  81 +});
70 82
71 require('./like'); 83 require('./like');
72 84
@@ -405,6 +405,9 @@ $basicBtnC:#eb0313; @@ -405,6 +405,9 @@ $basicBtnC:#eb0313;
405 border-radius: 50%; 405 border-radius: 50%;
406 color: #fff; 406 color: #fff;
407 font-size: pxToRem(24px); 407 font-size: pxToRem(24px);
  408 + &.hide{
  409 + display: none;
  410 + }
408 } 411 }
409 } 412 }
410 // .recommend-for-you { 413 // .recommend-for-you {
@@ -118,9 +118,7 @@ @@ -118,9 +118,7 @@
118 118
119 {{#cartInfo}} 119 {{#cartInfo}}
120 <div class="cart-bar"> 120 <div class="cart-bar">
121 - {{#if numInCart}}  
122 - <span class="num-tag">{{numInCart}}</span>  
123 - {{/if}} 121 + <span class="num-tag hide"></span>
124 <a href="{{cartUrl}}" class="num-incart iconfont">&#xe62c;</a> 122 <a href="{{cartUrl}}" class="num-incart iconfont">&#xe62c;</a>
125 123
126 {{#if addToCart}} 124 {{#if addToCart}}