...
|
...
|
@@ -5,13 +5,67 @@ |
|
|
*/
|
|
|
var $ = require('yoho-jquery');
|
|
|
|
|
|
var $bagNum = $('.bag-num'),
|
|
|
$bagGoodsList = $('.mini-goods-list');
|
|
|
|
|
|
var $searchWrap = $('.search-wrapper'),
|
|
|
$searchForm = $('#search-form'),
|
|
|
$searchKey = $('#search-key'),
|
|
|
$clearInput = $('.clear-input');
|
|
|
|
|
|
var goodsTpl = require('../../tpl/common/bag-goods.hbs');
|
|
|
|
|
|
var delayer;
|
|
|
|
|
|
function handelProduct(data) {
|
|
|
var goods = [],
|
|
|
list = ['commonPros', 'preSalePros', 'noStorage'];
|
|
|
var i, total = 0;
|
|
|
|
|
|
for (i = 0; i < list.length; i++) {
|
|
|
if (data[list[i]].length) {
|
|
|
goods = goods.concat(data[list[i]]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$.each(goods, function(key) {
|
|
|
total += +goods[key].buy_number || 0;
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
total: total,
|
|
|
goods: goods
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function refreshBag() {
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: '/shopping/cart/data',
|
|
|
data: {},
|
|
|
success: function(result) {
|
|
|
var data;
|
|
|
|
|
|
if (result.code === 200) {
|
|
|
data = handelProduct(result);
|
|
|
|
|
|
if (data.total) {
|
|
|
$bagNum.text(data.total);
|
|
|
$bagGoodsList.html(goodsTpl(data));
|
|
|
$bagGoodsList.parent().removeClass('bag-empty');
|
|
|
} else {
|
|
|
$bagNum.text('');
|
|
|
$bagGoodsList.empty();
|
|
|
$bagGoodsList.parent().addClass('bag-empty');
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
};
|
|
|
|
|
|
refreshBag();
|
|
|
|
|
|
$('.yoho-group a').hover(function() {
|
|
|
var data = $(this).data();
|
|
|
|
...
|
...
|
@@ -89,3 +143,7 @@ $(document).click(function(e) { |
|
|
$searchWrap.hide();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
module.exports = {
|
|
|
refreshBag
|
|
|
}; |
...
|
...
|
|