Showing
17 changed files
with
1487 additions
and
18 deletions
@@ -11,14 +11,14 @@ var express = require('express'), | @@ -11,14 +11,14 @@ var express = require('express'), | ||
11 | var app = express(); | 11 | var app = express(); |
12 | 12 | ||
13 | // set view engin | 13 | // set view engin |
14 | -var doraemon = path.join(__dirname, '../../doraemon/views'); //parent view root | 14 | +var doraemon = path.join(__dirname, '../../doraemon/views'); // parent view root |
15 | 15 | ||
16 | app.set('views', path.join(__dirname, 'views/action')); | 16 | app.set('views', path.join(__dirname, 'views/action')); |
17 | app.engine('.hbs', hbs({ | 17 | app.engine('.hbs', hbs({ |
18 | extname: '.hbs', | 18 | extname: '.hbs', |
19 | defaultLayout: 'layout', | 19 | defaultLayout: 'layout', |
20 | layoutsDir: doraemon, | 20 | layoutsDir: doraemon, |
21 | - partialsDir: ['./views/partial', `${doraemon}/partial`], | 21 | + partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`], |
22 | helpers: 'helpers' | 22 | helpers: 'helpers' |
23 | })); | 23 | })); |
24 | 24 |
@@ -23,27 +23,27 @@ hello, I am product hbs | @@ -23,27 +23,27 @@ hello, I am product hbs | ||
23 | <p class="good-tag limit-tag">限量商品</p> | 23 | <p class="good-tag limit-tag">限量商品</p> |
24 | {{/ is_limited}} | 24 | {{/ is_limited}} |
25 | {{# is_soon_sold_out}} | 25 | {{# is_soon_sold_out}} |
26 | - <p class="good-tag soonSoldOut-tag">即将售罄</p> | 26 | + <p class="good-tag soon-sold-out-tag">即将售罄</p> |
27 | {{/ is_soon_sold_out}} | 27 | {{/ is_soon_sold_out}} |
28 | {{/ tags}} | 28 | {{/ tags}} |
29 | </div> | 29 | </div> |
30 | {{# bannerTop}} | 30 | {{# bannerTop}} |
31 | - {{!> product/banner-swiper-arrow}} | 31 | + {{> product/banner-swiper-arrow}} |
32 | {{/ bannerTop}} | 32 | {{/ bannerTop}} |
33 | </div> | 33 | </div> |
34 | {{# goodsName}} | 34 | {{# goodsName}} |
35 | - <h2 class="goodsName"><span>{{.}}</span></h2> | 35 | + <h2 class="goods-name"><span>{{.}}</span></h2> |
36 | {{/ goodsName}} | 36 | {{/ goodsName}} |
37 | 37 | ||
38 | {{# goodsSubtitle}} | 38 | {{# goodsSubtitle}} |
39 | - <h1 class="goodsSubtitle"><span>{{.}}</span></h1> | 39 | + <h1 class="goods-subtitle"><span>{{.}}</span></h1> |
40 | {{/ goodsSubtitle}} | 40 | {{/ goodsSubtitle}} |
41 | 41 | ||
42 | <div class="price-date"> | 42 | <div class="price-date"> |
43 | {{# goodsPrice}} | 43 | {{# goodsPrice}} |
44 | <div class="goodsPrice"> | 44 | <div class="goodsPrice"> |
45 | - <h1 class="currentPrice">{{currentPrice}}</h1> | ||
46 | - <h1 class="previousPrice">{{previousPrice}}</h1> | 45 | + <h1 class="current-price">{{currentPrice}}</h1> |
46 | + <h1 class="previous-price">{{previousPrice}}</h1> | ||
47 | </div> | 47 | </div> |
48 | {{/ goodsPrice}} | 48 | {{/ goodsPrice}} |
49 | 49 | ||
@@ -131,8 +131,8 @@ hello, I am product hbs | @@ -131,8 +131,8 @@ hello, I am product hbs | ||
131 | {{/ enterStore}} | 131 | {{/ enterStore}} |
132 | 132 | ||
133 | <div id="productDesc"> </div> | 133 | <div id="productDesc"> </div> |
134 | - {{!> product/recommend-for-you}} | ||
135 | - {{!> cart/chose-panel}} | 134 | + {{> product/recommend-for-you}} |
135 | + {{> cart/chose-panel}} | ||
136 | 136 | ||
137 | {{#cartInfo}} | 137 | {{#cartInfo}} |
138 | <div class="cart-bar"> | 138 | <div class="cart-bar"> |
apps/product/views/partials/cart/chose-panel.phtml
→
apps/product/views/partial/cart/chose-panel.hbs
@@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
4 | <div class="infos"> | 4 | <div class="infos"> |
5 | <div class="basic-info" > | 5 | <div class="basic-info" > |
6 | {{#thumbs}} | 6 | {{#thumbs}} |
7 | - <img class="thumb {{#unless @first}}hide{{/if}}" src={{img}}> | 7 | + <img class="thumb {{#unless @first}}hide{{/unless}}" src={{img}}> |
8 | {{/thumbs}} | 8 | {{/thumbs}} |
9 | <div class="text-info"> | 9 | <div class="text-info"> |
10 | <p class="name">{{name}}</p> | 10 | <p class="name">{{name}}</p> |
@@ -20,7 +20,7 @@ | @@ -20,7 +20,7 @@ | ||
20 | <div class="color-list block-list"> | 20 | <div class="color-list block-list"> |
21 | <span>颜色</span> | 21 | <span>颜色</span> |
22 | {{# colors}} | 22 | {{# colors}} |
23 | - <ul id="{{id}}" data-index="{{@index}}" class="size-row clearfix {{#unless @first}}hide{{/if}}"> | 23 | + <ul id="{{id}}" data-index="{{@index}}" class="size-row clearfix {{#unless @first}}hide{{/unless}}"> |
24 | {{# color}} | 24 | {{# color}} |
25 | <li class="block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}zero-stock{{/unless}}" data-num="{{colorNum}}"> | 25 | <li class="block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}zero-stock{{/unless}}" data-num="{{colorNum}}"> |
26 | {{name}} | 26 | {{name}} |
@@ -32,7 +32,7 @@ | @@ -32,7 +32,7 @@ | ||
32 | <div class="size-list block-list"> | 32 | <div class="size-list block-list"> |
33 | <span>尺码</span> | 33 | <span>尺码</span> |
34 | {{# sizes}} | 34 | {{# sizes}} |
35 | - <ul class="size-row clearfix {{#unless @first}}hide{{/if}}"> | 35 | + <ul class="size-row clearfix {{#unless @first}}hide{{/unless}}"> |
36 | {{# size}} | 36 | {{# size}} |
37 | <li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}zero-stock{{/unless}}" data-num="{{sizeNum}}" data-id="{{id}}" data-skuid="{{skuId}}"> | 37 | <li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}zero-stock{{/unless}}" data-num="{{sizeNum}}" data-id="{{id}}" data-skuid="{{skuId}}"> |
38 | {{name}} | 38 | {{name}} |
public/js/cart/chose-panel.js
0 → 100644
1 | +/** | ||
2 | + * 购物车选择尺寸、颜色和数量面板 | ||
3 | + * 显示时构造当前商品信息的HTML插入yoho-page;消失则是直接清除HTML | ||
4 | + * @author: xuqi<qi.xu@yoho.cn> | ||
5 | + * @date: 2015/10/21 | ||
6 | + */ | ||
7 | + | ||
8 | + | ||
9 | +// bikai | ||
10 | +// 增加init函数,异步请求的接口需要重新初始化一下选择列表 | ||
11 | +// 异步渲染的模板统一插入 #chose-panel ,兼容页面多个选择框 | ||
12 | + | ||
13 | +var $ = require('yoho-jquery'), | ||
14 | + tip = require('../plugin/tip'), | ||
15 | + loading = require('../plugin/loading'); | ||
16 | + | ||
17 | +var innerScroll = require('../plugin/inner-scroll'); | ||
18 | + | ||
19 | +var $chosePanel = $('#chose-panel'), | ||
20 | + $num, | ||
21 | + $chosed, | ||
22 | + $imgsThumb, | ||
23 | + $leftNum, | ||
24 | + leftNum, | ||
25 | + confirming, | ||
26 | + curColorIndex, | ||
27 | + curSizeIndex, | ||
28 | + hasChooseColor, | ||
29 | + hasChooseSize, | ||
30 | + $curSizeBlock, | ||
31 | + $sizeRowList, | ||
32 | + $curColorBlock, | ||
33 | + $colorRowList, | ||
34 | + cbFn, | ||
35 | + $allChoseItems, | ||
36 | + queryString, | ||
37 | + $choseArea, | ||
38 | + $cartBar, | ||
39 | + $soonSoldOut = $('.soonSoldOut-tag'), | ||
40 | + $yohoPage = $('.yoho-page'); | ||
41 | + | ||
42 | +// 购物车编辑标相关变量 | ||
43 | +var isEdit, | ||
44 | + isSelected, | ||
45 | + oldSknId; | ||
46 | + | ||
47 | +// 限购商品的商品码。只有限购商品时才会设置。 | ||
48 | +var limitProductCode, | ||
49 | + | ||
50 | + // 限购商品的skn。只有限购商品时才会设置。 | ||
51 | + skn; | ||
52 | + | ||
53 | +// 禁用数字编辑 | ||
54 | +function disableNumEdit() { | ||
55 | + var $numBtn = $('.chose-panel').find('.num .btn>.iconfont'); | ||
56 | + | ||
57 | + // 添加disabled样式 | ||
58 | + $numBtn.hasClass('disabled') ? null : $numBtn.addClass('disabled'); | ||
59 | + | ||
60 | + $yohoPage.off('touchstart', '.btn-minus'); | ||
61 | + $yohoPage.off('touchstart', '.btn-plus'); | ||
62 | +} | ||
63 | + | ||
64 | +// 初始化购物车面板显示 | ||
65 | +function init() { | ||
66 | + hasChooseColor = false; | ||
67 | + hasChooseSize = false; | ||
68 | + $curSizeBlock = null; | ||
69 | + | ||
70 | + queryString = $.queryString(); | ||
71 | + $imgsThumb = $('.chose-panel').find('.thumb'); | ||
72 | + $choseArea = $('.chose-panel .main .chose-items'); | ||
73 | + $allChoseItems = $('.chose-items'); | ||
74 | + $sizeRowList = $('.size-list ul'); | ||
75 | + $colorRowList = $('.color-list ul'); | ||
76 | + $leftNum = $('#left-num'); | ||
77 | + $cartBar = $('.cart-bar'); | ||
78 | + curColorIndex = 0; | ||
79 | + curSizeIndex = 0; | ||
80 | + isEdit = 0; | ||
81 | +} | ||
82 | + | ||
83 | +/* | ||
84 | + * 设置当前面板为编辑模式 | ||
85 | + * | ||
86 | + * @param {String} sknId. 当前编辑商品的sknId | ||
87 | + * | ||
88 | + * @param {Bool} isThisGoodSelected. 当前编辑商品的在购物车中是否被选中 | ||
89 | + * | ||
90 | + * @return {undefined} | ||
91 | + */ | ||
92 | +function setEditModeWithSknId(sknId, isThisGoodSelected) { | ||
93 | + $('#chose-btn-sure').html('确认'); | ||
94 | + isEdit = 1; | ||
95 | + oldSknId = sknId; | ||
96 | + isSelected = isThisGoodSelected; | ||
97 | +} | ||
98 | + | ||
99 | +/* | ||
100 | + * 设置当前面板为限购商品模式 | ||
101 | + * | ||
102 | + * @param {String} code 当前限购商品的商品码 | ||
103 | + * | ||
104 | + * @param {String} sknId. 当前限购商品的sknId | ||
105 | + * | ||
106 | + * @return {undefined} | ||
107 | + */ | ||
108 | +function setLimitGoodModeWithSknId(code, sknId) { | ||
109 | + disableNumEdit(); | ||
110 | + $('#chose-btn-sure').html('立即购买'); | ||
111 | + limitProductCode = code; | ||
112 | + skn = sknId; | ||
113 | +} | ||
114 | + | ||
115 | +// 删除面板 | ||
116 | +function removePannel() { | ||
117 | + var $pannel = $('.chose-panel'), | ||
118 | + $promotionId = $('#promotionId'); | ||
119 | + | ||
120 | + if ($pannel) { | ||
121 | + $pannel.remove(); | ||
122 | + } | ||
123 | + | ||
124 | + if ($promotionId) { | ||
125 | + $promotionId.remove(); | ||
126 | + } | ||
127 | +} | ||
128 | + | ||
129 | +function checkColorSizeNum() { | ||
130 | + if (!hasChooseColor && !hasChooseSize) { | ||
131 | + tip.show('请选择颜色和尺码~'); | ||
132 | + return false; | ||
133 | + } else if (!hasChooseColor) { | ||
134 | + tip.show('请选择颜色~'); | ||
135 | + return false; | ||
136 | + } else if (!hasChooseSize) { | ||
137 | + tip.show('请选择尺码~'); | ||
138 | + return false; | ||
139 | + } | ||
140 | + return true; | ||
141 | +} | ||
142 | + | ||
143 | + | ||
144 | + | ||
145 | +function show(html, cb) { | ||
146 | + if (html) { | ||
147 | + $chosePanel.html(html); | ||
148 | + if ($('#promotionId').val() !== '') { | ||
149 | + disableNumEdit(); | ||
150 | + } | ||
151 | + init(); | ||
152 | + } | ||
153 | + | ||
154 | + $('.chose-panel').show(); | ||
155 | + $num = $('#good-num'); | ||
156 | + cbFn = cb; | ||
157 | + | ||
158 | + | ||
159 | + innerScroll.disableScroll($choseArea); | ||
160 | +} | ||
161 | + | ||
162 | +// 隐藏当前Panel | ||
163 | +function hide() { | ||
164 | + $('.chose-panel').hide(); | ||
165 | + innerScroll.enableScroll($choseArea); | ||
166 | + | ||
167 | + if ($cartBar.length > 0) { | ||
168 | + $cartBar.show(); | ||
169 | + } | ||
170 | +} | ||
171 | + | ||
172 | +// 修改加入购物车的文字和背景 | ||
173 | +function updateConformButtonClassAndText() { | ||
174 | + $chosed = $allChoseItems.find('.chosed'); | ||
175 | + if ($chosed.closest('.zero-stock').length === 2) { | ||
176 | + $('#chose-btn-sure').css('background-color', '#c0c0c0').html('已售罄'); | ||
177 | + } else if (limitProductCode) { | ||
178 | + $('#chose-btn-sure').css('background-color', '#eb0313').html('立即购买'); | ||
179 | + } else { | ||
180 | + $('#chose-btn-sure').css('background-color', '#eb0313').html(isEdit ? '确认' : '加入购物车'); | ||
181 | + } | ||
182 | +} | ||
183 | + | ||
184 | +// 显示剩余件数 | ||
185 | +function displayGoodNum(curGoodNum) { | ||
186 | + | ||
187 | + // 数量大于0 | ||
188 | + if (curGoodNum > 0) { | ||
189 | + if ($soonSoldOut.length > 0) { | ||
190 | + $allChoseItems.find('.num .left-num').html('即将售罄'); | ||
191 | + } else { | ||
192 | + $allChoseItems.find('.num .left-num').html('剩余' + curGoodNum + '件'); | ||
193 | + } | ||
194 | + | ||
195 | + $leftNum.val(curGoodNum); | ||
196 | + | ||
197 | + // 数量小于0 | ||
198 | + } else { | ||
199 | + $allChoseItems.find('.num .left-num').html(''); | ||
200 | + $leftNum.val(0); | ||
201 | + } | ||
202 | +} | ||
203 | + | ||
204 | +// 老的选中尺码去掉勾选,新的选中尺码加上勾选 | ||
205 | +function changeSizeChosed(newSizeIndex) { | ||
206 | + var sizes, | ||
207 | + i; | ||
208 | + | ||
209 | + if (curColorIndex && $curSizeBlock && $curSizeBlock.length > 0) { | ||
210 | + $curSizeBlock.removeClass('chosed'); | ||
211 | + sizes = $sizeRowList.eq(newSizeIndex).children(); | ||
212 | + for (i = 0; i < sizes.length; i++) { | ||
213 | + if ($(sizes[i]).data('id') === $curSizeBlock.data('id')) { | ||
214 | + $curSizeBlock = $(sizes[i]); | ||
215 | + queryString = '#' + $curSizeBlock.data('id'); | ||
216 | + curColorIndex = $(queryString).data('index'); | ||
217 | + $curSizeBlock.addClass('chosed'); | ||
218 | + return $curSizeBlock.data('num'); | ||
219 | + } | ||
220 | + } | ||
221 | + | ||
222 | + // 特殊处理: 老的选中尺码在新选中的颜色对应尺码中不存在,需要下述1,2,3 | ||
223 | + // 1.重置尺码选择的标志变量. | ||
224 | + $curSizeBlock = null; | ||
225 | + hasChooseSize = false; | ||
226 | + | ||
227 | + // 2.当前颜色行隐藏 | ||
228 | + $colorRowList.eq(curColorIndex).addClass('hide'); | ||
229 | + | ||
230 | + // 3.目标颜色行第一行显示 | ||
231 | + $colorRowList.eq(0).removeClass('hide'); | ||
232 | + curColorIndex = 0; | ||
233 | + | ||
234 | + return -1; | ||
235 | + } | ||
236 | + return 0; | ||
237 | +} | ||
238 | + | ||
239 | +// 老的选中颜色去掉勾选,新的选中颜色加上勾选 | ||
240 | +function changeColorChosed(newColorIndex) { | ||
241 | + if (curSizeIndex && $curColorBlock && $curColorBlock.length > 0) { | ||
242 | + $curColorBlock.removeClass('chosed'); | ||
243 | + $curColorBlock = $($colorRowList.eq(newColorIndex).children().get(curSizeIndex - 1)); | ||
244 | + $curColorBlock.addClass('chosed'); | ||
245 | + return $curColorBlock.data('num'); | ||
246 | + } | ||
247 | + return 0; | ||
248 | +} | ||
249 | + | ||
250 | +init(); | ||
251 | + | ||
252 | + | ||
253 | +$yohoPage.on('touchstart', '.chose-panel', function(e) { | ||
254 | + var $cur = $(e.target); | ||
255 | + | ||
256 | + if ($cur.closest('.main').length > 0) { | ||
257 | + return; | ||
258 | + } | ||
259 | + | ||
260 | + // 点击蒙版消失 | ||
261 | + hide(); | ||
262 | + | ||
263 | + return false; | ||
264 | +}); | ||
265 | + | ||
266 | +$yohoPage.on('touchstart', '.color-list .block', function() { | ||
267 | + var $this = $(this), | ||
268 | + index = $this.index(), | ||
269 | + curGoodNum; | ||
270 | + | ||
271 | + // 当前颜色已经是选中状态,再点击时 | ||
272 | + if ($this.hasClass('chosed')) { | ||
273 | + | ||
274 | + // 清空剩余件数的提示 | ||
275 | + $allChoseItems.find('.num .left-num').html(''); | ||
276 | + $leftNum.val(0); | ||
277 | + hasChooseColor = false; | ||
278 | + | ||
279 | + // 当前尺码行隐藏 | ||
280 | + $sizeRowList.eq(curSizeIndex).addClass('hide'); | ||
281 | + | ||
282 | + // 目标尺码行显示 | ||
283 | + $sizeRowList.eq(0).removeClass('hide'); | ||
284 | + | ||
285 | + curSizeIndex = 0; | ||
286 | + | ||
287 | + // 老的选中尺码去掉勾选,新的选中尺码加上勾选 | ||
288 | + changeSizeChosed(0); | ||
289 | + | ||
290 | + // 当前颜色不是选中状态,选中时 | ||
291 | + } else { | ||
292 | + hasChooseColor = true; | ||
293 | + | ||
294 | + // 尺码行当前行隐藏 | ||
295 | + $sizeRowList.eq(curSizeIndex).addClass('hide'); | ||
296 | + | ||
297 | + // 老的选中尺码去掉勾选,新的选中尺码加上勾选 | ||
298 | + curGoodNum = changeSizeChosed(index + 1); | ||
299 | + | ||
300 | + // 显示剩余数量 | ||
301 | + displayGoodNum(curGoodNum); | ||
302 | + | ||
303 | + // 尺码对应行显示 | ||
304 | + $sizeRowList.eq(index + 1).removeClass('hide'); | ||
305 | + | ||
306 | + curSizeIndex = index + 1; | ||
307 | + $curColorBlock = $this; | ||
308 | + | ||
309 | + // 修改颜色时修改商品图片 | ||
310 | + $imgsThumb.addClass('hide').eq(index).removeClass('hide'); | ||
311 | + } | ||
312 | + | ||
313 | + // 颜色块切换勾选样式 | ||
314 | + $this.siblings('.chosed').removeClass('chosed'); | ||
315 | + | ||
316 | + // 特殊处理: 老的选中尺码在新选中的颜色对应尺码中不存在, 需要将颜色的第一行对应的颜色块加上勾选样式. | ||
317 | + if (curGoodNum === -1) { | ||
318 | + $curColorBlock = $($colorRowList.eq(0).children().get(index)); | ||
319 | + $curColorBlock.addClass('chosed'); | ||
320 | + | ||
321 | + // 当前选择的颜色块,加上勾选样式 | ||
322 | + } else { | ||
323 | + $this.toggleClass('chosed'); | ||
324 | + } | ||
325 | + | ||
326 | + $('#good-num').val(1); | ||
327 | + | ||
328 | + // 设置按钮的样式和文字 | ||
329 | + updateConformButtonClassAndText(); | ||
330 | +}).on('touchstart', '.size-list .block', function() { | ||
331 | + var $this = $(this), | ||
332 | + index, | ||
333 | + curGoodNum; | ||
334 | + | ||
335 | + // 当前尺码已经是选中状态,再点击时 | ||
336 | + if ($this.hasClass('chosed')) { | ||
337 | + | ||
338 | + // 清空剩余件数的提示 | ||
339 | + $allChoseItems.find('.num .left-num').html(''); | ||
340 | + $leftNum.val(0); | ||
341 | + hasChooseSize = false; | ||
342 | + | ||
343 | + // 当前颜色行隐藏 | ||
344 | + $colorRowList.eq(curColorIndex).addClass('hide'); | ||
345 | + | ||
346 | + // 目标颜色行显示 | ||
347 | + $colorRowList.eq(0).removeClass('hide'); | ||
348 | + | ||
349 | + curColorIndex = 0; | ||
350 | + | ||
351 | + // 老的选中颜色去掉勾选,新的选中颜色加上勾选 | ||
352 | + changeColorChosed(0); | ||
353 | + | ||
354 | + // 当前尺码不是选中状态,选中时 | ||
355 | + } else { | ||
356 | + hasChooseSize = true; | ||
357 | + | ||
358 | + index = $('#' + $this.data('id')).data('index') - 1; | ||
359 | + | ||
360 | + // 颜色当前行隐藏 | ||
361 | + $colorRowList.eq(curColorIndex).addClass('hide'); | ||
362 | + | ||
363 | + // 老的选中颜色去掉勾选,新的选中颜色加上勾选 | ||
364 | + curGoodNum = changeColorChosed(index + 1); | ||
365 | + | ||
366 | + // 显示剩余数量 | ||
367 | + displayGoodNum(curGoodNum); | ||
368 | + | ||
369 | + // 颜色对应行显示 | ||
370 | + $colorRowList.eq(index + 1).removeClass('hide'); | ||
371 | + | ||
372 | + curColorIndex = index + 1; | ||
373 | + $curSizeBlock = $this; | ||
374 | + } | ||
375 | + | ||
376 | + // 颜色块切换勾选样式 | ||
377 | + $this.siblings('.chosed').removeClass('chosed'); | ||
378 | + $this.toggleClass('chosed'); | ||
379 | + $('#good-num').val(1); | ||
380 | + | ||
381 | + // 设置按钮的样式和文字 | ||
382 | + updateConformButtonClassAndText(); | ||
383 | +}); | ||
384 | + | ||
385 | +$yohoPage.on('touchstart', '.btn-minus', function() { | ||
386 | + var num = parseInt($num.val(), 10); | ||
387 | + | ||
388 | + leftNum = $('#left-num').val(); | ||
389 | + | ||
390 | + if (!checkColorSizeNum()) { | ||
391 | + return; | ||
392 | + } | ||
393 | + | ||
394 | + if (num === 1 || (leftNum - 0) === 0) { | ||
395 | + tip.show('您选择的数量不能为零~'); | ||
396 | + return; | ||
397 | + } | ||
398 | + if (num < 0) { | ||
399 | + tip.show('您选择的数量不能为负数~'); | ||
400 | + return; | ||
401 | + } | ||
402 | + | ||
403 | + $num.val(num - 1); | ||
404 | +}).on('touchstart', '.btn-plus', function() { | ||
405 | + var num = parseInt($num.val(), 10); | ||
406 | + | ||
407 | + leftNum = $('#left-num').val(); | ||
408 | + | ||
409 | + if (!checkColorSizeNum()) { | ||
410 | + return; | ||
411 | + } | ||
412 | + | ||
413 | + if (num - 0 === leftNum || leftNum === 0) { | ||
414 | + return; | ||
415 | + } | ||
416 | + | ||
417 | + // TODO:库存数验证 | ||
418 | + if (num > leftNum - 1) { | ||
419 | + tip.show('您选择的数量超过了最大库存量~'); | ||
420 | + return; | ||
421 | + } | ||
422 | + $num.val(num + 1); | ||
423 | +}).on('touchstart', '#chose-btn-sure', function() { | ||
424 | + | ||
425 | + var productSku, | ||
426 | + buyNumber = $('#good-num').val() - 0, | ||
427 | + | ||
428 | + promotionId, | ||
429 | + cartGoodData, | ||
430 | + url, | ||
431 | + num = parseInt($num.val(), 10); | ||
432 | + | ||
433 | + // 颜色尺码没有选择 | ||
434 | + if (!checkColorSizeNum()) { | ||
435 | + return; | ||
436 | + } | ||
437 | + | ||
438 | + if ($('#chose-btn-sure').html() === '已售罄') { | ||
439 | + return; | ||
440 | + } | ||
441 | + | ||
442 | + leftNum = $('#left-num').val() - 0; | ||
443 | + | ||
444 | + if (num > leftNum) { | ||
445 | + tip.show('您选择的数量超过了最大库存量~'); | ||
446 | + return; | ||
447 | + } | ||
448 | + if (num < 0) { | ||
449 | + tip.show('您选择的数量小于一件~'); | ||
450 | + return; | ||
451 | + } | ||
452 | + $chosed = $('.block-list>ul>li.chosed'); | ||
453 | + | ||
454 | + if ($chosed.length === 2 && $chosed.closest('.zero-stock').length === 0) { | ||
455 | + productSku = $curSizeBlock.data('skuid'); | ||
456 | + promotionId = $('#promotionId').val(); | ||
457 | + if (confirming) { | ||
458 | + return false; | ||
459 | + } | ||
460 | + | ||
461 | + confirming = true; | ||
462 | + loading.showLoadingMask(); | ||
463 | + | ||
464 | + // 针对是否处于编辑模式设置不同的url和需要post的数据 | ||
465 | + if (isEdit) { | ||
466 | + cartGoodData = { | ||
467 | + new_product_sku: productSku, | ||
468 | + old_product_sku: oldSknId, | ||
469 | + buy_number: buyNumber, | ||
470 | + selected: isSelected | ||
471 | + }; | ||
472 | + | ||
473 | + url = '/cart/index/modify'; | ||
474 | + | ||
475 | + } else if (limitProductCode) { | ||
476 | + | ||
477 | + $(this).css('background-color', '#ccc').removeAttr('id'); | ||
478 | + | ||
479 | + // 当前面板选择的是限购商品 | ||
480 | + url = $('#limitProductPay').val() + '?limitproductcode=' + limitProductCode + '&sku=' + | ||
481 | + productSku + '&skn=' + skn + '&buy_number=' + buyNumber; | ||
482 | + | ||
483 | + removePannel(); | ||
484 | + loading.showLoadingMask(); | ||
485 | + | ||
486 | + // 调用接口判断商品是否可以购买 | ||
487 | + $.ajax({ | ||
488 | + url: url | ||
489 | + }).then(function(res) { | ||
490 | + | ||
491 | + // 如果有错,则商品不可购买,执行页面刷新,否则跳到结算页面 | ||
492 | + if (res.error) { | ||
493 | + tip.show(res.message); | ||
494 | + setTimeout(function() { | ||
495 | + location.reload(); | ||
496 | + }, 2000); | ||
497 | + } else { | ||
498 | + location.href = url; | ||
499 | + } | ||
500 | + }).fail(function() { | ||
501 | + tip.show('网络异常!'); | ||
502 | + setTimeout(function() { | ||
503 | + location.reload(); | ||
504 | + }, 2000); | ||
505 | + }); | ||
506 | + | ||
507 | + return false; | ||
508 | + | ||
509 | + } else { | ||
510 | + cartGoodData = { | ||
511 | + productSku: productSku, | ||
512 | + buyNumber: buyNumber, | ||
513 | + promotionId: promotionId, | ||
514 | + isEdit: isEdit, | ||
515 | + cartType: queryString.cartType | ||
516 | + }; | ||
517 | + | ||
518 | + url = '/cart/index/add'; | ||
519 | + } | ||
520 | + | ||
521 | + $.ajax({ | ||
522 | + method: 'POST', | ||
523 | + url: url, | ||
524 | + data: cartGoodData | ||
525 | + }).done(function(res) { | ||
526 | + var cartNum; | ||
527 | + | ||
528 | + loading.hideLoadingMask(); | ||
529 | + if (res.code === 200 && !isEdit) { | ||
530 | + cartNum = res.data.goods_count; | ||
531 | + if (cartNum > 99) { | ||
532 | + cartNum = '99+'; | ||
533 | + } | ||
534 | + $('.num-tag').html(cartNum).removeClass('hide'); | ||
535 | + confirming = false; | ||
536 | + | ||
537 | + if (cbFn) { | ||
538 | + cbFn(); | ||
539 | + } | ||
540 | + } | ||
541 | + if (res.message && !isEdit) { | ||
542 | + tip.show(res.message); | ||
543 | + } | ||
544 | + | ||
545 | + hide(); | ||
546 | + | ||
547 | + if (isEdit) { | ||
548 | + loading.showLoadingMask(); | ||
549 | + | ||
550 | + // 延迟刷新,否则面板可能无法隐藏 | ||
551 | + setTimeout(function() { | ||
552 | + | ||
553 | + // 获取当前页面商品类型:普通商品/预售商品 | ||
554 | + window.location.href = '/cart/index/index?cartType=' + $('#cartType').val(); | ||
555 | + }, 1); | ||
556 | + } | ||
557 | + }).fail(function() { | ||
558 | + tip.show('网络出了点问题~'); | ||
559 | + }).always(function() { | ||
560 | + confirming = false; | ||
561 | + }); | ||
562 | + } | ||
563 | + | ||
564 | +}); | ||
565 | + | ||
566 | +exports.init = init; | ||
567 | +exports.show = show; | ||
568 | +exports.remove = removePannel; | ||
569 | +exports.setEditModeWithSknId = setEditModeWithSknId; | ||
570 | +exports.disableNumEdit = disableNumEdit; | ||
571 | +exports.setLimitGoodModeWithSknId = setLimitGoodModeWithSknId; |
public/js/me/dialog.js
0 → 100644
1 | +/* | ||
2 | + * @Description: dialog | ||
3 | + * @Time: 2015/11/18 | ||
4 | + * @author: chenglong.wang | ||
5 | + */ | ||
6 | + | ||
7 | +var $ = require('yoho-jquery'), | ||
8 | + Handlebars = require('yoho-handlebars'), | ||
9 | + Hammer = require('yoho-hammer'); | ||
10 | + | ||
11 | +var $dialogWrapper, | ||
12 | + dialogTpl, | ||
13 | + dialogTemplate; | ||
14 | + | ||
15 | +function getInstance() { | ||
16 | + if (dialogTpl === undefined) { | ||
17 | + dialogTpl = '<div id="dialog-wrapper" class="dialog-wrapper">' + | ||
18 | + '<div class="dialog-box">' + | ||
19 | + '{{# hasHeader}}' + | ||
20 | + '{{/ hasHeader}}' + | ||
21 | + '<div class="dialog-content">{{dialogText}}</div>' + | ||
22 | + '{{# hasFooter}}' + | ||
23 | + '<div class="dialog-footer">' + | ||
24 | + '{{# leftBtnText}}' + | ||
25 | + '<span class="dialog-left-btn tap-hightlight">{{.}}</span>' + | ||
26 | + '{{/ leftBtnText}}' + | ||
27 | + '{{# rightBtnText}}' + | ||
28 | + '<span class="dialog-right-btn tap-hightlight">{{.}}</span>' + | ||
29 | + '{{/ rightBtnText}}' + | ||
30 | + '</div>' + | ||
31 | + '{{/ hasFooter}}' + | ||
32 | + '</div>' + | ||
33 | + '</div>'; | ||
34 | + | ||
35 | + dialogTemplate = Handlebars.compile(dialogTpl); | ||
36 | + } | ||
37 | + return dialogTemplate; | ||
38 | +} | ||
39 | + | ||
40 | +// fullWithBtn是供详情页获取限购码使用的特殊参数 | ||
41 | +exports.showDialog = function(data, callback, callbackForLeft, fullWithBtn) { | ||
42 | + | ||
43 | + var dialogTemplate = getInstance(), | ||
44 | + dialogStr = dialogTemplate(data), | ||
45 | + $dialogBox, | ||
46 | + defaultHideDuraton, | ||
47 | + dialogWrapperHammer; | ||
48 | + | ||
49 | + $('.dialog-wrapper').remove(); | ||
50 | + | ||
51 | + $('body').append($(dialogStr)); | ||
52 | + | ||
53 | + $dialogBox = $('.dialog-box'); | ||
54 | + $dialogWrapper = $('.dialog-wrapper'); | ||
55 | + | ||
56 | + | ||
57 | + dialogWrapperHammer = new Hammer(document.getElementById('dialog-wrapper')); | ||
58 | + | ||
59 | + // 显示 | ||
60 | + if (data.fast) { | ||
61 | + $dialogWrapper.css({ | ||
62 | + display: 'block' | ||
63 | + }); | ||
64 | + } else { | ||
65 | + $dialogWrapper.fadeIn(); | ||
66 | + } | ||
67 | + | ||
68 | + if (fullWithBtn) { | ||
69 | + $('.dialog-wrapper .dialog-footer > span').css('width', '100%'); | ||
70 | + $('.dialog-wrapper .dialog-content').css({ | ||
71 | + 'padding-left': '1.85rem', | ||
72 | + 'padding-right': '1.85rem' | ||
73 | + }); | ||
74 | + $dialogWrapper.css('z-index', '10'); | ||
75 | + } | ||
76 | + | ||
77 | + $dialogBox.css({ | ||
78 | + top: '50%', | ||
79 | + marginTop: -($dialogBox.height() / 2) | ||
80 | + }); | ||
81 | + | ||
82 | + // 隐藏 | ||
83 | + if (data.autoHide) { | ||
84 | + defaultHideDuraton = 1000; | ||
85 | + if (data.autoHide > 1) { | ||
86 | + defaultHideDuraton = data.autoHide; | ||
87 | + } | ||
88 | + setTimeout(function() { | ||
89 | + $dialogWrapper.fadeOut(); | ||
90 | + }, defaultHideDuraton); | ||
91 | + } | ||
92 | + | ||
93 | + // 禁止在dialog上可以上下滚动 | ||
94 | + $dialogWrapper.on('touchmove', function() { | ||
95 | + return false; | ||
96 | + }); | ||
97 | + | ||
98 | + dialogWrapperHammer.on('tap', function(event) { | ||
99 | + | ||
100 | + if ($(event.target).hasClass('dialog-left-btn')) { | ||
101 | + if (typeof callbackForLeft === 'function') { | ||
102 | + callbackForLeft(); | ||
103 | + } | ||
104 | + $dialogWrapper.fadeOut(); | ||
105 | + } else if ($(event.target).hasClass('dialog-right-btn')) { | ||
106 | + callback(); | ||
107 | + } | ||
108 | + | ||
109 | + // 防止出现点透问题 | ||
110 | + event.preventDefault(); | ||
111 | + event.srcEvent.stopPropagation(); | ||
112 | + }); | ||
113 | +}; | ||
114 | + | ||
115 | +exports.hideDialog = function() { | ||
116 | + $('.dialog-wrapper').remove(); | ||
117 | +}; |
public/js/plugin/inner-scroll.js
0 → 100644
1 | +/** | ||
2 | + * 弹出层可以滚动,遮盖层禁止滚动插件 | ||
3 | + * | ||
4 | + * @author liangzhifeng<zhifeng.liang@yoho.cn> | ||
5 | + * @date: 2016/02/22 | ||
6 | + */ | ||
7 | + | ||
8 | +var $ = require('yoho-jquery'); | ||
9 | + | ||
10 | +function preventDefault(e) { | ||
11 | + e = e || window.event; | ||
12 | + e.preventDefault && e.preventDefault(); | ||
13 | + e.returnValue = false; | ||
14 | +} | ||
15 | + | ||
16 | +function stopPropagation(e) { | ||
17 | + e = e || window.event; | ||
18 | + e.stopPropagation && e.stopPropagation(); | ||
19 | + e.cancelBubble = false; | ||
20 | +} | ||
21 | + | ||
22 | +function innerScroll(e) { | ||
23 | + var delta = e.wheelDelta || e.originalEvent.wheelDelta || e.detail || 0, | ||
24 | + box = $(this).get(0); | ||
25 | + | ||
26 | + // 阻止冒泡到document | ||
27 | + // document上已经preventDefault | ||
28 | + stopPropagation(e); | ||
29 | + | ||
30 | + | ||
31 | + if ($(box).height() + box.scrollTop >= box.scrollHeight) { | ||
32 | + if (delta < 0) { | ||
33 | + preventDefault(e); | ||
34 | + return false; | ||
35 | + } | ||
36 | + } | ||
37 | + if (box.scrollTop === 0) { | ||
38 | + if (delta > 0) { | ||
39 | + preventDefault(e); | ||
40 | + return false; | ||
41 | + } | ||
42 | + } | ||
43 | +} | ||
44 | + | ||
45 | +function disableScroll($choseArea) { | ||
46 | + var startX, startY; | ||
47 | + | ||
48 | + // 内部可滚 | ||
49 | + $choseArea.on('mousewheel', innerScroll); | ||
50 | + | ||
51 | + // 移动端touch重写 | ||
52 | + $choseArea.on('touchstart', function(e) { | ||
53 | + startX = e.originalEvent.changedTouches[0].pageX; | ||
54 | + startY = e.originalEvent.changedTouches[0].pageY; | ||
55 | + }); | ||
56 | + | ||
57 | + // 仿innerScroll方法 | ||
58 | + $choseArea.on('touchmove', function(e) { | ||
59 | + var deltaX = e.originalEvent.changedTouches[0].pageX - startX, | ||
60 | + deltaY = e.originalEvent.changedTouches[0].pageY - startY; | ||
61 | + | ||
62 | + var box = $(this).get(0); | ||
63 | + | ||
64 | + e.stopPropagation(); | ||
65 | + | ||
66 | + | ||
67 | + // 只能纵向滚 | ||
68 | + if (Math.abs(deltaY) < Math.abs(deltaX)) { | ||
69 | + e.preventDefault(); | ||
70 | + return false; | ||
71 | + } | ||
72 | + | ||
73 | + | ||
74 | + if ($(box).height() + box.scrollTop >= box.scrollHeight) { | ||
75 | + if (deltaY < 0) { | ||
76 | + e.preventDefault(); | ||
77 | + return false; | ||
78 | + } | ||
79 | + } | ||
80 | + if (box.scrollTop === 0) { | ||
81 | + if (deltaY > 0) { | ||
82 | + e.preventDefault(); | ||
83 | + return false; | ||
84 | + } | ||
85 | + } | ||
86 | + }); | ||
87 | + | ||
88 | + $(document).on('mousewheel', preventDefault); | ||
89 | + $(document).on('touchmove', preventDefault); | ||
90 | +} | ||
91 | + | ||
92 | +function enableScroll($choseArea) { | ||
93 | + | ||
94 | + $choseArea.off('touchstart'); | ||
95 | + $choseArea.off('touchmove'); | ||
96 | + $choseArea.off('mousewheel'); | ||
97 | + | ||
98 | + $(document).off('mousewheel', preventDefault); | ||
99 | + $(document).off('touchmove', preventDefault); | ||
100 | +} | ||
101 | + | ||
102 | +exports.enableScroll = enableScroll; | ||
103 | +exports.disableScroll = disableScroll; |
public/js/product/comments-consults.js
0 → 100644
1 | +/** | ||
2 | + * 商品详情 --评论和咨询tab | ||
3 | + * @author: Lynnic | ||
4 | + * @date: 2015/11/18 | ||
5 | + */ | ||
6 | +var $ = require('yoho-jquery'), | ||
7 | + tip = require('../plugin/tip'), | ||
8 | + Hammer = require('yoho-hammer'); | ||
9 | + | ||
10 | +var commentsNum, consultsNum; | ||
11 | + | ||
12 | +var navtabEle = document.getElementById('nav-tab'), | ||
13 | + navtabHammer = navtabEle && new Hammer(navtabEle), | ||
14 | + | ||
15 | + gotoConsultEle = document.getElementById('goto-consult'), | ||
16 | + gotoConsultHammer = gotoConsultEle && new Hammer(gotoConsultEle), | ||
17 | + | ||
18 | + readmore = document.getElementById('readmore'), | ||
19 | + readmoreHammer = readmore && new Hammer(readmore); | ||
20 | + | ||
21 | + | ||
22 | + | ||
23 | +(function() { | ||
24 | + consultsNum = $('#nav-tab .consults-num').html() - 0; | ||
25 | + | ||
26 | + commentsNum = $('#nav-tab .comments-num').html() - 0; | ||
27 | + | ||
28 | + $('#nav-tab li').each(function() { | ||
29 | + $(this).removeClass('focus'); | ||
30 | + }); | ||
31 | + | ||
32 | + $('#feedback-content .content').each(function() { | ||
33 | + $(this).addClass('hide'); | ||
34 | + }); | ||
35 | + if (0 !== commentsNum) { | ||
36 | + $('#nav-tab .comment-nav').addClass('focus'); | ||
37 | + $('#feedback-content .comment-content').removeClass('hide'); | ||
38 | + | ||
39 | + } else if (0 !== consultsNum) { | ||
40 | + $('#nav-tab .consult-nav').addClass('focus'); | ||
41 | + $('#feedback-content .consult-content').removeClass('hide'); | ||
42 | + } | ||
43 | + | ||
44 | +})(); | ||
45 | + | ||
46 | +if (navtabHammer) { | ||
47 | + navtabHammer.on('tap', function(e) { | ||
48 | + var $this = $(e.target).closest('li'); | ||
49 | + var index = $this.index(); | ||
50 | + | ||
51 | + if ($this.hasClass('comment-nav') && 0 === commentsNum) { | ||
52 | + tip.show('暂无商品评价'); | ||
53 | + } else { | ||
54 | + if (!$this.hasClass('focus')) { | ||
55 | + | ||
56 | + $('#nav-tab li').each(function() { | ||
57 | + $(this).removeClass('focus'); | ||
58 | + }); | ||
59 | + $('#feedback-content .content').each(function() { | ||
60 | + $(this).addClass('hide'); | ||
61 | + }); | ||
62 | + | ||
63 | + $this.addClass('focus'); | ||
64 | + $('#feedback-content .content:eq(' + index + ')').removeClass('hide'); | ||
65 | + } | ||
66 | + } | ||
67 | + }); | ||
68 | +} | ||
69 | + | ||
70 | +// if (consultFooterHammer) { | ||
71 | +// consultFooterHammer.on('tap', function() { | ||
72 | +// location.href = $(consultFooterEle).data('href'); | ||
73 | +// }); | ||
74 | +// } | ||
75 | + | ||
76 | +if (gotoConsultHammer) { | ||
77 | + gotoConsultHammer.on('tap', function() { | ||
78 | + location.href = $(gotoConsultEle).find('a').attr('href'); | ||
79 | + }); | ||
80 | +} | ||
81 | + | ||
82 | +// 咨询页面固定header | ||
83 | +if ($('.goods-consults-page').length > 0) { | ||
84 | + $('#yoho-header').css('position', 'fixed').css('top', '0'); | ||
85 | +} | ||
86 | + | ||
87 | +if ($('.goods-consults-page').length > 0) { | ||
88 | + $('#yoho-footer').css('border-top', '1px solid #e0e0e0'); | ||
89 | +} | ||
90 | + | ||
91 | +if (readmoreHammer) { | ||
92 | + readmoreHammer.on('tap', function() { | ||
93 | + $('.readmore').hide(); | ||
94 | + $('.goods-consults.customer-consults').removeClass('customer-consults'); | ||
95 | + | ||
96 | + return false; | ||
97 | + }); | ||
98 | +} | ||
99 | + | ||
100 | +require('./fav'); |
public/js/product/consultform.js
0 → 100644
1 | +/** | ||
2 | + * 我要咨询提交页面 | ||
3 | + * @author: liangzhifeng<zhifeng.liang@yoho.cn> | ||
4 | + * @date: 2015/12/01 | ||
5 | + */ | ||
6 | +var $ = require('yoho-jquery'), | ||
7 | + tip = require('../../plugin/tip'), | ||
8 | + loading = require('../../plugin/loading'); | ||
9 | + | ||
10 | +var $consultForm = $('.consult-form'), | ||
11 | + $submit = $('#submit'), | ||
12 | + $content = $('#content'), | ||
13 | + productId = $('#product_id').val(), | ||
14 | + isSubmiting; | ||
15 | + | ||
16 | +$submit.on('touchend', function() { | ||
17 | + $content.blur(); | ||
18 | + $consultForm.submit(); | ||
19 | + return false; | ||
20 | +}).on('touchstart', function() { | ||
21 | + $(this).addClass('highlight'); | ||
22 | +}).on('touchend touchcancel', function() { | ||
23 | + $(this).removeClass('highlight'); | ||
24 | +}); | ||
25 | + | ||
26 | +$content.on('focus', function() { | ||
27 | + if ($content.val() === '请输入咨询内容') { | ||
28 | + $content.val(''); | ||
29 | + } | ||
30 | +}).on('blur', function() { | ||
31 | + if ($content.val() === '') { | ||
32 | + $content.val('请输入咨询内容'); | ||
33 | + } | ||
34 | +}); | ||
35 | + | ||
36 | +// 提交表单请求 | ||
37 | +$consultForm.on('submit', function() { | ||
38 | + var content; | ||
39 | + | ||
40 | + if (isSubmiting) { | ||
41 | + return false; | ||
42 | + } | ||
43 | + | ||
44 | + // 简单的表单校验 | ||
45 | + content = $content.val(); | ||
46 | + if (!content || content === '请输入咨询内容') { | ||
47 | + tip.show('咨询内容不能为空'); | ||
48 | + return false; | ||
49 | + } | ||
50 | + | ||
51 | + isSubmiting = true; | ||
52 | + loading.showLoadingMask(); | ||
53 | + $.ajax({ | ||
54 | + method: 'POST', | ||
55 | + url: '/product/detail/consultsubmit', | ||
56 | + data: { | ||
57 | + product_id: productId, | ||
58 | + content: content | ||
59 | + } | ||
60 | + }).then(function(res) { | ||
61 | + if ($.type(res) !== 'object') { | ||
62 | + res = {}; | ||
63 | + } | ||
64 | + if (res.code !== 200) { | ||
65 | + tip.show(res.message || '网络出了点问题~'); | ||
66 | + isSubmiting = false; | ||
67 | + loading.hideLoadingMask(); | ||
68 | + } else { | ||
69 | + tip.show('提交成功~'); | ||
70 | + setTimeout(function() { | ||
71 | + window.history.go(-1); | ||
72 | + }, 3000); | ||
73 | + } | ||
74 | + }).fail(function() { | ||
75 | + tip.show('网络出了点问题~'); | ||
76 | + isSubmiting = false; | ||
77 | + }); | ||
78 | + return false; | ||
79 | +}); |
public/js/product/desc.js
0 → 100644
1 | +/** | ||
2 | + * 商品详情 --异步加载页面下半部分 | ||
3 | + * @author: liangzhifeng<zhifeng.liang@yoho.cn> | ||
4 | + * @date: 2015/11/18 | ||
5 | + */ | ||
6 | +var $ = require('yoho-jquery'), | ||
7 | + lazyLoad = require('yoho-jquery-lazyload'), | ||
8 | + Swiper = require('yoho-swiper'), | ||
9 | + loading = require('../plugin/loading'), | ||
10 | + tip = require('../plugin/tip'); | ||
11 | + | ||
12 | +var introUrl = $('#introUrl').val(), | ||
13 | + winH = $(window).height(), | ||
14 | + $productDesc, | ||
15 | + searching = false, | ||
16 | + end = false; | ||
17 | + | ||
18 | +var sizeSwiper, | ||
19 | + refSwiper; | ||
20 | + | ||
21 | + | ||
22 | +// 判断是否要显示向左滑动提示 | ||
23 | +function hiddenTips($ele) { | ||
24 | + var offsetContainer, | ||
25 | + offsetLastColumn; | ||
26 | + | ||
27 | + if ($ele.length > 0) { | ||
28 | + offsetContainer = $ele[0].getBoundingClientRect().right; | ||
29 | + offsetLastColumn = $ele.find('.swiper-slide:last-child')[0].getBoundingClientRect().right; | ||
30 | + | ||
31 | + | ||
32 | + if (offsetLastColumn - offsetContainer < 0) { | ||
33 | + $ele.next('.tips').css('display', 'none'); | ||
34 | + } else { | ||
35 | + $ele.next('.tips').css('display', 'block'); | ||
36 | + } | ||
37 | + } | ||
38 | +} | ||
39 | + | ||
40 | +// function isFlexSupport() { | ||
41 | +// var flex = document.createElement('p').style.flex, | ||
42 | +// webkitFlex = document.createElement('p').style.webkitFlex, | ||
43 | +// flexWrap = document.createElement('p').style.flexWrap; | ||
44 | +// | ||
45 | +// if ((flex === '' || webkitFlex === '') && flexWrap === '') { | ||
46 | +// return true; | ||
47 | +// } else { | ||
48 | +// return false; | ||
49 | +// } | ||
50 | +// } | ||
51 | + | ||
52 | +function wrapElements(selector, count) { | ||
53 | + var elArr = null; | ||
54 | + | ||
55 | + $(selector).each(function(idx, el) { | ||
56 | + elArr = $(selector).slice(idx, idx + count); | ||
57 | + | ||
58 | + if (elArr.length === count && idx % count === 0) { | ||
59 | + $(elArr).wrapAll($('<div class="js-wraper"></div>')); | ||
60 | + } | ||
61 | + }); | ||
62 | +} | ||
63 | + | ||
64 | + | ||
65 | + | ||
66 | +function search() { | ||
67 | + if (searching || end) { | ||
68 | + return; | ||
69 | + } | ||
70 | + searching = true; | ||
71 | + | ||
72 | + // alert($('#reference-swiper-container .swiper-wrapper').width()); | ||
73 | + | ||
74 | + loading.showLoadingMask(); | ||
75 | + | ||
76 | + $.ajax({ | ||
77 | + type: 'GET', | ||
78 | + url: introUrl, | ||
79 | + success: function(data) { | ||
80 | + $productDesc = $('#productDesc'); | ||
81 | + $productDesc.append(data); | ||
82 | + | ||
83 | + window.rePosFooter(); | ||
84 | + | ||
85 | + lazyLoad($productDesc.find('img.lazy')); | ||
86 | + | ||
87 | + // 尺码信息左右滑动 | ||
88 | + sizeSwiper = new Swiper('#size-swiper-container', { | ||
89 | + slidesPerView: 'auto' | ||
90 | + }); | ||
91 | + | ||
92 | + // 模特试穿左右滑动 | ||
93 | + refSwiper = new Swiper('#reference-swiper-container', { | ||
94 | + slidesPerView: 'auto' | ||
95 | + }); | ||
96 | + | ||
97 | + hiddenTips($('#size-swiper-container')); | ||
98 | + hiddenTips($('#reference-swiper-container')); | ||
99 | + | ||
100 | + // if (!isFlexSupport()) { | ||
101 | + // $('.detail .column').removeClass('column').addClass('oldbox'); | ||
102 | + // } | ||
103 | + wrapElements('.detail .column', 2); | ||
104 | + searching = false; | ||
105 | + end = true; | ||
106 | + loading.hideLoadingMask(); | ||
107 | + }, | ||
108 | + error: function() { | ||
109 | + tip.show('网络断开连接了~'); | ||
110 | + searching = false; | ||
111 | + loading.hideLoadingMask(); | ||
112 | + } | ||
113 | + }); | ||
114 | +} | ||
115 | + | ||
116 | +function scrollHandler() { | ||
117 | + if (!end || $(window).scrollTop() + winH >= $(document).height() - 200) { | ||
118 | + search(); | ||
119 | + } | ||
120 | +} | ||
121 | + | ||
122 | +// srcoll to load more | ||
123 | +$(window).scroll(function() { | ||
124 | + window.requestAnimationFrame(scrollHandler); | ||
125 | +}); | ||
126 | + |
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 goodsSwiper, | ||
12 | + $discountFolder = $('.goodsDiscount .discount-folder'), | ||
13 | + $discountArrow = $('.goodsDiscount .first-item span'); | ||
14 | + | ||
15 | +var goodsDiscountEl = document.getElementById('goodsDiscount'), | ||
16 | + goodsDiscountHammer = goodsDiscountEl && new Hammer(goodsDiscountEl), | ||
17 | + $discountFirstItem = $(goodsDiscountEl).find('.first-item'); | ||
18 | + | ||
19 | +var $cart = $('.cart-bar'); | ||
20 | + | ||
21 | +var appUrl = $('input[name="limitCodeUrl"]').val(); | ||
22 | + | ||
23 | +var dialog = require('../me/dialog'); | ||
24 | + | ||
25 | + | ||
26 | +// add extra marign-bottom for footer to show the yoho copyright | ||
27 | +function showFooter() { | ||
28 | + var $cartBar = $('.cart-bar'); | ||
29 | + | ||
30 | + var timer = setInterval(function() { | ||
31 | + if ($cartBar) { | ||
32 | + window.reMarginFooter('.cart-bar'); | ||
33 | + clearInterval(timer); | ||
34 | + } else { | ||
35 | + $cartBar = $('.cart-bar'); | ||
36 | + } | ||
37 | + }, 200); | ||
38 | +} | ||
39 | + | ||
40 | +showFooter(); | ||
41 | + | ||
42 | +require('./like'); | ||
43 | + | ||
44 | +lazyLoad($('img.lazy')); | ||
45 | + | ||
46 | +if ($('#goodsDiscount h1').length < 1) { | ||
47 | + $('.dropdown').remove(); | ||
48 | +} | ||
49 | + | ||
50 | +// 顶部swiper | ||
51 | +goodsSwiper = 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 | + | ||
62 | +// 初始化goods-discount | ||
63 | +if (0 === $discountFolder.children().length) { | ||
64 | + $discountFolder.css('display', 'none'); | ||
65 | + $discountArrow.html(''); | ||
66 | +} | ||
67 | + | ||
68 | +// goods-discount下拉按钮点击事件 | ||
69 | +if (goodsDiscountHammer && $discountFolder.children().length > 0) { | ||
70 | + goodsDiscountHammer.on('tap', function(e) { | ||
71 | + if ($discountFolder.is(':hidden')) { | ||
72 | + $discountFirstItem.removeClass('short-text'); | ||
73 | + $discountArrow.removeClass('icon-down').addClass('icon-up').html(''); | ||
74 | + $discountFolder.slideDown(); | ||
75 | + } else { | ||
76 | + $discountFirstItem.addClass('short-text'); | ||
77 | + $discountArrow.removeClass('icon-up').addClass('icon-down').html(''); | ||
78 | + $discountFolder.slideUp(); | ||
79 | + } | ||
80 | + }); | ||
81 | +} | ||
82 | + | ||
83 | +$('#limit-sale').on('touchend', function(e) { | ||
84 | + var loginUrl = $('#loginUrl').val(), | ||
85 | + time, | ||
86 | + ifr; | ||
87 | + | ||
88 | + e.stopPropagation(); | ||
89 | + | ||
90 | + if (loginUrl) { | ||
91 | + window.location = loginUrl; | ||
92 | + } else { | ||
93 | + dialog.showDialog({ | ||
94 | + dialogText: '进入有货APP,获取限购码', | ||
95 | + hasFooter: { | ||
96 | + rightBtnText: '打开Yoho!Buy有货APP' | ||
97 | + } | ||
98 | + }, function() { | ||
99 | + ifr = document.createElement('iframe'); | ||
100 | + ifr.src = appUrl; | ||
101 | + ifr.style.display = 'none'; | ||
102 | + document.body.appendChild(ifr); | ||
103 | + window.location.href = appUrl; | ||
104 | + | ||
105 | + time = Date.now(); | ||
106 | + window.setTimeout(function() { | ||
107 | + document.body.removeChild(ifr); | ||
108 | + if (Date.now() - time < 3200) { | ||
109 | + window.location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho'; | ||
110 | + } | ||
111 | + }, 3000); | ||
112 | + | ||
113 | + }, undefined, true); | ||
114 | + | ||
115 | + $('.dialog-wrapper').off('touchstart').on('touchstart', function(e) { | ||
116 | + e.stopPropagation(); | ||
117 | + if ($(e.target).hasClass('dialog-wrapper')) { | ||
118 | + dialog.hideDialog(); | ||
119 | + } | ||
120 | + }); | ||
121 | + } | ||
122 | +}); | ||
123 | + | ||
124 | +require('./desc'); | ||
125 | +require('./comments-consults'); | ||
126 | +require('../recommend-for-you-product-desc'); | ||
127 | + | ||
128 | +// 购物车商品数量 | ||
129 | +$.ajax({ | ||
130 | + type: 'GET', | ||
131 | + url: '/cart/index/count', | ||
132 | + success: function(data) { | ||
133 | + var count; | ||
134 | + | ||
135 | + if (data.code === 200) { | ||
136 | + count = data.data.cart_goods_count || 0; | ||
137 | + if (count === 0) { | ||
138 | + return false; | ||
139 | + } | ||
140 | + if (count > 99) { | ||
141 | + count = '99+'; | ||
142 | + } | ||
143 | + $cart.find('.num-tag').html(count).removeClass('hide'); | ||
144 | + } | ||
145 | + } | ||
146 | +}); | ||
147 | + | ||
148 | +if ($('.good-detail-page').length > 0) { | ||
149 | + $('#yoho-footer').css('border-top', '1px solid #e0e0e0'); | ||
150 | +} | ||
151 | + | ||
152 | + |
public/js/product/fav.js
0 → 100755
1 | +/** | ||
2 | + * 商品详情咨询页 --点赞和帮助功能 | ||
3 | + * @author: Lynnic | ||
4 | + * @date: 2015/12/09 | ||
5 | + */ | ||
6 | + | ||
7 | + var $ = require('yoho-jquery'), | ||
8 | + Hammer = require('yoho-hammer'), | ||
9 | + tip = require('../plugin/tip'); | ||
10 | + | ||
11 | + var goodsConsultsEle = $('#goods-consults')[0], | ||
12 | + goodsConsultsHammer = goodsConsultsEle && new Hammer(goodsConsultsEle); | ||
13 | + | ||
14 | + var productId, | ||
15 | + total; | ||
16 | + | ||
17 | + function showCountPlus($el) { | ||
18 | + var $count = $el.find('.animate-count'); | ||
19 | + | ||
20 | + $count.css('display', 'inline'); | ||
21 | + $count.animate({ | ||
22 | + opacity: 0.25, | ||
23 | + fontSize: '0.7rem', | ||
24 | + right: '-=5' | ||
25 | + }, 300, function() { | ||
26 | + $count.css('display', 'none'); | ||
27 | + }); | ||
28 | + } | ||
29 | + | ||
30 | + (function() { | ||
31 | + var queryStr = window.location.search.substring(1); | ||
32 | + | ||
33 | + productId = queryStr.split('&')[0].split('=')[1]; | ||
34 | + total = queryStr.split('&')[1] ? queryStr.split('&')[1].split('=')[1] : undefined; | ||
35 | + })(); | ||
36 | + | ||
37 | + if (goodsConsultsHammer) { | ||
38 | + | ||
39 | + goodsConsultsHammer.on('tap', function(e) { | ||
40 | + | ||
41 | + var $this = $(e.target).closest('li'), | ||
42 | + id = $this.closest('.consult-item').data('id'), | ||
43 | + count = $this.find('.count').html() - 0, | ||
44 | + url; | ||
45 | + | ||
46 | + if (!$this.hasClass('highlight')) { | ||
47 | + | ||
48 | + if ($this.hasClass('fav')) { | ||
49 | + url = '/product/detail/consultupvote'; | ||
50 | + } else if ($this.hasClass('useful')) { | ||
51 | + url = '/product/detail/consultuseful'; | ||
52 | + } | ||
53 | + | ||
54 | + $.ajax({ | ||
55 | + method: 'post', | ||
56 | + url: url, | ||
57 | + data: { | ||
58 | + id: id, | ||
59 | + productId: productId, | ||
60 | + total: total | ||
61 | + } | ||
62 | + }).done(function(data) { | ||
63 | + if (data.code === 200) { | ||
64 | + showCountPlus($this); | ||
65 | + $this.addClass('highlight'); | ||
66 | + $this.find('.count').html(count + 1); | ||
67 | + } else if (data.code === 401) { | ||
68 | + location.href = data.data;// 未登录跳转登录页 | ||
69 | + } | ||
70 | + }).fail(function(data) { | ||
71 | + tip.show('网络断开连接了~'); | ||
72 | + }); | ||
73 | + | ||
74 | + } | ||
75 | + }); | ||
76 | + } |
public/js/product/like.js
0 → 100644
1 | +/** | ||
2 | + * 商品详情 --添加收藏 | ||
3 | + * @author: Lynnic | ||
4 | + * @date: 2015/11/24 | ||
5 | + */ | ||
6 | + | ||
7 | + | ||
8 | +var $ = require('yoho-jquery'), | ||
9 | + tip = require('../plugin/tip'), | ||
10 | + chosePanel = require('../cart/chose-panel'); | ||
11 | + | ||
12 | +var productId = $('#productId').val(); | ||
13 | + | ||
14 | +var skn = $('#productSkn').val(), | ||
15 | + productCode = $('#limitProductCode').val(); | ||
16 | + | ||
17 | +$('#likeBtn').on('touchstart', function() { | ||
18 | + var opt, | ||
19 | + favorite; | ||
20 | + | ||
21 | + var $this = $(this); | ||
22 | + | ||
23 | + if ($this.hasClass('liked')) { | ||
24 | + opt = 'cancel'; | ||
25 | + favorite = 0; | ||
26 | + } else { | ||
27 | + opt = 'ok'; | ||
28 | + favorite = 1; | ||
29 | + } | ||
30 | + | ||
31 | + $.ajax({ | ||
32 | + type: 'POST', | ||
33 | + url: '/product/opt/favoriteProduct', | ||
34 | + data: { | ||
35 | + id: productId, | ||
36 | + opt: opt | ||
37 | + }, | ||
38 | + success: function(data) { | ||
39 | + if (data.code === 200) { | ||
40 | + $this.toggleClass('liked'); | ||
41 | + | ||
42 | + if ('cancel' === opt) { | ||
43 | + tip.show('取消收藏成功'); | ||
44 | + } else if ('ok' === opt) { | ||
45 | + tip.show('收藏成功'); | ||
46 | + } | ||
47 | + } else if (data.code === 400) { | ||
48 | + location.href = data.data;// 未登录跳转登录页 | ||
49 | + } else { | ||
50 | + tip.show(data.message); | ||
51 | + } | ||
52 | + }, | ||
53 | + error: function() { | ||
54 | + tip.show('网络断开连接了~'); | ||
55 | + } | ||
56 | + }); | ||
57 | + | ||
58 | + // 统计代码:用于统计用户加入或取消商品收藏的动作 | ||
59 | + if (window._yas) { | ||
60 | + window._yas.sendCustomInfo({ | ||
61 | + pd: productId, | ||
62 | + fa: favorite | ||
63 | + }, true); | ||
64 | + } | ||
65 | + | ||
66 | + return false; | ||
67 | +}); | ||
68 | + | ||
69 | +$('#addtoCart').on('touchstart', function() { | ||
70 | + $('.cart-bar').hide(); | ||
71 | + productCode && chosePanel.setLimitGoodModeWithSknId(productCode, skn); | ||
72 | + chosePanel.show(); | ||
73 | + | ||
74 | + // 统计代码:用于统计用户加入购物车的动作 | ||
75 | + if (window._yas) { | ||
76 | + window._yas.sendCustomInfo({ | ||
77 | + pd: productId, | ||
78 | + by: 1 | ||
79 | + }, true); | ||
80 | + } | ||
81 | + | ||
82 | + return false; | ||
83 | +}); |
public/js/recommend-for-you-product-desc.js
0 → 100644
1 | +/** | ||
2 | + * 为您优选 | ||
3 | + * @author: liangzhifeng<zhifeng.liang@yoho.cn> | ||
4 | + * @date: 2015/11/16 | ||
5 | + */ | ||
6 | + | ||
7 | + | ||
8 | +var Swiper = require('yoho-swiper'), | ||
9 | + $ = require('yoho-jquery'); | ||
10 | + | ||
11 | +var recommendSwiper, | ||
12 | + $recommendForYou = $('.recommend-for-you'), | ||
13 | + preferenceUrl = $('#preferenceUrl').val(), | ||
14 | + winH = $(window).height(), | ||
15 | + end = false, | ||
16 | + requesting = false; | ||
17 | + | ||
18 | + | ||
19 | +function request() { | ||
20 | + if (requesting || end) { | ||
21 | + return; | ||
22 | + } | ||
23 | + | ||
24 | + requesting = true; | ||
25 | + | ||
26 | + if (preferenceUrl) { | ||
27 | + $.get(preferenceUrl).then(function(html) { | ||
28 | + if (html.length < 5) { | ||
29 | + $recommendForYou.css('display', 'none'); | ||
30 | + } else { | ||
31 | + $recommendForYou.html(html).show(); | ||
32 | + if ($('#swiper-recommend').length) { | ||
33 | + recommendSwiper = new Swiper('#swiper-recommend', { | ||
34 | + slidesPerView: 'auto', | ||
35 | + grabCursor: true, | ||
36 | + slideElement: 'a', | ||
37 | + lazyLoading: true, | ||
38 | + watchSlidesVisibility: true | ||
39 | + }); | ||
40 | + } | ||
41 | + } | ||
42 | + | ||
43 | + requesting = false; | ||
44 | + end = true; | ||
45 | + | ||
46 | + window.rePosFooter(); | ||
47 | + | ||
48 | + }).fail(function() { | ||
49 | + $recommendForYou.hide(); | ||
50 | + }); | ||
51 | + } | ||
52 | +} | ||
53 | + | ||
54 | +function scrollHandler() { | ||
55 | + if (!end || $(window).scrollTop() + winH >= $(document).height() - 200) { | ||
56 | + request(); | ||
57 | + } | ||
58 | +} | ||
59 | + | ||
60 | +$(window).scroll(function() { | ||
61 | + window.requestAnimationFrame(scrollHandler); | ||
62 | +}); |
@@ -156,7 +156,7 @@ $basicBtnC:#eb0313; | @@ -156,7 +156,7 @@ $basicBtnC:#eb0313; | ||
156 | background-color: #fff; | 156 | background-color: #fff; |
157 | color: #000; | 157 | color: #000; |
158 | } | 158 | } |
159 | - .soonSoldOut-tag { | 159 | + .soon-sold-out-tag { |
160 | background-color: #ffac5b; | 160 | background-color: #ffac5b; |
161 | color: #fff; | 161 | color: #fff; |
162 | } | 162 | } |
@@ -212,7 +212,7 @@ $basicBtnC:#eb0313; | @@ -212,7 +212,7 @@ $basicBtnC:#eb0313; | ||
212 | } | 212 | } |
213 | } | 213 | } |
214 | } | 214 | } |
215 | - .goodsName { | 215 | + .goods-name { |
216 | box-sizing: border-box; | 216 | box-sizing: border-box; |
217 | width: 100%; | 217 | width: 100%; |
218 | font-size: 28px; | 218 | font-size: 28px; |
@@ -221,7 +221,7 @@ $basicBtnC:#eb0313; | @@ -221,7 +221,7 @@ $basicBtnC:#eb0313; | ||
221 | line-height: 48px; | 221 | line-height: 48px; |
222 | background-color: #515150; | 222 | background-color: #515150; |
223 | } | 223 | } |
224 | - .goodsSubtitle { | 224 | + .goods-subtitle { |
225 | /*display: table;*/ | 225 | /*display: table;*/ |
226 | height: 88px; | 226 | height: 88px; |
227 | font-size: 24px; | 227 | font-size: 24px; |
@@ -296,11 +296,11 @@ $basicBtnC:#eb0313; | @@ -296,11 +296,11 @@ $basicBtnC:#eb0313; | ||
296 | display: inline-block; | 296 | display: inline-block; |
297 | line-height: 88px; | 297 | line-height: 88px; |
298 | } | 298 | } |
299 | - .currentPrice { | 299 | + .current-price { |
300 | color: #d0021b; | 300 | color: #d0021b; |
301 | margin-right: 10px; | 301 | margin-right: 10px; |
302 | } | 302 | } |
303 | - .previousPrice { | 303 | + .previous-price { |
304 | text-decoration: line-through; | 304 | text-decoration: line-through; |
305 | } | 305 | } |
306 | } | 306 | } |
-
Please register or login to post a comment