|
|
1
|
+/**
|
|
|
2
|
+ * 商品详情
|
|
|
3
|
+ * @author: liangzhifeng<zhifeng.liang@yoho.cn>
|
|
|
4
|
+ * @date: 2015/10/20
|
|
|
5
|
+ */
|
|
|
6
|
+var $ = require('yoho-jquery'),
|
|
|
7
|
+ Swiper = require('yoho-swiper'),
|
|
|
8
|
+ Hammer = require('yoho-hammer'),
|
|
|
9
|
+ lazyLoad = require('yoho-jquery-lazyload');
|
|
|
10
|
+
|
|
|
11
|
+var $discountFolder = $('.goods-discount .discount-folder'),
|
|
|
12
|
+ $discountArrow = $('.goods-discount .first-item span');
|
|
|
13
|
+
|
|
|
14
|
+var goodsDiscountEl = document.getElementById('goodsDiscount'),
|
|
|
15
|
+ goodsDiscountHammer = goodsDiscountEl && new Hammer(goodsDiscountEl),
|
|
|
16
|
+ $discountFirstItem = $(goodsDiscountEl).find('.first-item');
|
|
|
17
|
+
|
|
|
18
|
+var $cart = $('.cart-bar');
|
|
|
19
|
+
|
|
|
20
|
+var appUrl = $('input[name="limitCodeUrl"]').val();
|
|
|
21
|
+
|
|
|
22
|
+var dialog = require('../plugin/dialog');
|
|
|
23
|
+
|
|
|
24
|
+require('../common');
|
|
|
25
|
+
|
|
|
26
|
+require('./tick');
|
|
|
27
|
+
|
|
|
28
|
+// add extra marign-bottom for footer to show the yoho copyright
|
|
|
29
|
+function showFooter() {
|
|
|
30
|
+ var $cartBar = $('.cart-bar');
|
|
|
31
|
+
|
|
|
32
|
+ var timer = setInterval(function() {
|
|
|
33
|
+ if ($cartBar) {
|
|
|
34
|
+ window.reMarginFooter('.cart-bar');
|
|
|
35
|
+ clearInterval(timer);
|
|
|
36
|
+ } else {
|
|
|
37
|
+ $cartBar = $('.cart-bar');
|
|
|
38
|
+ }
|
|
|
39
|
+ }, 200);
|
|
|
40
|
+}
|
|
|
41
|
+
|
|
|
42
|
+showFooter();
|
|
|
43
|
+
|
|
|
44
|
+lazyLoad($('img.lazy'));
|
|
|
45
|
+
|
|
|
46
|
+if ($('#goodsDiscount h1').length < 1) {
|
|
|
47
|
+ $('.dropdown').remove();
|
|
|
48
|
+}
|
|
|
49
|
+
|
|
|
50
|
+// 顶部swiper
|
|
|
51
|
+new Swiper('.banner-swiper', {
|
|
|
52
|
+ lazyLoading: true,
|
|
|
53
|
+ lazyLoadingInPrevNext: true,
|
|
|
54
|
+ paginationClickable: true,
|
|
|
55
|
+ pagination: '.banner-top .pagination-inner',
|
|
|
56
|
+ nextButton: '.my-swiper-button-next',
|
|
|
57
|
+ prevButton: '.my-swiper-button-prev',
|
|
|
58
|
+ spaceBetween: 3
|
|
|
59
|
+});
|
|
|
60
|
+
|
|
|
61
|
+// 初始化goods-discount
|
|
|
62
|
+if ($discountFolder.children().length === 0) {
|
|
|
63
|
+ $discountFolder.css('display', 'none');
|
|
|
64
|
+ $discountArrow.html('');
|
|
|
65
|
+}
|
|
|
66
|
+
|
|
|
67
|
+// goods-discount下拉按钮点击事件
|
|
|
68
|
+if (goodsDiscountHammer && $discountFolder.children().length > 0) {
|
|
|
69
|
+ goodsDiscountHammer.on('tap', function() {
|
|
|
70
|
+ if ($discountFolder.is(':hidden')) {
|
|
|
71
|
+ $discountFirstItem.removeClass('short-text');
|
|
|
72
|
+ $discountArrow.removeClass('icon-down').addClass('icon-up').html('');
|
|
|
73
|
+ $discountFolder.slideDown();
|
|
|
74
|
+ } else {
|
|
|
75
|
+ $discountFirstItem.addClass('short-text');
|
|
|
76
|
+ $discountArrow.removeClass('icon-up').addClass('icon-down').html('');
|
|
|
77
|
+ $discountFolder.slideUp();
|
|
|
78
|
+ }
|
|
|
79
|
+ });
|
|
|
80
|
+}
|
|
|
81
|
+
|
|
|
82
|
+$('#limit-sale').on('touchend', function(e) {
|
|
|
83
|
+ var loginUrl = $('#loginUrl').val(),
|
|
|
84
|
+ time,
|
|
|
85
|
+ ifr;
|
|
|
86
|
+
|
|
|
87
|
+ e.stopPropagation();
|
|
|
88
|
+
|
|
|
89
|
+ if (loginUrl) {
|
|
|
90
|
+ window.location = loginUrl;
|
|
|
91
|
+ } else {
|
|
|
92
|
+ dialog.showDialog({
|
|
|
93
|
+ dialogText: '进入有货APP,获取限购码',
|
|
|
94
|
+ hasFooter: {
|
|
|
95
|
+ rightBtnText: '打开Yoho!Buy有货APP'
|
|
|
96
|
+ }
|
|
|
97
|
+ }, function() {
|
|
|
98
|
+ ifr = document.createElement('iframe');
|
|
|
99
|
+ ifr.src = appUrl;
|
|
|
100
|
+ ifr.style.display = 'none';
|
|
|
101
|
+ document.body.appendChild(ifr);
|
|
|
102
|
+ window.location.href = appUrl;
|
|
|
103
|
+
|
|
|
104
|
+ time = Date.now();
|
|
|
105
|
+ window.setTimeout(function() {
|
|
|
106
|
+ document.body.removeChild(ifr);
|
|
|
107
|
+ if (Date.now() - time < 3200) {
|
|
|
108
|
+ window.location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho';
|
|
|
109
|
+ }
|
|
|
110
|
+ }, 3000);
|
|
|
111
|
+
|
|
|
112
|
+ }, null, true);
|
|
|
113
|
+
|
|
|
114
|
+ $('.dialog-wrapper').off('touchstart').on('touchstart', function(para) {
|
|
|
115
|
+ para.stopPropagation();
|
|
|
116
|
+ if ($(para.target).hasClass('dialog-wrapper')) {
|
|
|
117
|
+ dialog.hideDialog();
|
|
|
118
|
+ }
|
|
|
119
|
+ });
|
|
|
120
|
+ }
|
|
|
121
|
+});
|
|
|
122
|
+
|
|
|
123
|
+require('./detail/like');
|
|
|
124
|
+require('./detail/desc');
|
|
|
125
|
+require('./detail/comments-consults');
|
|
|
126
|
+require('./detail/consultform');
|
|
|
127
|
+require('./detail/recommend-for-you-product-desc');
|
|
|
128
|
+
|
|
|
129
|
+// 购物车商品数量
|
|
|
130
|
+$.ajax({
|
|
|
131
|
+ type: 'GET',
|
|
|
132
|
+ url: '/cart/index/count',
|
|
|
133
|
+ success: function(data) {
|
|
|
134
|
+ var count;
|
|
|
135
|
+
|
|
|
136
|
+ if (data.code === 200) {
|
|
|
137
|
+ count = data.data.cart_goods_count || 0;
|
|
|
138
|
+ if (count === 0) {
|
|
|
139
|
+ return false;
|
|
|
140
|
+ }
|
|
|
141
|
+ if (count > 99) {
|
|
|
142
|
+ count = '99+';
|
|
|
143
|
+ }
|
|
|
144
|
+ $cart.find('.num-tag').html(count).removeClass('hide');
|
|
|
145
|
+ }
|
|
|
146
|
+ }
|
|
|
147
|
+});
|
|
|
148
|
+
|
|
|
149
|
+if ($('.good-detail-page').length > 0) {
|
|
|
150
|
+ $('#yoho-footer').css('border-top', '1px solid #e0e0e0');
|
|
|
151
|
+} |