Authored by 陈轩

Merge branch 'feature/detail-coupon' into 'release/5.2'

商品领券: 修改 显示条件,并改为amd

领券过滤:
1.  秒杀
2.  限定
3.  定金预售
4.  普通预售

改为amd

See merge request !3
@@ -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 币
@@ -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
@@ -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(),