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) => {
dest.introUrl = '/product/detail/intro/' + origin.product_skn;
dest.id = origin.product_id;
dest.goodsId = origin.goods_id;
dest.isDepositAdvance = origin.is_deposit_advance === 'Y'; // 是否定金预售
dest.isSeckill = origin.is_secKill === 'Y'; // 是否秒杀
dest.isLimitBuy = origin.isLimitBuy; // 是否 限购
dest.isPresale = Boolean(origin.expect_arrival_time); // 是否普通预售
// 自定义 属性
dest.showCoupon = !(
dest.isDepositAdvance || dest.isSeckill || dest.isLimitBuy || dest.isPresale
); // 商品有限购、秒杀、定金预售、普通预售 不显示领券
return dest;
... ... @@ -1586,7 +1594,8 @@ let _detailDataPkgAsync = (origin, uid, vipLevel, ua) => {
}
if (origin.is_secKill) {
dest.isDepositAdvance = origin.is_deposit_advance;// 判断定金预售字段
dest.isDepositAdvance = origin.isDeposit_advance;// A定金预售字段 = origin.is_deposit_advance === 'Y'; // 是否定金预售
dest.isPresale = Boolean(origin.expect_arrival_time)
}
// 商品返回 YOHO 币
... ...
... ... @@ -165,6 +165,7 @@
<input id="productSkn" type="hidden" value="{{productSkn}}">
<input id="brand-id" type="hidden" value="{{brandId}}">
<input id="product-limit" type="hidden" value="{{isLimitBuy}}">
<input id="product-coupon-switch" type="hidden" value="{{showCoupon}}">
<input type="hidden" class="data-bind" name="loginUrl" id="loginUrl" value="">
... ...
... ... @@ -151,7 +151,9 @@ require('./detail/page-render')(function() {
$('#yoho-footer').css('border-top', '1px solid #e0e0e0');
}
});
require('./detail/brand-coupon');
$(function() {
if ($('#product-coupon-switch').val() === 'true') {
require(['./detail/brand-coupon']); // amd
}
});
... ...
'use strict';
/**
* 商品详情: 品牌券
*/
var tip = require('plugin/tip');
var $ = require('yoho-jquery');
var $body = $(document.body);
var brandCoupon = {
skn: null,
brandId: null,
$entry: null,
$couponDrawer: null,
template: require('product/detail/coupon-list.hbs'),
init: function(skn, brandId) {
var self = this;
this.skn = skn;
this.brandId = brandId;
if (!(skn && brandId)) {
return;
}
this.fetchCoupons(this.skn, this.brandId)
.done(function(data) {
if (data.length) {
self.render(data);
self.domInit();
self.bindEvents();
/* global define */
// amd
define(function(require) {
'use strict';
/**
* 商品详情: 品牌券
*/
var tip = require('plugin/tip');
var $ = require('yoho-jquery');
var $body = $(document.body);
var brandCoupon = {
skn: null,
brandId: null,
$entry: null,
$couponDrawer: null,
template: require('product/detail/coupon-list.hbs'),
init: function(skn, brandId) {
var self = this;
this.skn = skn;
this.brandId = brandId;
if (!(skn && brandId)) {
return;
}
self.$entry.removeClass('hide');
this.fetchCoupons(this.skn, this.brandId)
.done(function(data) {
if (data.length) {
self.render(data);
self.domInit();
self.bindEvents();
self.$entry.removeClass('hide');
}
})
.fail();
},
domInit: function() {
this.$entry = $('.brand-coupon').removeClass('hide');
},
bindEvents: function() {
var self = this;
this.$entry.on('click', function() {
self.toggleDrawer(true);
});
this.$couponDrawer
.on('click', '.coupon-drawer-mask', $.proxy(this.toggleDrawer, this, false))
.on('click', '.coupon-btn-valid', $.proxy(this.saveCouponHandler, this));
},
render: function(data) {
this.$couponDrawer = $(this.template({
coupons: data
}));
this.$couponDrawer.appendTo('.good-detail-page');
return this;
},
// 获取 品牌券
fetchCoupons: function(skn, brandId) {
return $.get('/product/detail/coupon.json', {
skn: skn,
brandId: brandId
});
},
saveCoupon: function(couponId, callback) {
$.post('/product/detail/coupon/save.json', {
couponId: couponId
}).done(function(res) {
tip.show(res.message);
if (res.code === 200) {
callback(); // eslint-disable-line
} else {
tip.show(
res.message || '抱歉,您不符合领用条件'
);
if (res.redirect) {
setTimeout(function() {
location.href = res.redirect;
}, 1000);
}
}
})
.fail();
},
domInit: function() {
this.$entry = $('.brand-coupon').removeClass('hide');
},
bindEvents: function() {
var self = this;
this.$entry.on('click', function() {
self.toggleDrawer(true);
});
this.$couponDrawer
.on('click', '.coupon-drawer-mask', $.proxy(this.toggleDrawer, this, false))
.on('click', '.coupon-btn-valid', $.proxy(this.saveCouponHandler, this));
},
render: function(data) {
this.$couponDrawer = $(this.template({
coupons: data
}));
this.$couponDrawer.appendTo('.good-detail-page');
return this;
},
// 获取 品牌券
fetchCoupons: function(skn, brandId) {
return $.get('/product/detail/coupon.json', {
skn: skn,
brandId: brandId
});
},
saveCoupon: function(couponId, callback) {
$.post('/product/detail/coupon/save.json', {
couponId: couponId
}).done(function(res) {
tip.show(res.message);
if (res.code === 200) {
callback(); // eslint-disable-line
} else {
tip.show(
res.message || '抱歉,您不符合领用条件'
);
if (res.redirect) {
setTimeout(function() {
location.href = res.redirect;
}, 1000);
}
}
}).fail(function() {
tip.show('网络异常,请稍后再试');
});
},
// 收藏 品牌券
saveCouponHandler: function(event) {
var $btn = $(event.target);
var couponId = $btn.closest('.coupon').data('coupon');
this.saveCoupon(couponId, function() {
$btn.prop('disabled', true)
.removeClass('coupon-btn-valid')
.text('已领取');
});
event.stopPropagation();
},
toggleDrawer: function(bool) {
this.$couponDrawer.toggleClass('open', bool);
$body.toggleClass('coupon-drawer-open', bool);
}
};
$(function() {
if ($('#product-limit').val() !== '0') { // 限购商品 不展示优惠券
return;
}
}).fail(function() {
tip.show('网络异常,请稍后再试');
});
},
// 收藏 品牌券
saveCouponHandler: function(event) {
var $btn = $(event.target);
var couponId = $btn.closest('.coupon').data('coupon');
this.saveCoupon(couponId, function() {
$btn.prop('disabled', true)
.removeClass('coupon-btn-valid')
.text('已领取');
});
event.stopPropagation();
},
toggleDrawer: function(bool) {
this.$couponDrawer.toggleClass('open', bool);
$body.toggleClass('coupon-drawer-open', bool);
}
};
brandCoupon.init(
$('#productSkn').val(),
... ...