Authored by htoooth

add notify

... ... @@ -33,6 +33,7 @@ const homeService = require('./home-service');
const HeaderModel = require('../../../doraemon/models/header');
const BLANK_STR = ' ';
const BUNDLE_PROUDCE = 2;
// 展览票
const YOHOOD_TICKET = 51335912;
... ... @@ -200,6 +201,14 @@ const _getProductActivityBanner = (additionalData) => {
};
};
const _getBundleAsync = (data) => {
return {
count: _.get(data, 'bundleInfo.bundleCount', 1),
phrase: _.get(data, 'bundleInfo.promotionPhrase', ''),
type: _.get(data, 'bundleInfo.discountType', 1)
};
};
const _getActivityDataByProductBaseInfo = (data) => {
let result = [];
... ... @@ -336,11 +345,15 @@ const _getSkuDataByProductBaseInfo = (data) => {
size.storage_number = 0;
}
// 是否显示到货通知
size.notify = cur.isSuppled === 'Y' && cur.storage_number === 0 ? 'Y':'N';
goodsGroup.size.push({
name: size.size_name,
sku: size.product_sku,
num: _.parseInt(size.storage_number),
goodsId: size.size_id
goodsId: size.size_id,
notify: size.notify
});
// 单个sku商品的总数
... ... @@ -1118,7 +1131,8 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => {
addition: _getProductAdditionInfoAsync(origin), // 预处理所有的数据
fav: _getProductFavoriteDataAsync(uid, result.productId), // 处理收藏喜欢数据
promotion: productAPI.getPromotionAsync(result.skn), // 打折信息
coupon: couponService.listAsync(propOrigin('brand_info.brand_id'), result.skn, uid) // 优惠券
coupon: couponService.listAsync(propOrigin('brand_info.brand_id'), result.skn, uid), // 优惠券
bundle: productAPI.getBundleAsync(result.skn) // 量贩
};
if (propOrigin('isLimitBuy', false) && propOrigin('limitProductCode', '')) {
... ... @@ -1144,6 +1158,7 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => {
let coupon = requestData.coupon;
let limitedInfo = requestData.limited;
let domainBrand = requestData.brand;
let bundle = requestData.bundle;
// 商品标签
result.tags = _getTagsDataByProductInfo(origin);
... ... @@ -1301,6 +1316,15 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => {
result.addToCart = false;
}
// 量贩促销短语
result.bundle = _getBundleAsync(bundle);
if (result.bundle.type === BUNDLE_PROUDCE) {
result.activity.unshift({
type: '量贩销售',
des: result.bundle.phrase
});
}
// 电子票
result.isTicket = propOrigin('product_skn') === YOHOOD_TICKET;
if (virtualGoods && result.isTicket) {
... ... @@ -1585,6 +1609,8 @@ const getPackage = (skn) => {
})();
};
module.exports = {
getShareOrderListAsync: commentService.getShareOrderListAsync, // 获取评论列表
indexConsultAsync: consultService.indexAsync, // 获取咨询列表
... ...
... ... @@ -23,8 +23,13 @@
{{> common/path-nav}}
{{#if goodsInfo}}
<div class="main clearfix" data-skn="{{goodsInfo.skn}}" data-id="{{goodsInfo.productId}}"
data-md5="{{goodsInfo.md5}}" data-limitcode="{{goodsInfo.limitProductCode}}">
<div class="main clearfix"
data-skn="{{goodsInfo.skn}}"
data-id="{{goodsInfo.productId}}"
data-md5="{{goodsInfo.md5}}"
data-limitcode="{{goodsInfo.limitProductCode}}"
data-count="{{goodsInfo.bundle.count}}"
data-type="{{goodsInfo.bundle.type}}">
{{> product/detail-header}}
</div>
{{/if}}
... ...
... ... @@ -4,21 +4,24 @@
{{#if_cond activity.length '>' 3}}
<div class="activity-title">展开全部促销 <span class="iconfont index">&#xe610;</span> </div>
<div class="activity-container"></div>
<div class="activity-container">
<ul class="activity">
{{#each activity}}
<li class="promotion-item">
<span class="ac-type">{{type}}</span>
<span class="ac-des">{{des}}</span>
</li>
{{/each}}
</ul>
</div>
{{/if_cond}}
<div class="pull-left">
<ul class="activity">
{{#each activity}}
<li class="promotion-item {{#if_cond @index '>=' 3}}hide{{/if_cond}}">
{{#if activityImg}}
<a class="img-link" href="{{url}}">
<img src="{{activityImg}}">
</a>
{{^}}
<span class="ac-type">{{type}}</span>
<span class="ac-des">{{des}}</span>
{{/if}}
</li>
{{/each}}
</ul>
... ...
... ... @@ -6,8 +6,13 @@
{{#each colors}}
<ul class="size{{#unless focus}} hide{{/unless}}">
{{#each size}}
<li {{#unless num}}class="disable"{{/unless}} data-sku="{{sku}}"
data-num="{{num}}" data-name="{{name}}" data-title="{{title}}">{{name}}</li>
<li {{#unless num}}class="disable"{{/unless}}
data-sku="{{sku}}"
data-num="{{num}}"
data-name="{{name}}"
data-notify="{{notify}}"
data-title="{{title}}">
{{name}}</li>
{{/each}}
<span class="size-warn warn-tip hide"> <i class="iconfont">&#xe61f;</i> 请选择尺码 </span>
... ...
... ... @@ -7,14 +7,15 @@
<div class="content">
商品一旦在 30 日内到货,我们将会第一时间<br/>
通知您,请及时关注哦!
</div>
<div class="content">
<i class="iconfont checked">&#xe613;</i>
<i class="iconfont checked active">&#xe613;</i>
<span>添加收藏夹</span>
</div>
<div class="row">
<a class='ok'>订阅</a>
<a class='cancel'>取消</a>
<a class='ok' data-pid="{{pid}}" data-sku="{{sku}}">订阅</a>
<a class='cancel btn-close'>取消</a>
</div>
</div>
... ...
... ... @@ -28,7 +28,9 @@ var $main = $('.main'),
skn = $main.data('skn'),
deposit = $main.data('deposit') === 'Y',
secKill = $main.data('seckill') === 'Y',
limitCode = $main.data('limitcode');
limitCode = $main.data('limitcode'),
isBundle = $main.data('type') === 2, // 量贩商品
goodsBaseNum = isBundle ? $main.data('count'): 1; // 每次购买最低件数
var SLIDETIME = 200;
... ... @@ -38,7 +40,7 @@ var colTxt = {
hover: '取消收藏'
};
var oldtatus = {
var oldStatus = {
txt: '已领取',
html: '<a class="coupon-btn">去使用</a>'
};
... ... @@ -236,13 +238,6 @@ bindEvent.add(function() {
if ($(this).hasClass('active')) {
$(this).find('span').html(icon.fold);
if (!$('.activity-container').html()) {
$('.activity-container').append($('.activity').clone().find('li').each(function() {
$(this).removeClass('hide');
}).end());
}
$('.activity-container').slideDown(400);
} else {
$(this).find('span').html(icon.unfold);
... ... @@ -274,19 +269,23 @@ bindEvent.add(function() {
/**
* 获取当前选择的商品数目
* @return [Number]
*/
function getNum() {
return +$num.text();
}
// 重置Num显示为1
// 是否能:量贩购买
function canBundleBuy() {
return goodsBaseNum < maxStock;
}
// 重置Num显示为最小购买数
function resetNum() {
$num.text('1');
$num.text(goodsBaseNum + '');
// +-按钮状态重置
if (maxStock === 1 || maxStock === 0) {
if (maxStock === 1 || maxStock === 0 || !canBundleBuy()) {
// 数目为1/0时
$plusNum.addClass('dis');
... ... @@ -310,44 +309,13 @@ bindEvent.add(function() {
}
// 选中的商品存量为0或者某个颜色的total为0
if (maxStock === 0 || ($color && ~~$color.data('total') === 0)) {
if (maxStock === 0 || ($color && ~~$color.data('total') === 0) || !canBundleBuy()) {
$itemBuy.addClass('hide'); // 隐藏加入购物车、即将开售、立即购买等相同位置的按钮
$soldOut.removeClass('hide');
$enableNotifyYou.removeClass('hide');
notify.status(getSku()).then(function(result) {
// 检查当前请求是否是选中的sku
if (result.data.sku !== getSku()) {
return null;
}
if (result.data.status === 'Y') {
$enableNotifyYou.addClass('dis');
$enableNotifyYou.find('span').text('已订阅到货通知');
} else {
$enableNotifyYou.removeClass('dis');
$enableNotifyYou.find('span').text('到货通知');
}
}).fail(function(err) {
if (err.code === 400) {
window.jumpUrl(err.data.refer);
return;
}
// 检查当前请求是否是选中的sku
if (err.data.sku !== getSku()) {
return null;
}
$enableNotifyYou.removeClass('dis');
$enableNotifyYou.find('span').text('到货通知');
});
} else {
// 包括默认的-1情况下
$itemBuy.removeClass('hide');
$soldOut.addClass('hide');
$enableNotifyYou.addClass('hide');
}
}
... ... @@ -475,6 +443,36 @@ bindEvent.add(function() {
switchBtnStatus();
/// 到货通知:状态
if ($this.data('notify') === 'Y') {
$enableNotifyYou.removeClass('hide');
notify.statusAsync(getSku()).then(function(result) {
// 检查当前请求是否是选中的sku
if (result.data.sku !== getSku()) {
return null;
}
if (result.data.status === 'Y') {
$enableNotifyYou.addClass('dis');
$enableNotifyYou.find('span').text('已订阅到货通知');
} else {
$enableNotifyYou.removeClass('dis');
$enableNotifyYou.find('span').text('到货通知');
}
}).fail(function(err) {
// 检查当前请求是否是选中的sku
if (err.data.sku !== getSku()) {
return null;
}
$enableNotifyYou.removeClass('dis');
$enableNotifyYou.find('span').text('到货通知');
});
} else {
$enableNotifyYou.addClass('hide');
}
resetNum();
}).on('click', '.size-ruler', function() {
... ... @@ -485,14 +483,62 @@ bindEvent.add(function() {
}, 300);
});
// 增加到货通知
$enableNotifyYou.on('click', function() {
var opt = {
if ($enableNotifyYou.hasClass('dis')) {
return;
}
var opt = { //eslint-disable-line
className: 'notify-goods-wrapper',
closeIcon: true,
content: notifyTpl({msg: '测试信息!'})
content: notifyTpl({pid: id, sku: getSku()})
};
new Dialog(opt).show();
var dialog = new Dialog(opt); // eslint-disable-line
var FAV = { //eslint-disable-line
checked: '&#xe613;',
unchecked: '&#xe612;'
};
dialog.$el.on('click', '.ok', function() {
var $this = $(this),
sku = $this.data('sku'),
isFav = dialog.$el.find('.active').length === 1;
notify.addAsync(skn, sku).then(function() {
if (isFav) {
$('#collect-product').triggerHandler('click');
}
$enableNotifyYou.addClass('dis');
$enableNotifyYou.find('span').text('已订阅到货通知');
}).fail(function(err) {
if (err.code === 400) {
window.jumpUrl(err.data.refer);
return;
}
alert(err.message);
}).always(function() {
dialog.close();
});
});
dialog.$el.on('click', '.checked', function() {
var $this = $(this);
$this.toggleClass('active');
if ($this.hasClass('active')) {
$this.html(FAV.checked);
} else {
$this.html(FAV.unchecked);
}
});
dialog.show();
});
// 增加购买数量
... ... @@ -787,8 +833,8 @@ bindEvent.add(function() {
switch (status) {
case 1:
getCouponAsync(couponId).then(function() {
$ele.find('.coupon-status').text(oldtatus.txt);
$ele.find('.coupon-go').empty().append(oldtatus.html);
$ele.find('.coupon-status').text(oldStatus.txt);
$ele.find('.coupon-go').empty().append(oldStatus.html);
$item.data('status', 3);
}).fail(function(err) {
... ... @@ -1031,12 +1077,12 @@ function fetchComment() {
$('#consults-ul .zan-content').on('click', '.cuslike', function() {
var $this = $(this);
var id = $this.data('id');
var cid = $this.data('id');
var like = $this.data('like');
$.ajax({
type: 'GET',
url: '/product/detail/consult/like/' + id
url: '/product/detail/consult/like/' + cid
}).then(function(data) {
if (data && data.code === 400) {
return window.jumpUrl(data.data.refer);
... ... @@ -1044,7 +1090,7 @@ function fetchComment() {
if (data && data.code === 200) {
$this.addClass('getzan');
$('.zan-content .icon-border[data-id=' + id + '] .likeNum')
$('.zan-content .icon-border[data-id=' + cid + '] .likeNum')
.replaceWith('<em class="likeNum">' + (like + 1) + '</em>');
}
... ... @@ -1054,20 +1100,22 @@ function fetchComment() {
$('#consults-ul .zan-content').on('click', '.cususeful', function() {
var $this = $(this);
var id = $this.data('id');
var cid = $this.data('id');
var useful = $this.data('useful');
$this.addClass('getzan');
$.ajax({
type: 'GET',
url: '/product/detail/consult/useful/' + id
url: '/product/detail/consult/useful/' + cid
}).then(function(data) {
if (data && data.code === 400) {
return window.jumpUrl(data.data.refer);
}
if (data && data.code === 200) {
$('.zan-content .usefulData[data-id=' + id + '] .usefulNum')
.replaceWith('<em class="usefulNum">' + (useful + 1) + '</em>');
$('.zan-content .usefulData[data-id=' + cid + '] .usefulNum')
.replaceWith('<em class="usefulNum">' + (useful + 1) + '</em>');
}
});
... ... @@ -1075,7 +1123,6 @@ function fetchComment() {
baseUrl = '/product/detail/consult?productId=' + id + '&filterId=7';
$('.consults-devide').empty().append(
setPager({baseUrl: baseUrl,
totalRecords: totalnum,
... ...
... ... @@ -8,27 +8,47 @@ function statusAsync(sku) {
return $.Deferred().reject({}).promise(); // eslint-disable-line
}
if (!sku) {
return $.Deferred().reject({ // eslint-disable-line
code: 403,
message: '商品错误'
}).promise();
}
return $.getJSON('/product/detail/notify/status', {sku: sku})
.then(function(result) {
if (result.code === 200) {
result.data.sku = sku;
return result;
} else {
return $.Deferred().reject(result).promise(); // eslint-disable-line
}
});
.then(function(result) {
if (result.code === 200) {
result.data.sku = sku;
return result;
} else {
return $.Deferred().reject(result).promise(); // eslint-disable-line
}
});
}
function addAsync(skn, sku) {
return $.post('/product/detail/notify/add', {skn: skn, sku: sku});
}
var uid = getUid();
function cancelAsync(sku) {
return $.post('/product/detail/notify/cancel', {sku: sku});
if (!uid) {
return $.Deferred().reject({ // eslint-disable-line
code: 400,
data: {
refer: window.signinUrl()
}
}).promise();
}
if (skn && sku) {
return $.post('/product/detail/notify/add', {skn: skn, sku: sku});
} else {
return $.Deferred().reject({ // eslint-disable-line
code: 403,
message: '商品错误'
}).promise();
}
}
module.exports = {
statusAsync,
addAsync,
cancelAsync
addAsync
};
... ...
... ... @@ -2391,6 +2391,7 @@
font-size: 15px;
line-height: 33px;
margin-right: 20px;
cursor: pointer;
}
.cancel {
... ... @@ -2400,6 +2401,7 @@
height: 33px;
font-size: 15px;
line-height: 33px;
cursor: pointer;
}
}
}
... ...