Merge branch 'release/5.2' of git.yoho.cn:fe/yohobuywap-node into release/5.2
Showing
10 changed files
with
252 additions
and
153 deletions
@@ -10,7 +10,7 @@ exports.index = (req, res, next) => { | @@ -10,7 +10,7 @@ exports.index = (req, res, next) => { | ||
10 | token: params.token, | 10 | token: params.token, |
11 | }).then(result => { | 11 | }).then(result => { |
12 | params.token = result; | 12 | params.token = result; |
13 | - params.uname = decodeURIComponent(params.uname); | 13 | + params.uname = decodeURIComponent(params.uname.replace(/\%/g, escape('%'))); |
14 | params.icon = params.icon || 'https://img11.static.yhbimg.com/yhb-img01/2016/07/05/13/017ec560b82c132ab2fdb22f7cf6f42b83.png?imageView/2/w/{width}/h/{height}'; | 14 | params.icon = params.icon || 'https://img11.static.yhbimg.com/yhb-img01/2016/07/05/13/017ec560b82c132ab2fdb22f7cf6f42b83.png?imageView/2/w/{width}/h/{height}'; |
15 | res.render('myqrcode', { | 15 | res.render('myqrcode', { |
16 | title: '查看二维码', | 16 | title: '查看二维码', |
@@ -38,13 +38,16 @@ const _getUidFromUserAgent = (req) => { | @@ -38,13 +38,16 @@ const _getUidFromUserAgent = (req) => { | ||
38 | */ | 38 | */ |
39 | const _baseShop = (req, res, shopInfo, shopId) => { | 39 | const _baseShop = (req, res, shopInfo, shopId) => { |
40 | 40 | ||
41 | - listModel.getBaseShopData(req.query, shopInfo).then(result => { | 41 | + listModel.getBaseShopData(Object.assign(req.query, { |
42 | + channel: req.yoho.channel | ||
43 | + }), shopInfo).then(result => { | ||
42 | if (result && result.baseShopHome && result.baseShopHome.banner) { | 44 | if (result && result.baseShopHome && result.baseShopHome.banner) { |
43 | if (result.baseShopHome.banner.indexOf('?') < 0) { | 45 | if (result.baseShopHome.banner.indexOf('?') < 0) { |
44 | result.baseShopHome.banner += '?imageMogr2/auto-orient/strip/thumbnail/x150/crop/640x150'; | 46 | result.baseShopHome.banner += '?imageMogr2/auto-orient/strip/thumbnail/x150/crop/640x150'; |
45 | } | 47 | } |
46 | } | 48 | } |
47 | - res.render('search/goods-list', { | 49 | + |
50 | + res.render('search/goods-list', Object.assign({ | ||
48 | module: 'product', | 51 | module: 'product', |
49 | page: 'search-list', | 52 | page: 'search-list', |
50 | pageHeader: headerModel.setNav({ | 53 | pageHeader: headerModel.setNav({ |
@@ -53,12 +56,9 @@ const _baseShop = (req, res, shopInfo, shopId) => { | @@ -53,12 +56,9 @@ const _baseShop = (req, res, shopInfo, shopId) => { | ||
53 | goodList: result, | 56 | goodList: result, |
54 | showDownloadApp: true, | 57 | showDownloadApp: true, |
55 | pageFooter: true, | 58 | pageFooter: true, |
56 | - title: shopInfo.shop_name + '|' + shopInfo.shop_name + '潮流服装服饰-Yoho!Buy有货', | ||
57 | - keywords: shopInfo.shop_name + ',' + shopInfo.shop_name + '服装服饰,' + shopInfo.shop_name + '潮流服装服饰', | ||
58 | - description: shopInfo.shop_name + '|Yoho!Buy有货' + shopInfo.shop_name + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。', | ||
59 | shopId: shopId, | 59 | shopId: shopId, |
60 | shopPage: true | 60 | shopPage: true |
61 | - }); | 61 | + }, result.seoResult)); |
62 | }); | 62 | }); |
63 | 63 | ||
64 | }; | 64 | }; |
@@ -142,19 +142,16 @@ const _shop = (req, res, shopId) => { | @@ -142,19 +142,16 @@ const _shop = (req, res, shopId) => { | ||
142 | // 有领券功能,不缓存 | 142 | // 有领券功能,不缓存 |
143 | res.set('Cache-Control', 'no-cache'); | 143 | res.set('Cache-Control', 'no-cache'); |
144 | 144 | ||
145 | - res.render('shop/index', { | 145 | + res.render('shop/index', Object.assign({ |
146 | module: 'product', | 146 | module: 'product', |
147 | page: 'shop', | 147 | page: 'shop', |
148 | shopIndex: result, | 148 | shopIndex: result, |
149 | shopHeadHide: true, | 149 | shopHeadHide: true, |
150 | gender: req.query.gender, | 150 | gender: req.query.gender, |
151 | channel: req.query.channel, | 151 | channel: req.query.channel, |
152 | - title: result.seoTitle + '|' + result.seoTitle + '潮流服装服饰-Yoho!Buy有货', | ||
153 | - keywords: result.seoTitle + ',' + result.seoTitle + '服装服饰,' + result.seoTitle + '潮流服装服饰', | ||
154 | - description: result.seoTitle + '|Yoho!Buy有货' + result.seoTitle + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。', | ||
155 | shopId: shopId, | 152 | shopId: shopId, |
156 | shopPage: true | 153 | shopPage: true |
157 | - }); | 154 | + }, result.seoResult)); |
158 | 155 | ||
159 | }); | 156 | }); |
160 | } | 157 | } |
@@ -273,11 +270,13 @@ const brand = (req, res, next) => { | @@ -273,11 +270,13 @@ const brand = (req, res, next) => { | ||
273 | if (req.query.from !== 'search' && brandLogo.type === '2' && brandLogo.shopId) { | 270 | if (req.query.from !== 'search' && brandLogo.type === '2' && brandLogo.shopId) { |
274 | _shop(req, res, brandLogo.shopId); | 271 | _shop(req, res, brandLogo.shopId); |
275 | } else { // 获取品牌店铺信息 | 272 | } else { // 获取品牌店铺信息 |
276 | - listModel.getBrandShops(brandId).then(brandShop => { | 273 | + listModel.getBrandShops(brandId, req).then(brandShop => { |
277 | if (brandId === 0) { | 274 | if (brandId === 0) { |
278 | params.query = domain; | 275 | params.query = domain; |
279 | } | 276 | } |
280 | 277 | ||
278 | + params.seoResult = brandShop.seoResult; | ||
279 | + | ||
281 | // 从搜索页过来的,显示搜索框, 和进入品牌引导信息 或者品牌关联多店铺 | 280 | // 从搜索页过来的,显示搜索框, 和进入品牌引导信息 或者品牌关联多店铺 |
282 | if (req.query.from === 'search' || brandShop.length > 0) { | 281 | if (req.query.from === 'search' || brandShop.length > 0) { |
283 | params = _.assign({ | 282 | params = _.assign({ |
@@ -304,7 +303,7 @@ const brand = (req, res, next) => { | @@ -304,7 +303,7 @@ const brand = (req, res, next) => { | ||
304 | res.set('Cache-Control', 'no-cache'); | 303 | res.set('Cache-Control', 'no-cache'); |
305 | } | 304 | } |
306 | 305 | ||
307 | - res.render('search/goods-list', { | 306 | + res.render('search/goods-list', Object.assign({ |
308 | module: 'product', | 307 | module: 'product', |
309 | page: 'search-list', | 308 | page: 'search-list', |
310 | pageHeader: headerModel.setNav({ | 309 | pageHeader: headerModel.setNav({ |
@@ -313,12 +312,9 @@ const brand = (req, res, next) => { | @@ -313,12 +312,9 @@ const brand = (req, res, next) => { | ||
313 | goodList: params, | 312 | goodList: params, |
314 | showDownloadApp: true, | 313 | showDownloadApp: true, |
315 | pageFooter: true, | 314 | pageFooter: true, |
316 | - title: title + '|' + title + '潮流服装服饰-Yoho!Buy有货', | ||
317 | - keywords: title + ',' + title + '服装服饰,' + title + '潮流服装服饰', | ||
318 | - description: title + '|Yoho!Buy有货' + title + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。', | ||
319 | domain: req.query.domain, | 315 | domain: req.query.domain, |
320 | shopPage: true | 316 | shopPage: true |
321 | - }); | 317 | + }, params.seoResult)); |
322 | }); | 318 | }); |
323 | } | 319 | } |
324 | }).catch(next); | 320 | }).catch(next); |
@@ -1470,7 +1470,15 @@ const _detailDataPkg = (origin, ua) => { | @@ -1470,7 +1470,15 @@ const _detailDataPkg = (origin, ua) => { | ||
1470 | dest.introUrl = '/product/detail/intro/' + origin.product_skn; | 1470 | dest.introUrl = '/product/detail/intro/' + origin.product_skn; |
1471 | dest.id = origin.product_id; | 1471 | dest.id = origin.product_id; |
1472 | dest.goodsId = origin.goods_id; | 1472 | dest.goodsId = origin.goods_id; |
1473 | + dest.isDepositAdvance = origin.is_deposit_advance === 'Y'; // 是否定金预售 | ||
1474 | + dest.isSeckill = origin.is_secKill === 'Y'; // 是否秒杀 | ||
1475 | + dest.isLimitBuy = origin.isLimitBuy; // 是否 限购 | ||
1476 | + dest.isPresale = Boolean(origin.expect_arrival_time); // 是否普通预售 | ||
1473 | 1477 | ||
1478 | + // 自定义 属性 | ||
1479 | + dest.showCoupon = !( | ||
1480 | + dest.isDepositAdvance || dest.isSeckill || dest.isLimitBuy || dest.isPresale | ||
1481 | + ); // 商品有限购、秒杀、定金预售、普通预售 不显示领券 | ||
1474 | 1482 | ||
1475 | 1483 | ||
1476 | return dest; | 1484 | return dest; |
@@ -1586,7 +1594,8 @@ let _detailDataPkgAsync = (origin, uid, vipLevel, ua) => { | @@ -1586,7 +1594,8 @@ let _detailDataPkgAsync = (origin, uid, vipLevel, ua) => { | ||
1586 | } | 1594 | } |
1587 | 1595 | ||
1588 | if (origin.is_secKill) { | 1596 | if (origin.is_secKill) { |
1589 | - dest.isDepositAdvance = origin.is_deposit_advance;// 判断定金预售字段 | 1597 | + dest.isDepositAdvance = origin.isDeposit_advance;// A定金预售字段 = origin.is_deposit_advance === 'Y'; // 是否定金预售 |
1598 | + dest.isPresale = Boolean(origin.expect_arrival_time) | ||
1590 | } | 1599 | } |
1591 | 1600 | ||
1592 | // 商品返回 YOHO 币 | 1601 | // 商品返回 YOHO 币 |
@@ -51,7 +51,11 @@ const _processBrandShops = (list) => { | @@ -51,7 +51,11 @@ const _processBrandShops = (list) => { | ||
51 | */ | 51 | */ |
52 | const _modifyWapUrl = (origin, shopId) => { | 52 | const _modifyWapUrl = (origin, shopId) => { |
53 | if (parseInt(_.get(origin, 'linkType', 0), 10) === 1) { | 53 | if (parseInt(_.get(origin, 'linkType', 0), 10) === 1) { |
54 | - return helpers.urlFormat('', {filter_poolId: origin.categoryId, shop_id: shopId, title: origin.categoryName}, 'search'); //eslint-disable-line | 54 | + return helpers.urlFormat('', { |
55 | + filter_poolId: origin.categoryId, | ||
56 | + shop_id: shopId, | ||
57 | + title: origin.categoryName | ||
58 | + }, 'search'); //eslint-disable-line | ||
55 | } else { | 59 | } else { |
56 | if (_.has(origin, 'url')) { | 60 | if (_.has(origin, 'url')) { |
57 | return origin.url; | 61 | return origin.url; |
@@ -135,7 +139,71 @@ const _getShopCategory = (shopId, channel, gender) => { | @@ -135,7 +139,71 @@ const _getShopCategory = (shopId, channel, gender) => { | ||
135 | }; | 139 | }; |
136 | 140 | ||
137 | /** | 141 | /** |
138 | - * TODO TAR 店铺和品牌收藏状态调用新的接口 | 142 | + * 处理店铺或者品牌 seo 数据 |
143 | + * @param channel | ||
144 | + * @param info | ||
145 | + * @param qs | ||
146 | + * @returns {{}} | ||
147 | + * @private | ||
148 | + */ | ||
149 | +const _getBrandShopSeo = (channel, info, qs) => { | ||
150 | + | ||
151 | + let resData = {}, | ||
152 | + ctype = { | ||
153 | + boys: {fashionType: '男装', brandType: '男生品牌'}, | ||
154 | + girls: {fashionType: '女装', brandType: '女生品牌'}, | ||
155 | + kids: {fashionType: '童装', brandType: '潮童品牌'}, | ||
156 | + lifestyle: {fashionType: '创意生活', brandType: '创意生活品牌'} | ||
157 | + }; | ||
158 | + let params = { | ||
159 | + nameEn: '', | ||
160 | + name: '' | ||
161 | + }; | ||
162 | + | ||
163 | + | ||
164 | + if (info) { | ||
165 | + Object.assign(params, { | ||
166 | + nameEn: _.get(info, 'brand_name_en', ''), | ||
167 | + nameCn: _.get(info, 'brand_name_cn', ''), | ||
168 | + name: _.get(info, 'brand_name', '') | ||
169 | + }); | ||
170 | + params.name = `${params.nameEn} ${params.nameCn} ${params.name}`; | ||
171 | + if (info.shop_name) { | ||
172 | + Object.assign(params, { | ||
173 | + nameEn: info.shop_name, | ||
174 | + name: info.shop_name | ||
175 | + }); | ||
176 | + } | ||
177 | + } | ||
178 | + | ||
179 | + if (qs && qs.gender) { | ||
180 | + if (qs.gender === '1,3') { | ||
181 | + channel = 'boys'; | ||
182 | + } else if (qs.gender === '2,3') { | ||
183 | + channel = 'girls'; | ||
184 | + } | ||
185 | + | ||
186 | + Object.assign(params, ctype[channel] || ctype.boys); | ||
187 | + Object.assign(resData, { | ||
188 | + title: `${params.nameEn} | ${params.name} ${params.brandType}`, | ||
189 | + keywords: `${params.nameEn}, ${params.name} ${params.fashionType},${params.nameEn} ${params.brandType}`, | ||
190 | + description: `${params.nameEn}正品网购。${params.name}官方授权!` | ||
191 | + }); | ||
192 | + } else { | ||
193 | + Object.assign(resData, { | ||
194 | + title: `${params.nameEn} | ${params.name}官网`, | ||
195 | + keywords: `${params.nameEn}, ${params.name}官网`, | ||
196 | + description: `${params.nameEn}正品网购。${params.name}官方授权!` | ||
197 | + }); | ||
198 | + } | ||
199 | + | ||
200 | + resData.title += resData.title ? ' | YOHO!有货 100%正品保证' : ''; | ||
201 | + resData.description += resData.description ? ' YOHO! 有货中国最大的潮流商品购物网站。100%品牌正品保证,支持货到付款。' : ''; // eslint-disable-line | ||
202 | + return resData; | ||
203 | +}; | ||
204 | + | ||
205 | +/** | ||
206 | + * | ||
139 | * 调用接口获取品牌或者店铺的收藏状态 | 207 | * 调用接口获取品牌或者店铺的收藏状态 |
140 | * @private | 208 | * @private |
141 | */ | 209 | */ |
@@ -436,8 +504,11 @@ const _formShopData = (data, shopId, isApp) => { | @@ -436,8 +504,11 @@ const _formShopData = (data, shopId, isApp) => { | ||
436 | */ | 504 | */ |
437 | const getBaseShopData = (params, shopInfo) => { | 505 | const getBaseShopData = (params, shopInfo) => { |
438 | 506 | ||
507 | + /* tar add 161109 seo-info */ | ||
508 | + let seoResult = _getBrandShopSeo(params.channel, shopInfo, params); | ||
439 | let finalResult = { | 509 | let finalResult = { |
440 | - cartUrl: helpers.urlFormat('/cart/index/index') | 510 | + cartUrl: helpers.urlFormat('/cart/index/index'), |
511 | + seoResult: seoResult | ||
441 | }; | 512 | }; |
442 | 513 | ||
443 | let shopId = params.shop_id || shopInfo.shops_id; | 514 | let shopId = params.shop_id || shopInfo.shops_id; |
@@ -490,6 +561,8 @@ const getShopData = (req, shopId, uid, isApp) => { | @@ -490,6 +561,8 @@ const getShopData = (req, shopId, uid, isApp) => { | ||
490 | 561 | ||
491 | return _getShopInfo(shopId, uid).then(shopInfoResult => { | 562 | return _getShopInfo(shopId, uid).then(shopInfoResult => { |
492 | 563 | ||
564 | + let seoResult = _getBrandShopSeo(channel, shopInfoResult, req.query); | ||
565 | + | ||
493 | /* 基础店铺返回程序内的跳转信号,跳转到基础店铺 */ | 566 | /* 基础店铺返回程序内的跳转信号,跳转到基础店铺 */ |
494 | if (shopInfoResult && shopInfoResult.shop_template_type && parseInt(shopInfoResult.shop_template_type, 10) === 1) { | 567 | if (shopInfoResult && shopInfoResult.shop_template_type && parseInt(shopInfoResult.shop_template_type, 10) === 1) { |
495 | return { | 568 | return { |
@@ -515,7 +588,7 @@ const getShopData = (req, shopId, uid, isApp) => { | @@ -515,7 +588,7 @@ const getShopData = (req, shopId, uid, isApp) => { | ||
515 | return Promise.all([ | 588 | return Promise.all([ |
516 | searchModel.getFilterSearchData({ | 589 | searchModel.getFilterSearchData({ |
517 | shop_id: shopId, | 590 | shop_id: shopId, |
518 | - type: 'default',//默认 | 591 | + type: 'default', // 默认 |
519 | brand: brandData.join(','), | 592 | brand: brandData.join(','), |
520 | order: '0', | 593 | order: '0', |
521 | channel: channel | 594 | channel: channel |
@@ -551,7 +624,8 @@ const getShopData = (req, shopId, uid, isApp) => { | @@ -551,7 +624,8 @@ const getShopData = (req, shopId, uid, isApp) => { | ||
551 | { | 624 | { |
552 | shopId: shopId, | 625 | shopId: shopId, |
553 | uid: uid ? crypto.encryption('', uid + '') : '', | 626 | uid: uid ? crypto.encryption('', uid + '') : '', |
554 | - coverChannel: channel | 627 | + coverChannel: channel, |
628 | + seoResult: seoResult | ||
555 | } | 629 | } |
556 | ); | 630 | ); |
557 | }); | 631 | }); |
@@ -662,9 +736,10 @@ const getBrandLogoByDomain = (domain) => { | @@ -662,9 +736,10 @@ const getBrandLogoByDomain = (domain) => { | ||
662 | /** | 736 | /** |
663 | * 根据brandId 获取相关店铺列表 | 737 | * 根据brandId 获取相关店铺列表 |
664 | * @param brandId | 738 | * @param brandId |
739 | + * @param req | ||
665 | * @return array | 740 | * @return array |
666 | */ | 741 | */ |
667 | -const getBrandShops = (brandId) => { | 742 | +const getBrandShops = (brandId, req) => { |
668 | return api.get('', { | 743 | return api.get('', { |
669 | method: 'app.shop.queryShopsByBrandId', | 744 | method: 'app.shop.queryShopsByBrandId', |
670 | brand_id: brandId | 745 | brand_id: brandId |
@@ -673,7 +748,9 @@ const getBrandShops = (brandId) => { | @@ -673,7 +748,9 @@ const getBrandShops = (brandId) => { | ||
673 | cache: true | 748 | cache: true |
674 | }).then(result => { | 749 | }).then(result => { |
675 | if (_.isArray(result.data)) { | 750 | if (_.isArray(result.data)) { |
676 | - return _processBrandShops(result.data); | 751 | + let seoResult = _getBrandShopSeo(req.channel, result.data[0], req.query); |
752 | + | ||
753 | + return Object.assign(_processBrandShops(result.data), {seoResult: seoResult}); | ||
677 | } else { | 754 | } else { |
678 | return []; | 755 | return []; |
679 | } | 756 | } |
@@ -784,9 +861,8 @@ const getShopCategory = (params) => { | @@ -784,9 +861,8 @@ const getShopCategory = (params) => { | ||
784 | 861 | ||
785 | /** | 862 | /** |
786 | * 获取店铺优惠券列表 | 863 | * 获取店铺优惠券列表 |
787 | - * @param {[int]} shop_id 店铺id | ||
788 | - * @param {[int]} uid 当前用户id,空则不传 | ||
789 | * @return {[array]} | 864 | * @return {[array]} |
865 | + * @param params | ||
790 | */ | 866 | */ |
791 | const shopCouponsList = (params) => { | 867 | const shopCouponsList = (params) => { |
792 | return api.get('', Object.assign({ | 868 | return api.get('', Object.assign({ |
@@ -165,6 +165,7 @@ | @@ -165,6 +165,7 @@ | ||
165 | <input id="productSkn" type="hidden" value="{{productSkn}}"> | 165 | <input id="productSkn" type="hidden" value="{{productSkn}}"> |
166 | <input id="brand-id" type="hidden" value="{{brandId}}"> | 166 | <input id="brand-id" type="hidden" value="{{brandId}}"> |
167 | <input id="product-limit" type="hidden" value="{{isLimitBuy}}"> | 167 | <input id="product-limit" type="hidden" value="{{isLimitBuy}}"> |
168 | + <input id="product-coupon-switch" type="hidden" value="{{showCoupon}}"> | ||
168 | 169 | ||
169 | <input type="hidden" class="data-bind" name="loginUrl" id="loginUrl" value=""> | 170 | <input type="hidden" class="data-bind" name="loginUrl" id="loginUrl" value=""> |
170 | 171 |
@@ -19,3 +19,18 @@ function async_load(){ | @@ -19,3 +19,18 @@ function async_load(){ | ||
19 | } | 19 | } |
20 | window.addEventListener('load', async_load, false); | 20 | window.addEventListener('load', async_load, false); |
21 | </script> | 21 | </script> |
22 | + | ||
23 | +<script> | ||
24 | + (function(){ | ||
25 | + var bp = document.createElement('script'); | ||
26 | + var curProtocol = window.location.protocol.split(':')[0]; | ||
27 | + if (curProtocol === 'https') { | ||
28 | + bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; | ||
29 | + } | ||
30 | + else { | ||
31 | + bp.src = 'http://push.zhanzhang.baidu.com/push.js'; | ||
32 | + } | ||
33 | + var s = document.getElementsByTagName("script")[0]; | ||
34 | + s.parentNode.insertBefore(bp, s); | ||
35 | + })(); | ||
36 | +</script> |
@@ -28,3 +28,7 @@ if ($('#remove-cart-count').length) { | @@ -28,3 +28,7 @@ if ($('#remove-cart-count').length) { | ||
28 | }); | 28 | }); |
29 | } | 29 | } |
30 | 30 | ||
31 | +/* tar add 161121 app del suspend cart */ | ||
32 | +if (queryString.app_version || queryString.appVersion) { | ||
33 | + $('.suspend-cart').css('display', 'none'); | ||
34 | +} |
@@ -151,7 +151,9 @@ require('./detail/page-render')(function() { | @@ -151,7 +151,9 @@ require('./detail/page-render')(function() { | ||
151 | $('#yoho-footer').css('border-top', '1px solid #e0e0e0'); | 151 | $('#yoho-footer').css('border-top', '1px solid #e0e0e0'); |
152 | } | 152 | } |
153 | }); | 153 | }); |
154 | -require('./detail/brand-coupon'); | ||
155 | - | ||
156 | - | ||
157 | 154 | ||
155 | +$(function() { | ||
156 | + if ($('#product-coupon-switch').val() === 'true') { | ||
157 | + require(['./detail/brand-coupon']); // amd | ||
158 | + } | ||
159 | +}); |
1 | -'use strict'; | ||
2 | - | ||
3 | -/** | ||
4 | - * 商品详情: 品牌券 | ||
5 | - */ | ||
6 | -var tip = require('plugin/tip'); | ||
7 | -var $ = require('yoho-jquery'); | ||
8 | -var $body = $(document.body); | ||
9 | - | ||
10 | -var brandCoupon = { | ||
11 | - skn: null, | ||
12 | - brandId: null, | ||
13 | - $entry: null, | ||
14 | - $couponDrawer: null, | ||
15 | - | ||
16 | - template: require('product/detail/coupon-list.hbs'), | ||
17 | - | ||
18 | - init: function(skn, brandId) { | ||
19 | - var self = this; | ||
20 | - | ||
21 | - this.skn = skn; | ||
22 | - this.brandId = brandId; | ||
23 | - | ||
24 | - if (!(skn && brandId)) { | ||
25 | - return; | ||
26 | - } | ||
27 | - | ||
28 | - this.fetchCoupons(this.skn, this.brandId) | ||
29 | - .done(function(data) { | ||
30 | - if (data.length) { | ||
31 | - self.render(data); | ||
32 | - self.domInit(); | ||
33 | - self.bindEvents(); | 1 | +/* global define */ |
2 | +// amd | ||
3 | +define(function(require) { | ||
4 | + 'use strict'; | ||
5 | + | ||
6 | + /** | ||
7 | + * 商品详情: 品牌券 | ||
8 | + */ | ||
9 | + var tip = require('plugin/tip'); | ||
10 | + var $ = require('yoho-jquery'); | ||
11 | + var $body = $(document.body); | ||
12 | + | ||
13 | + var brandCoupon = { | ||
14 | + skn: null, | ||
15 | + brandId: null, | ||
16 | + $entry: null, | ||
17 | + $couponDrawer: null, | ||
18 | + | ||
19 | + template: require('product/detail/coupon-list.hbs'), | ||
20 | + | ||
21 | + init: function(skn, brandId) { | ||
22 | + var self = this; | ||
23 | + | ||
24 | + this.skn = skn; | ||
25 | + this.brandId = brandId; | ||
26 | + | ||
27 | + if (!(skn && brandId)) { | ||
28 | + return; | ||
29 | + } | ||
34 | 30 | ||
35 | - self.$entry.removeClass('hide'); | 31 | + this.fetchCoupons(this.skn, this.brandId) |
32 | + .done(function(data) { | ||
33 | + if (data.length) { | ||
34 | + self.render(data); | ||
35 | + self.domInit(); | ||
36 | + self.bindEvents(); | ||
37 | + | ||
38 | + self.$entry.removeClass('hide'); | ||
39 | + } | ||
40 | + }) | ||
41 | + .fail(); | ||
42 | + }, | ||
43 | + | ||
44 | + domInit: function() { | ||
45 | + this.$entry = $('.brand-coupon').removeClass('hide'); | ||
46 | + }, | ||
47 | + | ||
48 | + bindEvents: function() { | ||
49 | + var self = this; | ||
50 | + | ||
51 | + this.$entry.on('click', function() { | ||
52 | + self.toggleDrawer(true); | ||
53 | + }); | ||
54 | + | ||
55 | + this.$couponDrawer | ||
56 | + .on('click', '.coupon-drawer-mask', $.proxy(this.toggleDrawer, this, false)) | ||
57 | + .on('click', '.coupon-btn-valid', $.proxy(this.saveCouponHandler, this)); | ||
58 | + }, | ||
59 | + | ||
60 | + render: function(data) { | ||
61 | + this.$couponDrawer = $(this.template({ | ||
62 | + coupons: data | ||
63 | + })); | ||
64 | + this.$couponDrawer.appendTo('.good-detail-page'); | ||
65 | + | ||
66 | + return this; | ||
67 | + }, | ||
68 | + | ||
69 | + // 获取 品牌券 | ||
70 | + fetchCoupons: function(skn, brandId) { | ||
71 | + return $.get('/product/detail/coupon.json', { | ||
72 | + skn: skn, | ||
73 | + brandId: brandId | ||
74 | + }); | ||
75 | + }, | ||
76 | + | ||
77 | + saveCoupon: function(couponId, callback) { | ||
78 | + $.post('/product/detail/coupon/save.json', { | ||
79 | + couponId: couponId | ||
80 | + }).done(function(res) { | ||
81 | + tip.show(res.message); | ||
82 | + | ||
83 | + if (res.code === 200) { | ||
84 | + callback(); // eslint-disable-line | ||
85 | + } else { | ||
86 | + tip.show( | ||
87 | + res.message || '抱歉,您不符合领用条件' | ||
88 | + ); | ||
89 | + | ||
90 | + if (res.redirect) { | ||
91 | + setTimeout(function() { | ||
92 | + location.href = res.redirect; | ||
93 | + }, 1000); | ||
94 | + } | ||
36 | } | 95 | } |
37 | - }) | ||
38 | - .fail(); | ||
39 | - }, | ||
40 | - | ||
41 | - domInit: function() { | ||
42 | - this.$entry = $('.brand-coupon').removeClass('hide'); | ||
43 | - }, | ||
44 | - | ||
45 | - bindEvents: function() { | ||
46 | - var self = this; | ||
47 | - | ||
48 | - this.$entry.on('click', function() { | ||
49 | - self.toggleDrawer(true); | ||
50 | - }); | ||
51 | - | ||
52 | - this.$couponDrawer | ||
53 | - .on('click', '.coupon-drawer-mask', $.proxy(this.toggleDrawer, this, false)) | ||
54 | - .on('click', '.coupon-btn-valid', $.proxy(this.saveCouponHandler, this)); | ||
55 | - }, | ||
56 | - | ||
57 | - render: function(data) { | ||
58 | - this.$couponDrawer = $(this.template({ | ||
59 | - coupons: data | ||
60 | - })); | ||
61 | - this.$couponDrawer.appendTo('.good-detail-page'); | ||
62 | - | ||
63 | - return this; | ||
64 | - }, | ||
65 | - | ||
66 | - // 获取 品牌券 | ||
67 | - fetchCoupons: function(skn, brandId) { | ||
68 | - return $.get('/product/detail/coupon.json', { | ||
69 | - skn: skn, | ||
70 | - brandId: brandId | ||
71 | - }); | ||
72 | - }, | ||
73 | - | ||
74 | - saveCoupon: function(couponId, callback) { | ||
75 | - $.post('/product/detail/coupon/save.json', { | ||
76 | - couponId: couponId | ||
77 | - }).done(function(res) { | ||
78 | - tip.show(res.message); | ||
79 | - | ||
80 | - if (res.code === 200) { | ||
81 | - callback(); // eslint-disable-line | ||
82 | - } else { | ||
83 | - tip.show( | ||
84 | - res.message || '抱歉,您不符合领用条件' | ||
85 | - ); | ||
86 | - | ||
87 | - if (res.redirect) { | ||
88 | - setTimeout(function() { | ||
89 | - location.href = res.redirect; | ||
90 | - }, 1000); | ||
91 | - } | ||
92 | - } | ||
93 | - }).fail(function() { | ||
94 | - tip.show('网络异常,请稍后再试'); | ||
95 | - }); | ||
96 | - }, | ||
97 | - | ||
98 | - // 收藏 品牌券 | ||
99 | - saveCouponHandler: function(event) { | ||
100 | - var $btn = $(event.target); | ||
101 | - var couponId = $btn.closest('.coupon').data('coupon'); | ||
102 | - | ||
103 | - this.saveCoupon(couponId, function() { | ||
104 | - $btn.prop('disabled', true) | ||
105 | - .removeClass('coupon-btn-valid') | ||
106 | - .text('已领取'); | ||
107 | - }); | ||
108 | - | ||
109 | - event.stopPropagation(); | ||
110 | - }, | ||
111 | - | ||
112 | - toggleDrawer: function(bool) { | ||
113 | - this.$couponDrawer.toggleClass('open', bool); | ||
114 | - $body.toggleClass('coupon-drawer-open', bool); | ||
115 | - } | ||
116 | -}; | ||
117 | - | ||
118 | - | ||
119 | -$(function() { | ||
120 | - if ($('#product-limit').val() !== '0') { // 限购商品 不展示优惠券 | ||
121 | - return; | ||
122 | - } | 96 | + }).fail(function() { |
97 | + tip.show('网络异常,请稍后再试'); | ||
98 | + }); | ||
99 | + }, | ||
100 | + | ||
101 | + // 收藏 品牌券 | ||
102 | + saveCouponHandler: function(event) { | ||
103 | + var $btn = $(event.target); | ||
104 | + var couponId = $btn.closest('.coupon').data('coupon'); | ||
105 | + | ||
106 | + this.saveCoupon(couponId, function() { | ||
107 | + $btn.prop('disabled', true) | ||
108 | + .removeClass('coupon-btn-valid') | ||
109 | + .text('已领取'); | ||
110 | + }); | ||
111 | + | ||
112 | + event.stopPropagation(); | ||
113 | + }, | ||
114 | + | ||
115 | + toggleDrawer: function(bool) { | ||
116 | + this.$couponDrawer.toggleClass('open', bool); | ||
117 | + $body.toggleClass('coupon-drawer-open', bool); | ||
118 | + } | ||
119 | + }; | ||
123 | 120 | ||
124 | brandCoupon.init( | 121 | brandCoupon.init( |
125 | $('#productSkn').val(), | 122 | $('#productSkn').val(), |
-
Please register or login to post a comment