Showing
4 changed files
with
148 additions
and
12 deletions
web-static/js/footer.js
0 → 100644
1 | +/** | ||
2 | + * 尾部 | ||
3 | + * @author: wangqing<robin.wang@yoho.cn> | ||
4 | + * @date: 2015/12/01 | ||
5 | + */ | ||
6 | + | ||
7 | +var $ = require('yoho.jquery'); | ||
8 | +/** | ||
9 | + * 订阅 | ||
10 | + * @return {[type]} [description] | ||
11 | + */ | ||
12 | +function actionSubscription() { | ||
13 | + var $subscriberBox = $('#subscriberBox'), | ||
14 | + $subscriberBtn = $('#subscriberBtn'), | ||
15 | + emailReg = /^[.\-_a-zA-Z0-9]+@[\-_a-zA-Z0-9]+\.[a-zA-Z0-9]/; | ||
16 | + var subscribeParam = { | ||
17 | + method: 'open.subscriber.subscriber', | ||
18 | + v: 1, | ||
19 | + return_type: 'jsonp', | ||
20 | + open_key: '12345' | ||
21 | + }; | ||
22 | + var email = $.trim($subscriberBox.val()); | ||
23 | + var params = {}; | ||
24 | + $subscriberBox.focus(function() { | ||
25 | + $(this).val('').css('color', ''); | ||
26 | + $subscriberBtn.removeClass('done').text('m'); | ||
27 | + }); | ||
28 | + //订阅Start | ||
29 | + | ||
30 | + $subscriberBtn.click(function() { | ||
31 | + if (email !== '' && emailReg.test(email)) { | ||
32 | + $.extend(params, subscribeParam, { | ||
33 | + email: email, | ||
34 | + tmp: Math.random(), | ||
35 | + uid: $.uid('_UID') | ||
36 | + }); | ||
37 | + try { | ||
38 | + $.getJSON('http://test.open.yohobuy.com' + '/?callback=?', params, function(data) { | ||
39 | + if (data.data.result === 1) { | ||
40 | + $subscriberBox.val('已订阅到:' + email); | ||
41 | + $subscriberBtn.addClass('done').text('='); | ||
42 | + } else { | ||
43 | + $subscriberBox.css('color', 'red'); | ||
44 | + } | ||
45 | + }); | ||
46 | + } catch (e) { | ||
47 | + console.log(e.message); | ||
48 | + } | ||
49 | + } else { | ||
50 | + $subscriberBox.css('color', 'red'); | ||
51 | + } | ||
52 | + }); | ||
53 | +} | ||
54 | + | ||
55 | +function change(now, icon, box) { | ||
56 | + var obj = now; | ||
57 | + var index = icon.index(this); | ||
58 | + var offset = index * 3; | ||
59 | + box.each(function() { | ||
60 | + $(this).hide(); | ||
61 | + }); | ||
62 | + for (var i = offset; i < offset + 3; i++) { | ||
63 | + box.eq(i).show(); | ||
64 | + } | ||
65 | + now.each(function() { | ||
66 | + $(this).children().removeClass('cur').html('o'); | ||
67 | + }); | ||
68 | + obj.children().addClass('cur').html('O'); | ||
69 | +} | ||
70 | + | ||
71 | +function actionhomeFootChange() { | ||
72 | + | ||
73 | + | ||
74 | + //有货services | ||
75 | + $('#button-services a').click(function() { | ||
76 | + change($(this), $('#button-services a'), $('#foot-services ul li')); | ||
77 | + }); | ||
78 | + | ||
79 | + //更多有货产品 | ||
80 | + $('#button-mobile a').click(function() { | ||
81 | + change($(this), $('#button-mobile a'), $('#foot-mobile ul li')); | ||
82 | + }); | ||
83 | + | ||
84 | + //在线调查 | ||
85 | + $('#feedbackPage a').click(function() { | ||
86 | + $('#feedbackPage').find('a').children('span').removeClass('cur').html('o'); | ||
87 | + $(this).children('span').addClass('cur').html('O'); | ||
88 | + var indexNum = $('#feedbackPage a').index(this); | ||
89 | + $('.vote li').hide(); | ||
90 | + $('.vote li').eq(indexNum).show(); | ||
91 | + }); | ||
92 | + | ||
93 | + $('.vote li').each(function() { | ||
94 | + var obj = this; | ||
95 | + var index = $(this).index(); | ||
96 | + $(this).find('#feedbackBtn').click(function() { | ||
97 | + var params = {}; | ||
98 | + var _solution = []; | ||
99 | + $(obj).find('input').each(function() { | ||
100 | + if ($(this).attr('checked') == true || $(this).attr('checked') == 'checked') { | ||
101 | + _solution.push($(this).val()); | ||
102 | + } | ||
103 | + }); | ||
104 | + var _answer = $(obj).find('#feedback_answer').val(); | ||
105 | + var _feedback = $(obj).find('#feedback_id').val(); | ||
106 | + var _question = $(obj).find('#question_id').val(); | ||
107 | + | ||
108 | + params['method'] = 'open.feedback.submit'; | ||
109 | + params['feedback_id'] = _feedback || 0; | ||
110 | + params['question_id'] = _question || 0; | ||
111 | + params['answer'] = _answer || ''; | ||
112 | + params['solution'] = _solution.join(','); | ||
113 | + $.getData(apiDomain, params, function(reData) { | ||
114 | + if (reData.result == 1) { | ||
115 | + var voteCount = $('.vote li').length - 1; | ||
116 | + if (index == voteCount) { | ||
117 | + alert('感谢您的参与!'); | ||
118 | + return false; | ||
119 | + } | ||
120 | + var Next = index + 1; | ||
121 | + $('.vote li').eq(index).hide(); | ||
122 | + $('.vote li').eq(Next).show(); | ||
123 | + $('#feedbackPage').children('a').eq(index).children('span').removeClass('cur').html('o'); | ||
124 | + $('#feedbackPage').children('a').eq(Next).children('span').addClass('cur').html('O'); | ||
125 | + } | ||
126 | + return false; | ||
127 | + }); | ||
128 | + }); | ||
129 | + }); | ||
130 | +} | ||
131 | + | ||
132 | +exports.init = function() { | ||
133 | + actionSubscription();//执行订阅 | ||
134 | + actionhomeFootChange();//底部事件 | ||
135 | +} |
@@ -6,11 +6,12 @@ | @@ -6,11 +6,12 @@ | ||
6 | 6 | ||
7 | 7 | ||
8 | var $ = require('yoho.jquery'); | 8 | var $ = require('yoho.jquery'); |
9 | -var $yohocookie = require('../plugin/yohocookie'); | ||
10 | -var $yohocart = require('../plugin/yohocart'); | ||
11 | var yohodoT = require('../plugin/yohodoT'); | 9 | var yohodoT = require('../plugin/yohodoT'); |
12 | 10 | ||
13 | var noticeSuccess = false; | 11 | var noticeSuccess = false; |
12 | + | ||
13 | +require('../plugin/yohocookie'); | ||
14 | +require('../plugin/yohocart'); | ||
14 | /** | 15 | /** |
15 | * 获取头部banner的回调函数 | 16 | * 获取头部banner的回调函数 |
16 | * @param {[type]} data [description] | 17 | * @param {[type]} data [description] |
@@ -560,7 +561,7 @@ function loadCartData() { | @@ -560,7 +561,7 @@ function loadCartData() { | ||
560 | } | 561 | } |
561 | if ($('#miniCartBox .goods-list li').length < 1) { | 562 | if ($('#miniCartBox .goods-list li').length < 1) { |
562 | shoppingInfo = $.cookie('_g'); | 563 | shoppingInfo = $.cookie('_g'); |
563 | - shoppingData = JSON.parse('(' + shoppingInfo + ')'); | 564 | + shoppingData = eval('(' + shoppingInfo + ')'); |
564 | if (shoppingData !== null) { | 565 | if (shoppingData !== null) { |
565 | strK = '{"_k":"' + shoppingData._k + '","_nac":0' + ',"_ac":0,"_r":0}'; | 566 | strK = '{"_k":"' + shoppingData._k + '","_nac":0' + ',"_ac":0,"_r":0}'; |
566 | $.setcookie('_g', strK, { | 567 | $.setcookie('_g', strK, { |
@@ -588,7 +589,7 @@ function delCartGoods(id, isreduce) { | @@ -588,7 +589,7 @@ function delCartGoods(id, isreduce) { | ||
588 | isreduce: isreduce | 589 | isreduce: isreduce |
589 | }, function(jsonData) { | 590 | }, function(jsonData) { |
590 | var shoppingInfo = $.cookie('_g'); | 591 | var shoppingInfo = $.cookie('_g'); |
591 | - var shoppingData = JSON.parse('(' + shoppingInfo + ')'); | 592 | + var shoppingData = eval('(' + shoppingInfo + ')'); |
592 | var strK = '{"_k":"' + shoppingData._k + '","_nac":' + jsonData.total_goods_num + ',"_ac":0,"_r":0}'; | 593 | var strK = '{"_k":"' + shoppingData._k + '","_nac":' + jsonData.total_goods_num + ',"_ac":0,"_r":0}'; |
593 | 594 | ||
594 | $.setcookie('_g', strK, { | 595 | $.setcookie('_g', strK, { |
@@ -601,13 +602,13 @@ function delCartGoods(id, isreduce) { | @@ -601,13 +602,13 @@ function delCartGoods(id, isreduce) { | ||
601 | } | 602 | } |
602 | window.apiDomain = 'http://api.open.yohobuy.com'; | 603 | window.apiDomain = 'http://api.open.yohobuy.com'; |
603 | window.cartTpl = ''; | 604 | window.cartTpl = ''; |
604 | - | 605 | +window.delCartGoods = delCartGoods; |
605 | 606 | ||
606 | /** | 607 | /** |
607 | * 点击购物车 | 608 | * 点击购物车 |
608 | * @return {[type]} [description] | 609 | * @return {[type]} [description] |
609 | */ | 610 | */ |
610 | -function clickMiniCartBox() { | 611 | +function actionClickMiniCartBox() { |
611 | var $target; | 612 | var $target; |
612 | var shopcarurl = 'http://www.yohobuy.com/shopping/cart'; | 613 | var shopcarurl = 'http://www.yohobuy.com/shopping/cart'; |
613 | 614 | ||
@@ -803,8 +804,5 @@ exports.init = function() { | @@ -803,8 +804,5 @@ exports.init = function() { | ||
803 | actionUpdateCartNum(); //更新购物车数量 | 804 | actionUpdateCartNum(); //更新购物车数量 |
804 | actionLoopUpdCartNum(); //循环检测购物车数量 | 805 | actionLoopUpdCartNum(); //循环检测购物车数量 |
805 | actionSearch(); //搜索执行 | 806 | actionSearch(); //搜索执行 |
806 | - delCartGoods(); | ||
807 | - clickMiniCartBox(); | ||
808 | - $yohocookie(); | ||
809 | - $yohocart(); | 807 | + actionClickMiniCartBox(); //点击购物车跳转 |
810 | }; | 808 | }; |
1 | 1 | ||
2 | -var jQuery = require('jquery'); | 2 | +var jQuery = require('yoho.jquery'); |
3 | var $yohocookie = require('./yohocookie'); | 3 | var $yohocookie = require('./yohocookie'); |
4 | 4 | ||
5 | (function($) { | 5 | (function($) { |
@@ -127,3 +127,6 @@ var $yohocookie = require('./yohocookie'); | @@ -127,3 +127,6 @@ var $yohocookie = require('./yohocookie'); | ||
127 | }, | 127 | }, |
128 | }) | 128 | }) |
129 | })(jQuery); | 129 | })(jQuery); |
130 | +exports.init = function() { | ||
131 | + | ||
132 | +} |
-
Please register or login to post a comment