Authored by mark

add consult dialog

... ... @@ -142,7 +142,20 @@ const isFavShop = (req, res, next) => {
};
const num = (req, res, next) => {
let bid = req.query.bid;
let sid = req.query.sid;
if (sid) {
return brandService.getShopFavNumAsync(sid).then((result) => {
res.json(result);
}).catch(next);
}
if (bid) {
return brandService.getBrandFavNumAsync(bid).then((result) => {
res.json(result);
}).catch(next);
}
};
module.exports = {
... ...
... ... @@ -33,6 +33,7 @@ const homeService = require('./home-service');
const HeaderModel = require('../../../doraemon/models/header');
const BLANK_STR = ' ';
const BUNDLE_PRODUCE = 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商品的总数
... ... @@ -826,10 +839,12 @@ const _getDetailDataBySizeInfo = (sizeInfo) => {
// 图片换成懒加载方式
const replacePairs = {
'<img src=': '<img class="lazy" src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f' +
'///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" data-original=',
'<img border="0" src=': '<img border="0" class="lazy" src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP' +
'///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" data-original='
'<img src=': '<img class="lazy img-responsive" width="765" height="200" ' +
'src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" ' +
'data-original=',
'<img border="0" src=': '<img border="0" class="lazy img-responsive" width="200" height="574" ' +
'src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" ' +
'data-original='
};
let intro = _.get(sizeInfo, 'productIntroBo.productIntro', '');
... ... @@ -1102,6 +1117,7 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => {
result.name = propOrigin('product_name');
result.skn = propOrigin('product_skn');
result.productId = propOrigin('product_id');
result.shopId = propOrigin('shop_id', 0);
result.maxSortId = propOrigin('maxSortId', '');
result.smallSortId = propOrigin('smallSortId', '');
... ... @@ -1118,7 +1134,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 +1161,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 +1319,15 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => {
result.addToCart = false;
}
// 量贩促销短语
result.bundle = _getBundleAsync(bundle);
if (result.bundle.type === BUNDLE_PRODUCE) {
result.activity.unshift({
type: '量贩销售',
des: result.bundle.phrase
});
}
// 电子票
result.isTicket = propOrigin('product_skn') === YOHOOD_TICKET;
if (virtualGoods && result.isTicket) {
... ... @@ -1585,6 +1612,8 @@ const getPackage = (skn) => {
})();
};
module.exports = {
getShareOrderListAsync: commentService.getShareOrderListAsync, // 获取评论列表
indexConsultAsync: consultService.indexAsync, // 获取咨询列表
... ...
... ... @@ -5,6 +5,8 @@
'use strict';
const api = require('./favorite-api');
const serviceApi = global.yoho.ServiceAPI;
const _ = require('lodash');
const isFavoriteAsync = _.partial(api.isFavAsync, _, _, 'brand');
... ... @@ -13,8 +15,24 @@ const addFavAsync = _.partial(api.addFavAsync, _, _, 'brand');
const cancelFavAsync = _.partial(api.cancelFavAsync, _, _, 'brand');
const getShopFavNumAsync = (sid) => {
return serviceApi.get('brower/favorite/queryFavoriteCountByShopIds', {
favIds: [sid],
type: 'shop'
});
};
const getBrandIdNumAsync = (bid) => {
return serviceApi.get('brower/favorite/queryBrandFavoriteCountByBrandId', {
brandId: bid,
type: 'brand'
});
};
module.exports = {
isFavoriteAsync,
addFavAsync,
cancelFavAsync
cancelFavAsync,
getShopFavNumAsync,
getBrandIdNumAsync
};
... ...
... ... @@ -5,6 +5,7 @@
'use strict';
const api = require('./favorite-brand-api');
const _ = require('lodash');
const changeAsync = (type, uid, brandId) => {
switch (type) {
... ... @@ -17,10 +18,48 @@ const changeAsync = (type, uid, brandId) => {
}
};
const getShopFavNumAsync = (sid) => {
return api.getShopFavNumAsync(sid).then((result) => {
if (result.code === 200) {
return {
code: 200,
data: {
count: _.get(result, 'data.count')
}
};
} else {
return {
code: 500,
message: '服务器错误'
};
}
});
};
const getBrandFavNumAsync = (bid) => {
return api.getBrandIdNumAsync(bid).then((result) => {
if (result.code === 200) {
return {
code: 200,
data: {
count: _.get(result, 'data.count')
}
};
} else {
return {
code: 500,
message: '服务器错误'
};
}
});
};
const isFavoriteAsync = api.isFavoriteAsync;
module.exports = {
changeAsync,
isFavoriteAsync
isFavoriteAsync,
getShopFavNumAsync,
getBrandFavNumAsync
};
... ...
... ... @@ -71,7 +71,7 @@ router.get('/detail/header', detail.productHeader); // 价
router.get('/detail/return', detail.detailReturn); // 特殊商品退换货
router.get('/detail/recommend', detail.recommend); // 推荐商品
router.get('/index/isfav', favorite.isFavoriteBrand); // 品牌收藏状态
router.get('/index/favnum', favorite.num); // 收藏数量
router.get('/index/favnum', favorite.num); // 收藏数量(先店铺,后品牌)
router.get('/detail/coupon', auth, coupon.acquire); // 获得优惠券
router.get('/detail/getPacakge', detail.getPackage); // 获取套餐
router.get('/detail/notify/status', auth, notify.show); // 到货通知状态
... ... @@ -103,7 +103,7 @@ router.get('/brand/couponsync', list.brandCouponSync);
router.get('/shoplist', list.shopList); // 店铺列表页
router.post('/shop/togglecollect', favorite.collectShop); // 店铺收藏
router.post('/index/isFavoriteShop', favorite.isFavShop); // 判断用户是否收藏品牌
router.post('/index/isFavoriteShop', favorite.isFavShop); // 判断用户是否收藏店铺
// 品牌页水牌
router.post('/index/getNodeContent', list.getNodeContent);
... ...
... ... @@ -12,7 +12,8 @@
<span class="iconfont">&#xe61a;</span>
</a>
<span id="brand-favour" class="brand-fav{{#if isCollect}} coled{{/if}}" data-id="{{brandId}}">
<i class="iconfont">&#xe611;&nbsp;11111</i>
<i class="iconfont">&#xe611;</i>
<span></span>
</span>
</div>
</div>
... ... @@ -23,8 +24,14 @@
{{> 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}}"
data-shop="{{goodsInfo.shopId}}">
{{> product/detail-header}}
</div>
{{/if}}
... ...
... ... @@ -4,21 +4,25 @@
{{#if_cond activity.length '>' 3}}
<div class="activity-title">展开全部促销 <span class="iconfont index">&#xe610;</span> </div>
<div class="activity-container"></div>
{{/if_cond}}
<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>
<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>
... ...
... ... @@ -200,6 +200,19 @@ function jumpUrl(url) {
window.location.href = url;
}
function once(fn, context) {
var result;
return function() {
if (fn) {
result = fn.apply(context || this, arguments);
fn = null;
}
return result;
};
}
window.cookie = cookie;
window.setCookie = setCookie;
... ... @@ -220,5 +233,7 @@ window.registerUrl = registerUrl;
window.jumpUrl = jumpUrl;
window.once = once;
require('./header');
require('./footer');
... ...
... ... @@ -16,30 +16,35 @@ var yas = require('../common/data-yas');
var dataLazyLoad = require('../plugins/lazy-load')(document);
var setPager = require('./detail/pager');
var notify = require('./detail/notify');
var favorite = require('./detail/brand-fav');
var bindEvent = $.Callbacks(); // eslint-disable-line
var clickAcquireCouponEvent = $.Callbacks('unique'); // eslint-disable-line
var Dialog = require('../common/dialog').Dialog;
var $main = $('.main'),
id = $main.data('id'),
shopId = $main.data('shop'),
brandId = $('#brand-favour').data('id'),
md5 = $main.data('md5'),
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 maxStock = -1; // 记录当前选中的颜色-尺码的库存量,若为-1,代表未选择尺码
var SLIDETIME = 200;
var colTxt = {
def: '收藏商品',
normal: '收藏商品',
coled: '已收藏',
hover: '取消收藏'
};
var oldtatus = {
var oldStatus = {
txt: '已领取',
html: '<a class="coupon-btn">去使用</a>'
};
... ... @@ -99,15 +104,61 @@ bindEvent.add(function() {
var isTicket = $('input[name="isTicket"]').length > 0 && $('input[name="isTicket"]').val() === 'true';
var brandDomain = $('.home').attr('href');
var Alert = require('../common/dialog').Alert;
var $moreCoupon = $('.more-coupon');
/** 优惠券开始 **/
var $moreCoupon = $('.more-coupon'),
$couponItem = $('.coupon-item');
var $couponItem = $('.coupon-item');
function getCouponAsync(cid) {
var uid = getUid(); // eslint-disable-line
if (!uid) {
return $.Deferred().reject({data: {refer: window.signinUrl()}}).promise(); // eslint-disable-line
}
return $.getJSON('/product/detail/coupon', {
couponId: cid
}).then(function(result) {
var defer = $.Deferred(); //eslint-disable-line
if (result.code === 200) {
defer.resolve();
} else {
defer.reject(result);
}
return defer.promise();
});
}
function acquireCoupon($ele) {
var couponId = $ele.data('id');
var i = $ele.data('i');
var $item = $($couponItem.get(i));
var status = $item.data('status');
switch (status) {
case 1:
getCouponAsync(couponId).then(function() {
$ele.find('.coupon-status').text(oldStatus.txt);
$ele.find('.coupon-go').empty().append(oldStatus.html);
$item.data('status', 3);
}).fail(function(err) {
if (err.data && err.data.refer) {
return window.jumpUrl(err.data.refer);
}
alert(err.message);
});
break;
default:
window.jumpUrl(brandDomain);
}
}
function openCouponDialog(e) {
var $coupons = $couponItem.map(function(i) {
... ... @@ -144,14 +195,24 @@ bindEvent.add(function() {
}
};
new Dialog({
var dialog = new Dialog({
content: dialogTpl({coupon: couponData}),
className: 'coupon-big'
}).show();
});
dialog.$el.on('click', '.status', function() {
acquireCoupon($(this));
});
dialog.show();
e.stopPropagation();
}
// 打开优惠券列表
$moreCoupon.on('click', openCouponDialog);
/** 优惠券结束 **/
function getSku() {
return $('.size:not(.hide) li.focus').data('sku');
}
... ... @@ -226,6 +287,8 @@ bindEvent.add(function() {
move(e);
});
// 细节图结束
// 促销弹出框
var icon = { // eslint-disable-line
unfold: '&#xe610;',
... ... @@ -234,17 +297,8 @@ bindEvent.add(function() {
$('.activity-title').click(function() {
$(this).toggleClass('active');
$('.activity-container').empty();
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);
... ... @@ -252,43 +306,22 @@ bindEvent.add(function() {
}
});
function getCouponAsync(cid) {
var uid = getUid(); // eslint-disable-line
if (!uid) {
return $.Deferred().reject({data: {refer: window.signinUrl()}}).promise(); // eslint-disable-line
}
return $.getJSON('/product/detail/coupon', {
couponId: cid
}).then(function(result) {
var defer = $.Deferred(); //eslint-disable-line
if (result.code === 200) {
defer.resolve();
} else {
defer.reject(result);
}
return defer.promise();
});
}
/**
* 获取当前选择的商品数目
* @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');
... ... @@ -312,44 +345,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');
}
}
... ... @@ -477,24 +479,100 @@ 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() {
// 尺码帮助
$('body,html').animate({
scrollTop: $('.size-info').offset().top
}, 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()})
};
var dialog = new Dialog(opt); // eslint-disable-line
var FAV = { //eslint-disable-line
checked: '&#xe613;',
unchecked: '&#xe612;'
};
new Dialog(opt).show();
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();
});
// 增加购买数量
... ... @@ -640,7 +718,7 @@ bindEvent.add(function() {
$this.toggleClass('coled');
if (cancel) {
$this.find('em').text(colTxt.def);
$this.find('em').text(colTxt.normal);
} else {
$this.find('em').text(colTxt.coled);
}
... ... @@ -776,39 +854,6 @@ bindEvent.add(function() {
$sizes.eq($('.colors .focus').index()).find('li').click();
}
}());
// 打开优惠券列表
$moreCoupon.on('click', openCouponDialog);
function acquireCoupon($ele) {
var couponId = $ele.data('id');
var i = $ele.data('i');
var $item = $($couponItem.get(i));
var status = $item.data('status');
switch (status) {
case 1:
getCouponAsync(couponId).then(function() {
$ele.find('.coupon-status').text(oldtatus.txt);
$ele.find('.coupon-go').empty().append(oldtatus.html);
$item.data('status', 3);
}).fail(function(err) {
if (err.data && err.data.refer) {
return window.jumpUrl(err.data.refer);
}
alert(err.message);
});
break;
default:
window.jumpUrl(brandDomain);
}
}
// 清除原来的事件,增加新的事件
clickAcquireCouponEvent.empty();
clickAcquireCouponEvent.add(acquireCoupon);
});
// yas
... ... @@ -816,29 +861,22 @@ require('../common');
require('./detail/latest-walk'); // 最近浏览
// 优惠券的领取
$(document).on('click', '.status', function() {
clickAcquireCouponEvent.fire($(this));
});
// 品牌收藏
$('#brand-favour').click(function() {
var $this = $(this);
var type = $this.hasClass('coled') ? BRAND_FAV.cancel : BRAND_FAV.add;
$.ajax({
type: 'POST',
url: '/product/index/favoriteBrand',
data: {
brandId: $this.data('id'),
type: type
}
}).then(function(data) {
if (data.code === 200) {
$this.toggleClass('coled');
} else if (data.code === 403) {
location.href = data.data.url;
(function() {
switch (type) {
case BRAND_FAV.add:
return favorite.addFav(shopId, brandId);
case BRAND_FAV.cancel:
return favorite.cancelFav(shopId, brandId);
default:
return $.Deferred.reject().promise();
}
}()).then(function() {
$this.toggleClass('coled');
});
});
... ... @@ -848,18 +886,16 @@ $('.after-service-switch').click(function() {
$content = $this.next('.after-service-content');
var html = {
def: '&#xe610;',
spread: '&#xe615;'
down: '&#xe610;',
up: '&#xe615;'
};
if ($content.css('display') === 'none') {
$content.slideDown(SLIDETIME);
$this.find('.triangle').html(html.spread);
$this.find('.triangle').html(html.up);
} else {
$content.slideUp(SLIDETIME);
$this.find('.triangle').html(html.def);
$this.find('.triangle').html(html.down);
}
});
... ... @@ -1011,7 +1047,7 @@ function fetchComment() {
}
}).then(function(data) {
var res;
var totalnum;
var totalNum;
var baseUrl = '/product/detail/consult?productId=' + id + '&filterId=7';
if (data.code === 200) {
... ... @@ -1024,7 +1060,7 @@ function fetchComment() {
// 更新总数显示
$consultNum.text(res[0].total);
totalnum = Math.ceil(res[0].total / 10) * 20;
totalNum = Math.ceil(res[0].total / 10) * 20;
$consultsUl.empty().append(consultsTpl({
consults: res
... ... @@ -1033,20 +1069,20 @@ 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
}).then(function(data) {
if (data && data.code === 400) {
return window.jumpUrl(data.data.refer);
url: '/product/detail/consult/like/' + cid
}).then(function(result) {
if (result && result.code === 400) {
return window.jumpUrl(result.data.refer);
}
if (data && data.code === 200) {
if (result && result.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>');
}
... ... @@ -1056,20 +1092,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
}).then(function(data) {
if (data && data.code === 400) {
url: '/product/detail/consult/useful/' + cid
}).then(function(result) {
if (result && result.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>');
if (result && result.code === 200) {
$('.zan-content .usefulData[data-id=' + cid + '] .usefulNum')
.replaceWith('<em class="usefulNum">' + (useful + 1) + '</em>');
}
});
... ... @@ -1077,10 +1115,9 @@ function fetchComment() {
baseUrl = '/product/detail/consult?productId=' + id + '&filterId=7';
$('.consults-devide').empty().append(
setPager({baseUrl: baseUrl,
totalRecords: totalnum,
totalRecords: totalNum,
page: nowPage,
type: 'ellipsis',
theme: 'msg-pager'
... ... @@ -1113,8 +1150,6 @@ function fetchComment() {
}
});
// 我要咨询
$('#consults-btn').click(function() {
... ... @@ -1461,6 +1496,7 @@ $('.package-box').on('click', '#buy-detail', function() {
});
});
// 店铺推荐和最近浏览
$('.bottom-tab').on('click', '.bottom-title', function() {
var $this = $(this),
index = $this.index();
... ... @@ -1483,12 +1519,14 @@ $('.bottom-tab').on('click', '.bottom-title', function() {
// 店铺推荐
$recommendComment.slideDown(SLIDETIME);
$latestWalk.slideUp(SLIDETIME);
$('.change').css('display', 'inline-block');
} else {
// 最近游览
fetchLatestWalk(); // eslint-disable-line
$recommendComment.slideUp(SLIDETIME);
$latestWalk.slideDown(SLIDETIME);
$('.change').css('display', 'none');
}
... ... @@ -1540,19 +1578,13 @@ bindEvent.fire();
}
});
// 品牌收藏
$.ajax({
type: 'GET',
url: '/product/index/isfav',
data: {
brandId: $('#brand-favour').data('id')
}
}).then(function(result) {
if (result.code === 200 && result.data) {
$('#brand-favour').addClass('coled');
}
favorite.getFavNum(shopId, brandId).then(function(result) {
$('#brand-favour').find('span').html(result.count);
});
favorite.statusFav(shopId, brandId).then(function() {
$('#brand-favour').addClass('coled');
});
}());
$(window).scroll(function() {
... ... @@ -1601,6 +1633,7 @@ $('.shoppingCar').on('click', '.option', function(e) {
$this.addClass('fixed');
});
$('.shoppingCar-btn').on('click', function() {
var $addToCart = $('#add-to-cart');
var sc = $(document);
... ...
var $ = require('yoho-jquery');
exports.getFavNum = function(sid, bid) {
return $.getJSON('/product/index/favnum', {sid: sid, bid: bid})
.then(function(result) {
if (result.code === 200) {
return result.data.count;
} else {
return $.Deferred().reject().promise();// eslint-disable-line
}
});
};
exports.addFav = function(sid, bid) {
if (!getUid()) {// eslint-disable-line
return $.Deferred().reject(window.jumpUrl(window.signinUrl())).promise(); // eslint-disable-line
}
if (sid) {
return $.post('/product/shop/togglecollect', {
isFavorite: 0,
shopId: sid
}).then(function(result) {
if (result.code === 200) {
return $.Deferred().resolve().promise(); //eslint-disable-line
} if (result.code === 401) {
return window.jumpUrl(window.signinUrl());
} else {
return $.Deferred().reject().promise();//eslint-disable-line
}
});
}
if (bid) {
return $.post('/product/index/favoriteBrand', {
type: 'add',
brandId: bid
}).then(function(result) {
if (result.code === 200) {
return $.Deferred().resolve().promise();//eslint-disable-line
} else if (result.code === 403) {
return window.jumpUrl(window.signinUrl());
} else {
return $.Deferred().reject().promise();//eslint-disable-line
}
});
}
};
exports.cancelFav = function(sid, bid) {
if (!getUid()) {// eslint-disable-line
return $.Deferred().reject(window.jumpUrl(window.signinUrl())).promise();// eslint-disable-line
}
if (sid) {
return $.post('/product/shop/togglecollect', {
isFavorite: 1,
shopId: sid
}).then(function(result) {
if (result.code === 200) {
return $.Deferred().resolve().promise();//eslint-disable-line
}
if (result.code === 401) {
return window.jumpUrl(window.signinUrl());
} else {
return $.Deferred().reject().promise();//eslint-disable-line
}
});
}
if (bid) {
return $.post('/product/index/favoriteBrand', {
type: 'cancel',
brandId: bid
}).then(function(result) {
if (result.code === 200) {
return $.Deferred().resolve().promise();//eslint-disable-line
} else if (result.code === 403) {
return window.jumpUrl(window.signinUrl());
} else {
return $.Deferred().reject().promise();//eslint-disable-line
}
});
}
};
exports.statusFav = function(sid, bid) {
if (sid) {
return $.post('/product/index/isFavoriteShop', {
shopId: sid
}).then(function(result) {
if (result.code === 200) {
return $.Deferred().resolve().promise();//eslint-disable-line
} else {
return $.Deferred().reject().promise();//eslint-disable-line
}
});
}
if (bid) {
return $.getJSON('/product/index/isfav', {
brandId: bid
}).then(function(result) {
if (result.code === 200) {
return $.Deferred().resolve().promise();//eslint-disable-line
} else {
return $.Deferred().reject().promise();//eslint-disable-line
}
});
}
};
... ...
... ... @@ -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
exports = {
statusAsync: statusAsync,
addAsync: addAsync
};
... ...
... ... @@ -108,7 +108,7 @@ module.exports = function(opts) {
if ($.isArray(arr) && arr.length) {
arr.forEach((val) => {
arr.forEach(function(val) {
if (val === '.') {
ret += '<a>...</a>';
} else {
... ...
... ... @@ -452,6 +452,7 @@
}
li {
margin-bottom: 5px;
margin-right: 10px;
cursor: pointer;
border: 1px solid #eaeceb;
... ... @@ -802,10 +803,12 @@
.good-info .good-detail-text > .price {
text-align: center;
font-weight: bold;
margin-top: 0;
}
.good-info .good-detail-text > a {
height: 40px;
margin-top: 5px;
}
.package-priceList {
... ... @@ -821,16 +824,16 @@
}
.save-text {
margin-top: 10px;
margin-top: 15px;
}
.buy-product {
margin-top: 40px;
margin-top: 30px;
border-color: #d42838;
}
> p {
line-height: 25px;
line-height: 30px;
font-size: 14px;
}
}
... ... @@ -2342,6 +2345,10 @@
float: left;
width: 350px;
margin-left: 15px;
.pkg-colors, .pkg-sizes {
width: 306px;
}
}
.row {
... ... @@ -2429,6 +2436,7 @@
font-size: 15px;
line-height: 33px;
margin-right: 20px;
cursor: pointer;
}
.cancel {
... ... @@ -2438,10 +2446,12 @@
height: 33px;
font-size: 15px;
line-height: 33px;
cursor: pointer;
}
}
}
.consult-alert{
width: 500px;
background-color: #fff;
... ... @@ -2511,3 +2521,9 @@
}
}
}
.img-responsive {
display: block;
height: auto;
max-width: 100%
}
... ...