|
@@ -5,10 +5,14 @@ |
|
@@ -5,10 +5,14 @@ |
5
|
*/
|
5
|
*/
|
6
|
|
6
|
|
7
|
var $ = require('jquery');
|
7
|
var $ = require('jquery');
|
8
|
-
|
|
|
9
|
-
|
8
|
+var $yohocookie = require('./common/yohocookie');
|
|
|
9
|
+var $yohocart = require('./common/yohocart');
|
|
|
10
|
+var yohodoT = require('../plugin/yohodoT');
|
10
|
var noticeSuccess = false;
|
11
|
var noticeSuccess = false;
|
11
|
-
|
12
|
+/**
|
|
|
13
|
+ * 获取头部banner的回调函数
|
|
|
14
|
+ * @param {[type]} data [description]
|
|
|
15
|
+ */
|
12
|
function JsonPCallBack(data) {
|
16
|
function JsonPCallBack(data) {
|
13
|
var topbanner;
|
17
|
var topbanner;
|
14
|
|
18
|
|
|
@@ -22,6 +26,10 @@ function JsonPCallBack(data) { |
|
@@ -22,6 +26,10 @@ function JsonPCallBack(data) { |
22
|
}
|
26
|
}
|
23
|
}
|
27
|
}
|
24
|
|
28
|
|
|
|
29
|
+/**
|
|
|
30
|
+ * 获取头部服务器维护的回调
|
|
|
31
|
+ * @param {[type]} data [description]
|
|
|
32
|
+ */
|
25
|
function NoticeCallBack(data) {
|
33
|
function NoticeCallBack(data) {
|
26
|
if (+data.code === 200) {
|
34
|
if (+data.code === 200) {
|
27
|
noticeSuccess = true;
|
35
|
noticeSuccess = true;
|
|
@@ -375,6 +383,62 @@ window.bannerMap = { |
|
@@ -375,6 +383,62 @@ window.bannerMap = { |
375
|
indexkids: '17f6d5d5d454d2c507bc5fcbc90f7756',
|
383
|
indexkids: '17f6d5d5d454d2c507bc5fcbc90f7756',
|
376
|
indexlifestyle: '735cd393e841762af8793c346abbbc36'
|
384
|
indexlifestyle: '735cd393e841762af8793c346abbbc36'
|
377
|
};
|
385
|
};
|
|
|
386
|
+
|
|
|
387
|
+/**
|
|
|
388
|
+ * cookie 初始化
|
|
|
389
|
+ * @return {[type]} [description]
|
|
|
390
|
+ */
|
|
|
391
|
+function actionInitCookie() {
|
|
|
392
|
+ var $cookieGender = $.cookie('_Gender');
|
|
|
393
|
+ var $target = $('.cure');
|
|
|
394
|
+
|
|
|
395
|
+ if (typeof $cookieGender !== 'undefined' && $cookieGender !== '') {
|
|
|
396
|
+ $.setcookie('_Gender', 1, {
|
|
|
397
|
+ path: '/',
|
|
|
398
|
+ domain: '.yohobuy.com',
|
|
|
399
|
+ expires: 7
|
|
|
400
|
+ });
|
|
|
401
|
+ }
|
|
|
402
|
+ if ($target.find('.name-cn a').text() === '男生') {
|
|
|
403
|
+ $.setcookie('_Gender', '1,3', {
|
|
|
404
|
+ path: '/',
|
|
|
405
|
+ domain: '.yohobuy.com',
|
|
|
406
|
+ expires: 7
|
|
|
407
|
+ });
|
|
|
408
|
+ $.setcookie('_Channel', 'boys', {
|
|
|
409
|
+ path: '/',
|
|
|
410
|
+ domain: '.yohobuy.com',
|
|
|
411
|
+ expires: 7
|
|
|
412
|
+ });
|
|
|
413
|
+ }
|
|
|
414
|
+ if ($target.find('.name-cn a').text() === '女生') {
|
|
|
415
|
+ $.setcookie('_Gender', '2,3', {
|
|
|
416
|
+ path: '/',
|
|
|
417
|
+ domain: '.yohobuy.com',
|
|
|
418
|
+ expires: 7
|
|
|
419
|
+ });
|
|
|
420
|
+ $.setcookie('_Channel', 'girls', {
|
|
|
421
|
+ path: '/',
|
|
|
422
|
+ domain: '.yohobuy.com',
|
|
|
423
|
+ expires: 7
|
|
|
424
|
+ });
|
|
|
425
|
+ }
|
|
|
426
|
+ if ($target.find('.name-cn a').text() === '创意生活') {
|
|
|
427
|
+ $.setcookie('_Channel', 'lifestyle', {
|
|
|
428
|
+ path: '/',
|
|
|
429
|
+ domain: '.yohobuy.com',
|
|
|
430
|
+ expires: 7
|
|
|
431
|
+ });
|
|
|
432
|
+ }
|
|
|
433
|
+ if ($target.find('.name-cn a').text() === '潮童') {
|
|
|
434
|
+ $.setcookie('_Channel', 'kids', {
|
|
|
435
|
+ path: '/',
|
|
|
436
|
+ domain: '.yohobuy.com',
|
|
|
437
|
+ expires: 7
|
|
|
438
|
+ });
|
|
|
439
|
+ }
|
|
|
440
|
+}
|
|
|
441
|
+
|
378
|
/**
|
442
|
/**
|
379
|
* cookie集合
|
443
|
* cookie集合
|
380
|
* @type {Object}
|
444
|
* @type {Object}
|
|
@@ -394,9 +458,207 @@ function actionExeCookieMap() { |
|
@@ -394,9 +458,207 @@ function actionExeCookieMap() { |
394
|
window.cookieMap[key] = temparr[1];
|
458
|
window.cookieMap[key] = temparr[1];
|
395
|
}
|
459
|
}
|
396
|
}
|
460
|
}
|
|
|
461
|
+/**
|
|
|
462
|
+ * 一级菜单点击(会设置cookie)
|
|
|
463
|
+ * @return {[type]} [description]
|
|
|
464
|
+ */
|
|
|
465
|
+function actionFirstMenuClick() {
|
|
|
466
|
+ var $cookieGender;
|
|
|
467
|
+
|
|
|
468
|
+ $('.first-nav-item').click(function() {
|
|
|
469
|
+ $cookieGender = $.cookie('_Gender');
|
|
|
470
|
+ if (typeof $cookieGender !== 'undefined' && $cookieGender !== '') {
|
|
|
471
|
+ $.setcookie('_Gender', 1, {
|
|
|
472
|
+ path: '/',
|
|
|
473
|
+ domain: '.yohobuy.com',
|
|
|
474
|
+ expires: 7
|
|
|
475
|
+ });
|
|
|
476
|
+ }
|
|
|
477
|
+ if ($(this).find('.name-cn a').text() === '男生') {
|
|
|
478
|
+ $.setcookie('_Gender', '1,3', {
|
|
|
479
|
+ path: '/',
|
|
|
480
|
+ domain: '.yohobuy.com',
|
|
|
481
|
+ expires: 7
|
|
|
482
|
+ });
|
|
|
483
|
+ $.setcookie('_Channel', 'boys', {
|
|
|
484
|
+ path: '/',
|
|
|
485
|
+ domain: '.yohobuy.com',
|
|
|
486
|
+ expires: 7
|
|
|
487
|
+ });
|
|
|
488
|
+ }
|
|
|
489
|
+ if ($(this).find('.name-cn a').text() === '女生') {
|
|
|
490
|
+ $.setcookie('_Gender', '2,3', {
|
|
|
491
|
+ path: '/',
|
|
|
492
|
+ domain: '.yohobuy.com',
|
|
|
493
|
+ expires: 7
|
|
|
494
|
+ });
|
|
|
495
|
+ $.setcookie('_Channel', 'girls', {
|
|
|
496
|
+ path: '/',
|
|
|
497
|
+ domain: '.yohobuy.com',
|
|
|
498
|
+ expires: 7
|
|
|
499
|
+ });
|
|
|
500
|
+ }
|
|
|
501
|
+ if ($(this).find('.name-cn a').text() === '创意生活') {
|
|
|
502
|
+ $.setcookie('_Channel', 'lifestyle', {
|
|
|
503
|
+ path: '/',
|
|
|
504
|
+ domain: '.yohobuy.com',
|
|
|
505
|
+ expires: 7
|
|
|
506
|
+ });
|
|
|
507
|
+ }
|
|
|
508
|
+ if ($(this).find('.name-cn a').text() === '潮童') {
|
|
|
509
|
+ $.setcookie('_Channel', 'kids', {
|
|
|
510
|
+ path: '/',
|
|
|
511
|
+ domain: '.yohobuy.com',
|
|
|
512
|
+ expires: 7
|
|
|
513
|
+ });
|
|
|
514
|
+ }
|
|
|
515
|
+ });
|
|
|
516
|
+
|
|
|
517
|
+ $('#backToOld').click(function() {
|
|
|
518
|
+ $.setcookie('_New', 1, {
|
|
|
519
|
+ path: '/',
|
|
|
520
|
+ domain: '.yohobuy.com'
|
|
|
521
|
+ });
|
|
|
522
|
+ location.href = 'http://www.yohobuy.com';
|
|
|
523
|
+ });
|
|
|
524
|
+}
|
397
|
|
525
|
|
398
|
|
526
|
|
399
|
/**
|
527
|
/**
|
|
|
528
|
+ * 购物车商品数量
|
|
|
529
|
+ * @return {[type]} [description]
|
|
|
530
|
+ */
|
|
|
531
|
+function actionUpdateCartNum() {
|
|
|
532
|
+ $('#miniCartBox').miniCart({
|
|
|
533
|
+ cartNum: '.ic-infomation'
|
|
|
534
|
+ });
|
|
|
535
|
+}
|
|
|
536
|
+/**
|
|
|
537
|
+ * 加载购物车数据
|
|
|
538
|
+ * @return {[type]} [description]
|
|
|
539
|
+ */
|
|
|
540
|
+function loadCartData() {
|
|
|
541
|
+ var shoppingInfo,
|
|
|
542
|
+ shoppingData,
|
|
|
543
|
+ strK;
|
|
|
544
|
+
|
|
|
545
|
+ $.getData(window.apiDomain, {
|
|
|
546
|
+ method: 'open.Shoppingcart.getCartData',
|
|
|
547
|
+ shopping_key: $.getShoppingKey()
|
|
|
548
|
+ }, function(jsonData) {
|
|
|
549
|
+ if (window.cartTpl === '') {
|
|
|
550
|
+ window.cartTpl = yohodoT.template($('#mini-cart-tpl').html());
|
|
|
551
|
+ }
|
|
|
552
|
+ $('#miniCartBox').children('.gobuy-wrapper').html(window.cartTpl({
|
|
|
553
|
+ cartData: jsonData
|
|
|
554
|
+ }));
|
|
|
555
|
+ if (parseInt($('.ic-infomation').html()) === 0) {
|
|
|
556
|
+ $('#miniCartBox .gobuy-wrapper').html('<div class="gobuy-empty">' +
|
|
|
557
|
+ '<h3 class="information">您的购物车暂无商品</h3></div>');
|
|
|
558
|
+ }
|
|
|
559
|
+ if ($('#miniCartBox .goods-list li').length < 1) {
|
|
|
560
|
+ shoppingInfo = $.cookie('_g');
|
|
|
561
|
+ shoppingData = eval('(' + shoppingInfo + ')');
|
|
|
562
|
+ if (shoppingData !== null) {
|
|
|
563
|
+ strK = '{"_k":"' + shoppingData._k + '","_nac":0' + ',"_ac":0,"_r":0}';
|
|
|
564
|
+ $.setcookie('_g', strK, {
|
|
|
565
|
+ path: '/',
|
|
|
566
|
+ domain: '.yohobuy.com'
|
|
|
567
|
+ });
|
|
|
568
|
+ }
|
|
|
569
|
+ $('.ic-infomation').html(0);
|
|
|
570
|
+ $('#miniCartBox .gobuy-wrapper').html('<div class="gobuy-empty">' +
|
|
|
571
|
+ '<h3 class="information">您的购物车暂无商品</h3></div>');
|
|
|
572
|
+ }
|
|
|
573
|
+ });
|
|
|
574
|
+}
|
|
|
575
|
+/**
|
|
|
576
|
+ * 删除购物车数据
|
|
|
577
|
+ * @param {[type]} id [description]
|
|
|
578
|
+ * @param {Boolean} isreduce [description]
|
|
|
579
|
+ * @return {[type]} [description]
|
|
|
580
|
+ */
|
|
|
581
|
+function delCartGoods(id, isreduce) {
|
|
|
582
|
+ $.getData(window.apiDomain, {
|
|
|
583
|
+ method: 'open.Shoppingcart.delone',
|
|
|
584
|
+ shopping_key: $.getShoppingKey(),
|
|
|
585
|
+ id: id,
|
|
|
586
|
+ isreduce: isreduce
|
|
|
587
|
+ }, function(jsonData) {
|
|
|
588
|
+ var shoppingInfo = $.cookie('_g');
|
|
|
589
|
+ var shoppingData = eval('(' + shoppingInfo + ')');
|
|
|
590
|
+ var strK = '{"_k":"' + shoppingData._k + '","_nac":' + jsonData.total_goods_num + ',"_ac":0,"_r":0}';
|
|
|
591
|
+
|
|
|
592
|
+ $.setcookie('_g', strK, {
|
|
|
593
|
+ path: '/',
|
|
|
594
|
+ domain: '.yohobuy.com'
|
|
|
595
|
+ });
|
|
|
596
|
+ loadCartData();
|
|
|
597
|
+ actionUpdateCartNum();
|
|
|
598
|
+ });
|
|
|
599
|
+}
|
|
|
600
|
+window.apiDomain = 'http://api.open.yohobuy.com';
|
|
|
601
|
+window.cartTpl = '';
|
|
|
602
|
+
|
|
|
603
|
+
|
|
|
604
|
+/**
|
|
|
605
|
+ * 点击购物车
|
|
|
606
|
+ * @return {[type]} [description]
|
|
|
607
|
+ */
|
|
|
608
|
+function clickMiniCartBox() {
|
|
|
609
|
+ var $target;
|
|
|
610
|
+ var shopcarurl = 'http://www.yohobuy.com/shopping/cart';
|
|
|
611
|
+
|
|
|
612
|
+ $('#miniCartBox').on('click', function(e) {
|
|
|
613
|
+ $target = $(e.target);
|
|
|
614
|
+ if ($target.hasClass('gobuy')) {
|
|
|
615
|
+ window.location.href = shopcarurl;
|
|
|
616
|
+ }
|
|
|
617
|
+ });
|
|
|
618
|
+}
|
|
|
619
|
+
|
|
|
620
|
+/**
|
|
|
621
|
+ * 显示购物车效果
|
|
|
622
|
+ * @param {Boolean} isShow [description]
|
|
|
623
|
+ * @return {[type]} [description]
|
|
|
624
|
+ */
|
|
|
625
|
+function showMiniCart(isShow) {
|
|
|
626
|
+ if (isShow === 1) {
|
|
|
627
|
+ $('#miniCartBox').addClass('list-cur');
|
|
|
628
|
+ $('.gobuy-wrapper').show();
|
|
|
629
|
+ if (parseInt($('.ic-infomation').html()) !== 0) {
|
|
|
630
|
+ $('#miniCartBox .gobuy-wrapper').html('<div class="gobuy-loading">' +
|
|
|
631
|
+ '<h3 class="information">加载中,请稍后</h3></div>');
|
|
|
632
|
+ loadCartData();
|
|
|
633
|
+ } else {
|
|
|
634
|
+ $('#miniCartBox .gobuy-wrapper').html('<div class="gobuy-empty">' +
|
|
|
635
|
+ '<h3 class="information">您的购物车暂无商品</h3></div>');
|
|
|
636
|
+ }
|
|
|
637
|
+ } else {
|
|
|
638
|
+ $('#miniCartBox').removeClass('list-cur');
|
|
|
639
|
+ $('.gobuy-wrapper').hide();
|
|
|
640
|
+ }
|
|
|
641
|
+}
|
|
|
642
|
+
|
|
|
643
|
+
|
|
|
644
|
+/**
|
|
|
645
|
+ * 鼠标购物车的滑入滑出效果
|
|
|
646
|
+ * @return {[type]} [description]
|
|
|
647
|
+ */
|
|
|
648
|
+function actionGoodsCarMouseEffect() {
|
|
|
649
|
+ var $target;
|
|
|
650
|
+
|
|
|
651
|
+ $('#miniCartBox').mouseenter(function(e) {
|
|
|
652
|
+ $target = $(e.target);
|
|
|
653
|
+ if ($target.attr('id') === 'miniCartBox' || $target.attr('class') === 'ic-infomation') {
|
|
|
654
|
+ showMiniCart(1);
|
|
|
655
|
+ }
|
|
|
656
|
+ });
|
|
|
657
|
+ $('#miniCartBox').mouseleave(function(e) {
|
|
|
658
|
+ showMiniCart(0);
|
|
|
659
|
+ });
|
|
|
660
|
+}
|
|
|
661
|
+/**
|
400
|
* 获得banner & 异常通知
|
662
|
* 获得banner & 异常通知
|
401
|
* @return {[type]} [description]
|
663
|
* @return {[type]} [description]
|
402
|
*/
|
664
|
*/
|
|
@@ -496,15 +758,47 @@ function actionBrandChange() { |
|
@@ -496,15 +758,47 @@ function actionBrandChange() { |
496
|
}
|
758
|
}
|
497
|
}
|
759
|
}
|
498
|
/**
|
760
|
/**
|
|
|
761
|
+ * 循环检测购物车数量
|
|
|
762
|
+ * @return {[type]} [description]
|
|
|
763
|
+ */
|
|
|
764
|
+function actionLoopUpdCartNum() {
|
|
|
765
|
+ setInterval(actionUpdateCartNum, 2000);
|
|
|
766
|
+}
|
|
|
767
|
+/**
|
|
|
768
|
+ * 处理模板
|
|
|
769
|
+ * @return {[type]} [description]
|
|
|
770
|
+ */
|
|
|
771
|
+function actionExeTemplate() {
|
|
|
772
|
+ var resulthtml = $('#goodcartempwarpper').html().replace(/\%L/g, '{{').replace(/\%R/g, '}}');
|
|
|
773
|
+
|
|
|
774
|
+ $('#goodcartempwarpper').html(resulthtml);
|
|
|
775
|
+}
|
|
|
776
|
+/**
|
|
|
777
|
+ * 执行搜索
|
|
|
778
|
+ * @return {[type]} [description]
|
|
|
779
|
+ */
|
|
|
780
|
+function actionSearch() {
|
|
|
781
|
+ var searchDomain = 'http://search.yohobuy.com/api/suggest';
|
|
|
782
|
+
|
|
|
783
|
+ $('#query_key').search(searchDomain);
|
|
|
784
|
+}
|
|
|
785
|
+/**
|
499
|
* 初始化函数
|
786
|
* 初始化函数
|
500
|
* @return {[type]} [description]
|
787
|
* @return {[type]} [description]
|
501
|
*/
|
788
|
*/
|
502
|
exports.init = function() {
|
789
|
exports.init = function() {
|
503
|
- actionExeCookieMap();
|
|
|
504
|
- actionYoHoGroup();
|
|
|
505
|
- actionTopTagToggle();
|
|
|
506
|
- actionTopLogoAnimate();
|
|
|
507
|
- actionGetBannerAndNotice();
|
|
|
508
|
- actionBrandChange();
|
|
|
509
|
- actionAddKeyWords();
|
790
|
+ actionExeTemplate(); //处理模板
|
|
|
791
|
+ actionInitCookie(); //初始化cookie
|
|
|
792
|
+ actionExeCookieMap(); //格式化cookie
|
|
|
793
|
+ actionYoHoGroup(); // yoho集团鼠标效果
|
|
|
794
|
+ actionTopTagToggle(); // yoho上部分开关
|
|
|
795
|
+ actionTopLogoAnimate(); //yoho logo动画
|
|
|
796
|
+ actionGetBannerAndNotice(); // 获取banner和服务器维护提示
|
|
|
797
|
+ actionBrandChange(); //切换品牌
|
|
|
798
|
+ actionAddKeyWords(); //跳转后增加关键字
|
|
|
799
|
+ actionFirstMenuClick(); //一级菜单点击(会设置cookie)
|
|
|
800
|
+ actionGoodsCarMouseEffect(); //鼠标滑入滑出效果
|
|
|
801
|
+ actionUpdateCartNum(); //更新购物车数量
|
|
|
802
|
+ actionLoopUpdCartNum(); //循环检测购物车数量
|
|
|
803
|
+ actionSearch(); //搜索执行
|
510
|
}; |
804
|
}; |