...
|
...
|
@@ -3,10 +3,8 @@ |
|
|
* @author: yyq<yanqing.yang@yoho.cn>
|
|
|
* @date: 2016/5/9
|
|
|
*/
|
|
|
/* eslint-disable */
|
|
|
var $ = require('yoho-jquery');
|
|
|
// handlebars = require('yoho.handlebars'),
|
|
|
// json2 = require('json2');
|
|
|
var $ = require('yoho-jquery'),
|
|
|
handlebars = require('yoho-handlebars');
|
|
|
|
|
|
var $tool = $('.tool-wrapper'),
|
|
|
$yohoGroup = $tool.find('.yoho-group'),
|
...
|
...
|
@@ -21,29 +19,25 @@ var $head = $('.head-wrapper'), |
|
|
|
|
|
var $subNav = $('.sub-nav-list .contain-third');
|
|
|
|
|
|
var apiDomain = $('#api-domain').val(), // 获取登陆状态的地址
|
|
|
apiBanner = 'http://new.yohobuy.com/common/getbanner',
|
|
|
thirdLineNum = 9,
|
|
|
var thirdLineNum = 9,
|
|
|
delayer,
|
|
|
centerFn,
|
|
|
loginFn,
|
|
|
cartFn;
|
|
|
|
|
|
$('#api-domain').remove(); // 删除地址信息
|
|
|
|
|
|
// handlebars模板
|
|
|
// centerFn = handlebars.compile($('#simple-account-info-tpl').html());
|
|
|
// loginFn = handlebars.compile($('#header-login-info-tpl').html());
|
|
|
// cartFn = handlebars.compile($('#mini-cart-tpl').html());
|
|
|
centerFn = handlebars.compile($('#simple-account-info-tpl').html());
|
|
|
loginFn = handlebars.compile($('#header-login-info-tpl').html());
|
|
|
cartFn = handlebars.compile($('#mini-cart-tpl').html());
|
|
|
|
|
|
// handlebars helper
|
|
|
// handlebars.registerHelper('notzero', function(v1, options) {
|
|
|
// if (v1 !== '0') {
|
|
|
// return options.fn(this);
|
|
|
// } else {
|
|
|
// return options.inverse(this);
|
|
|
// }
|
|
|
// });
|
|
|
handlebars.registerHelper('notzero', function(v1, options) {
|
|
|
if (v1 !== '0') {
|
|
|
return options.fn(this);
|
|
|
} else {
|
|
|
return options.inverse(this);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 格式化三级菜单
|
|
|
function formatThirdMenu() {
|
...
|
...
|
@@ -91,7 +85,7 @@ function syncLoginInfo() { |
|
|
method: 'open.passport.get'
|
|
|
};
|
|
|
|
|
|
$.getJSON(apiDomain + '/?callback=?', param, function(jsonData) {
|
|
|
$.getJSON('http://www.yohobuy.com/common/passport/?callback=?', param, function(jsonData) {
|
|
|
if (jsonData && jsonData.data && jsonData.data.result !== -1) {
|
|
|
updateLoginInfo(jsonData.data.data);
|
|
|
} else {
|
...
|
...
|
@@ -110,7 +104,7 @@ function searchSuggest(key) { |
|
|
query: key
|
|
|
};
|
|
|
|
|
|
$.getJSON('http://search.yohobuy.com/api/suggest/?callback=?', param, function(jsonData) {
|
|
|
$.getJSON('http://search.yohobuy.com/api/suggest?callback=?', param, function(jsonData) {
|
|
|
if (jsonData.code === 200) {
|
|
|
if (jsonData.data && jsonData.data.length) {
|
|
|
$searchSug.html(jsonData.data).show();
|
...
|
...
|
@@ -123,72 +117,72 @@ function searchSuggest(key) { |
|
|
|
|
|
// 同步mini购物车数据
|
|
|
function syncCratInfo(strG) {
|
|
|
// var info, total;
|
|
|
//
|
|
|
// if (strG) {
|
|
|
// window.setCookie('_g', strG, {
|
|
|
// path: '/',
|
|
|
// domain: '.yohobuy.com'
|
|
|
// });
|
|
|
// }
|
|
|
// if (window.cookie('_g')) {
|
|
|
// info = json2.parse(window.cookie('_g'));
|
|
|
// total = parseInt(info._nac) + parseInt(info._ac);
|
|
|
// total = total > 0 ? total : 0;
|
|
|
// $goCart.data({
|
|
|
// key: info._k,
|
|
|
// num: total
|
|
|
// });
|
|
|
// $goodsNum.text(total);
|
|
|
// }
|
|
|
var info, total;
|
|
|
|
|
|
if (strG) {
|
|
|
window.setCookie('_g', strG, {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com'
|
|
|
});
|
|
|
}
|
|
|
if (window.cookie('_g')) {
|
|
|
info = $.parseJSON(window.cookie('_g'));
|
|
|
total = parseInt(info._nac, 10) + parseInt(info._ac, 10);
|
|
|
total = total > 0 ? total : 0;
|
|
|
$goCart.data({
|
|
|
key: info._k,
|
|
|
num: total
|
|
|
});
|
|
|
$goodsNum.text(total);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function loadCartDetail(key) {
|
|
|
// var param = {
|
|
|
// return_type: 'jsonp',
|
|
|
// method: 'open.Shoppingcart.getCartData',
|
|
|
// shopping_key: key
|
|
|
// };
|
|
|
//
|
|
|
// $.getJSON(apiDomain + '/?callback=?', param, function(jsonData) {
|
|
|
// var totalGoods, data;
|
|
|
//
|
|
|
// if (jsonData.code === 200) {
|
|
|
// data = jsonData.data;
|
|
|
// totalGoods = $.merge(data.main_goods, data.advance_goods);
|
|
|
// totalGoods = $.merge(totalGoods, data.outlet_goods);
|
|
|
// totalGoods = $.merge(totalGoods, data.gift_goods);
|
|
|
// totalGoods = $.merge(totalGoods, data.need_pay_gifts);
|
|
|
// if (totalGoods && totalGoods.length) {
|
|
|
// data.totalGoods = totalGoods;
|
|
|
// $miniCart.html(cartFn({
|
|
|
// carData: data
|
|
|
// }));
|
|
|
// } else {
|
|
|
// $miniCart.html('<div class="empty-cart"><h3>您的购物车暂无商品</h3></div>');
|
|
|
// }
|
|
|
// }
|
|
|
// });
|
|
|
var param = {
|
|
|
return_type: 'jsonp',
|
|
|
method: 'open.Shoppingcart.getCartData',
|
|
|
shopping_key: key
|
|
|
};
|
|
|
|
|
|
$.getJSON('http://www.yohobuy.com/common/shoppingCart/?callback=?', param, function(jsonData) {
|
|
|
var totalGoods, data;
|
|
|
|
|
|
if (jsonData.code === 200) {
|
|
|
data = jsonData.data;
|
|
|
totalGoods = $.merge(data.main_goods, data.advance_goods);
|
|
|
totalGoods = $.merge(totalGoods, data.outlet_goods);
|
|
|
totalGoods = $.merge(totalGoods, data.gift_goods);
|
|
|
totalGoods = $.merge(totalGoods, data.need_pay_gifts);
|
|
|
if (totalGoods && totalGoods.length) {
|
|
|
data.totalGoods = totalGoods;
|
|
|
$miniCart.html(cartFn({
|
|
|
carData: data
|
|
|
}));
|
|
|
} else {
|
|
|
$miniCart.html('<div class="empty-cart"><h3>您的购物车暂无商品</h3></div>');
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function delCartGoods(data, callback) {
|
|
|
// var param = {
|
|
|
// return_type: 'jsonp',
|
|
|
// method: 'open.Shoppingcart.delone',
|
|
|
// shopping_key: data.key,
|
|
|
// id: data.id,
|
|
|
// isreduce: data.isreduce
|
|
|
// };
|
|
|
//
|
|
|
// $.getJSON(apiDomain + '/?callback=?', param, function(jsonData) {
|
|
|
// var strG = '';
|
|
|
//
|
|
|
// if (jsonData.code === 200) {
|
|
|
// callback();
|
|
|
// strG = '{"_k":"' + data.key + '","_nac":' + jsonData.data.total_goods_num + ',"_ac":0,"_r":0}';
|
|
|
// syncCratInfo(strG);
|
|
|
// }
|
|
|
// });
|
|
|
var param = {
|
|
|
return_type: 'jsonp',
|
|
|
method: 'open.Shoppingcart.delone',
|
|
|
shopping_key: data.key,
|
|
|
id: data.id,
|
|
|
isreduce: data.isreduce
|
|
|
};
|
|
|
|
|
|
$.getJSON('http://www.yohobuy.com/common/shoppingCart/?callback=?', param, function(jsonData) {
|
|
|
var strG = '';
|
|
|
|
|
|
if (jsonData.code === 200) {
|
|
|
strG = '{"_k":"' + data.key + '","_nac":' + jsonData.data.total_goods_num + ',"_ac":0,"_r":0}';
|
|
|
syncCratInfo(strG);
|
|
|
return callback();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
syncLoginInfo();
|
...
|
...
|
@@ -240,9 +234,10 @@ $searchForm.on('keyup', '.search-key', function(e) { |
|
|
$(this).val(val);
|
|
|
searchSuggest(val);
|
|
|
}
|
|
|
|
|
|
// http://search.yohobuy.com/api/suggest
|
|
|
// searchSuggest
|
|
|
}).on('blur', '.search-key', function() {
|
|
|
setTimeout(function() {
|
|
|
$searchSug.hide();
|
|
|
}, 200);
|
|
|
});
|
|
|
|
|
|
$goCart.hover(function() {
|
...
|
...
|
@@ -265,7 +260,7 @@ $goCart.hover(function() { |
|
|
$goCart.removeClass('on-hover');
|
|
|
});
|
|
|
|
|
|
$goCart.on('click', '.cart-goods-del', function(e) {
|
|
|
$goCart.on('click', '.cart-goods-del', function() {
|
|
|
var $dom = $(this),
|
|
|
data = $dom.data(),
|
|
|
callback;
|
...
|
...
|
@@ -297,14 +292,14 @@ $subNav.on({ |
|
|
param.width = 174;
|
|
|
param.height = 155;
|
|
|
param._ = new Date();
|
|
|
// $.getJSON(apiBanner + '/?callback=?', param, function(JsonData) {
|
|
|
// if (JsonData.code === 200) {
|
|
|
// $show.addClass('show');
|
|
|
// $show.find('img').attr('src', JsonData.data.src);
|
|
|
// $show.find('a').attr('href', JsonData.data.url);
|
|
|
// $show.find('.title').text(JsonData.data.title);
|
|
|
// }
|
|
|
// });
|
|
|
$.getJSON('http://new.yohobuy.com/common/getbanner?callback=?', param, function(JsonData) {
|
|
|
if (JsonData.code === 200) {
|
|
|
$show.addClass('show');
|
|
|
$show.find('img').attr('src', JsonData.data.src);
|
|
|
$show.find('a').attr('href', JsonData.data.url);
|
|
|
$show.find('.title').text(JsonData.data.title);
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
mouseleave: function() {
|
|
|
var $thirdNav = $(this).children('.third-nav-wrapper');
|
...
|
...
|
@@ -315,6 +310,3 @@ $subNav.on({ |
|
|
$thirdNav.hide();
|
|
|
}
|
|
|
}); |
|
|
|
|
|
|
|
|
/* eslint-ensable */ |
...
|
...
|
|