Authored by 陈峰

尺码选择框50%

... ... @@ -28,7 +28,7 @@
<img src="{{thumb}}">
</a>
{{# is_soon_sold_out}}
<p class="few-tag">即将售罄</p>
<p class="few-tag ">即将售罄</p>
{{/ is_soon_sold_out}}
{{# is_solded}}
... ...
... ... @@ -681,7 +681,7 @@ let _detailDataPkgAsync = (origin, uid, vipLevel, ua) => {
}
// 商品信息
let cartInfo = productProcess.processSizeInfo(origin);
let cartInfo = productProcess.processSkusInfo(origin);
let soldOut = (origin.storage_sum === 0) || (cartInfo.totalStorageNum === 0); // status
let notForSale = origin.attribute === 2;
let preSale = (origin.status === 0 && origin.advance_shelve_time > 0);
... ...
... ... @@ -10,13 +10,13 @@ const isProduction = process.env.NODE_ENV === 'production';
const isTest = process.env.NODE_ENV === 'test';
const domains = {
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
// api: 'http://api.yoho.cn/',
// service: 'http://service.yoho.cn/',
liveApi: 'http://testapi.live.yohops.com:9999/',
singleApi: 'http://api-test3.yohops.com:9999/',
// api: 'http://dev-api.yohops.com:9999/',
// service: 'http://dev-service.yohops.com:9999/',
api: 'http://dev-api.yohops.com:9999/',
service: 'http://service-test3.yohops.com:9999/',
// liveApi: 'http://api.live.yoho.cn/',
// singleApi: 'http://single.yoho.cn/',
... ...
... ... @@ -5,8 +5,7 @@
<div class="infos {{#if @root.tickets}} tickets-info {{/if}}">
<div class="basic-info">
<div class="thumb-img">
{{#each thumbs}}
<img class="thumb {{#unless @first}}hide{{/unless}}" src="{{img}}"> {{/each}}
<img class="thumb" src="{{defaultThumb}}">
</div>
<div class="text-info">
<p class="price">
... ... @@ -23,25 +22,16 @@
</div>
</div>
<div class="chose-items">
<div class="color-list block-list">
<span class="name">{{#if @root.tickets}}日期{{else}}颜色{{/if}}</span> {{#each colors}}
<ul id="{{id}}" data-index="{{@index}}" class="size-row clearfix {{#unless @first}}hide{{/unless}}">
{{#each color}}
<li class="block {{#if chosed}} chosed{{/if}} {{#unless colorNum}} zero-stock{{/unless}}" data-num="{{colorNum}}">{{name}}</li>
{{/each}}
</ul>
{{/each}}
</div>
<div class="size-list block-list {{#if @root.single}} hide{{/if}}">
<span class="name">{{#if @root.tickets}}区域{{else}}尺码{{/if}}</span> {{#each sizes}}
<ul class="size-row clearfix {{#unless @first}}hide{{/unless}}">
{{#each size}}
<li class="block {{#if chosed}} chosed{{/if}} {{#unless sizeNum}} zero-stock {{/unless}}" data-num="{{sizeNum}}" data-id="{{id}}"
data-skuid="{{skuId}}" data-info="{{sizeInfo}}">{{name}}</li>
{{#each props}}
<div class="block-list">
<span class="name">{{name}}</span>
<ul class="size-row clearfix">
{{#each values}}
<li class="block" data-prop-id="{{../type}}" data-value-id="{{id}}">{{name}}</li>
{{/each}}
</ul>
{{/each}}
</div>
</ul>
</div>
{{/each}}
<div class="num">
<span class="name">数量</span>
<div class="clearfix">
... ... @@ -70,7 +60,7 @@
</div>
</div>
<div class="btn-wrap">
<button id="chose-btn-sure" class="btn btn-sure">{{#if @root.tickets}}立即购买{{else}}加入购物车{{/if}}</button>
<button id="chose-btn-sure" class="btn btn-sure">{{@root.buttonText}}</button>
</div>
</div>
</div>
... ...
{{> ../../common/chose-panel}}
{{# cartInfo}}
<div class="cart-bar">
{{#unless @root.wap.common.removeCartCount}}
... ...
... ... @@ -38,7 +38,7 @@ var $chosePanel = $('#chose-panel'),
queryString,
$choseArea,
$cartBar,
$soonSoldOut = $('.soonSoldOut-tag'),
$soonSoldOut = $('.soon-sold-out-tag'),
$yohoPage = $('.yoho-page'),
// 门票 限购数量
... ...
/**
* 购物车选择尺寸、颜色和数量面板
* @author: feng.chen<feng.chen@yoho.cn>
* @date: 2017/3/2
* 示例:
* let chosePanel = require('chose-panel-new');
* chosePanel.show({
* data: {},
* buttonText: '加入购物车'
* }).then((sku) => {
* //点击确认按钮回调,返回sku对象,各自业务在此处实现,该组件不做选择后的处理
* //...
* }, () => {
* //关闭选择框回调
* });
* choselPanel.close(); //关闭选择框
*/
let $ = require('yoho-jquery'),
innerScroll = require('../plugin/inner-scroll');
let panelT = require('common/chose-panel.hbs');
let $yohoPage = $('.yoho-page'),
$chosePanel = $('.chose-panel'),
$choseArea;
let chosePanelObj = {
setting: {
buttonText: '确认'
},
show(opt) {
let self = this;
if (opt) {
self.data = opt.data;
self.setting.buttonText = opt.buttonText || self.getButtonText();
}
if (!self.data) {
throw new Error('未赋值');
}
if (!opt) {
$('.chose-panel').show();
return;
}
self.render();
return new Promise((resolve, reject) => {
self._resolve = resolve;
self._reject = reject;
});
},
render() {
let self = this,
html;
html = panelT(Object.assign(self.data, {
buttonText: self.setting.buttonText
}));
if ($chosePanel.length) {
$chosePanel.replaceWith(html);
} else {
$yohoPage.append(html);
}
self._setVariable();
self._initStatus();
self._regEvents();
},
disableNumEdit() {
$('.btn-minus,.btn-plus').addClass('disabled');
},
close() {
let self = this;
$('.chose-panel').hide();
self._reject();
},
getButtonText() {
let self = this;
if (self.data.tickets) {
return '立即购买';
}
},
_initStatus() {
let self = this,
noStorageSkus = self.skus.filter(sku => sku.storage === 0);
$('.block').removeClass('zero-stock');
noStorageSkus.forEach(sku => {
for (let propType in sku.prop) {
if (propType) {
let prop = sku.prop[propType];
let zeroStock = !self.skus.some(_ => _.prop[propType].valId === prop.valId && _.storage > 0); //TODO 量贩
let $block = $(`.block[data-prop-id="${propType}"][data-value-id="${prop.valId}"]`);
if (zeroStock) {
$block.addClass('zero-stock');
} else {
$block.removeClass('zero-stock');
}
}
}
});
},
_setVariable() {
let self = this;
$chosePanel = $('.chose-panel');
$choseArea = $('.chose-panel .main .chose-items');
self.skus = self.data && self.data.cartInfo && self.data.cartInfo.skus || [];
self.props = self.data && self.data.cartInfo && self.data.cartInfo.props || [];
},
_regEvents() {
let self = this;
innerScroll.disableScroll($choseArea);
$yohoPage.off('touchstart', '.chose-panel').on('touchstart', '.chose-panel', (e) => {
return self._closeClick(e);
});
$yohoPage.off('touchstart', '.block').on('touchstart', '.block', (e) => {
return self._blockClick(e);
});
},
_closeClick(e) {
let self = this;
let $cur = $(e.target);
if ($cur.closest('.main').length > 0 && !$cur.hasClass('close')) {
return;
}
self.close();
return false;
},
_blockClick(e) {
let self = this;
let $block = $(e.currentTarget);
if ($block.hasClass('chosed')) {
$block.removeClass('chosed');
} else {
$block.addClass('chosed').siblings().removeClass('chosed');
}
self._selectBlock($block);
},
_selectBlock($selectBlock) {
let self = this;
let propId = $selectBlock.data('prop-id'),
valueId = $selectBlock.data('value-id');
let chosed = $($selectBlock).hasClass('chosed');
if ($('.block.chosed').length === 0) {
self._initStatus();
} else {
let filterSkus = self.skus.filter(sku => (!chosed || sku.prop[propId].valId === valueId) && sku.storage > 0); // TODO 量贩
let filterProps = self.props.filter(prop => prop.type !== propId);
filterProps.forEach(prop => {
$(`.block[data-prop-id="${prop.type}"]`).each((i, ele) => {
let $block = $(ele);
let valId = $block.data('value-id');
let existsSku = filterSkus.some(sku => sku.prop[prop.type].valId === valId);
if (!existsSku) {
$block.addClass('zero-stock');
} else {
$block.removeClass('zero-stock');
}
});
});
}
self._initBlockStatus();
},
_initBlockStatus() {
let self = this,
selectSku = self._getSelectSku();
// 设置底部按钮文字
if ($('.block.chosed.zero-stock').length) {
$('#chose-btn-sure').css('background-color', '#c0c0c0').text('已售罄');
} else {
$('#chose-btn-sure').css('background-color', '#eb0313').text(self.setting.buttonText);
}
// 根据颜色属性设置缩略图
let $colorBlock = $('.block.chosed[data-prop-id="color"]');
if ($colorBlock.length) {
let colorSkus = self.skus.filter(sku => sku.prop.color &&
sku.prop.color.valId === $colorBlock.data('value-id'));
if (colorSkus.length) {
let thumb = colorSkus[0].thumb;
if (!thumb) {
thumb = self.data.cartInfo.defaultThumb;
}
$chosePanel.find('.thumb').attr('src', thumb);
}
}
// 设置选择属性提示
let valueList = Array.from($('.block.chosed').map((index, ele) => {
return $(ele).text();
}));
if (valueList.length) {
$('.not-choose').addClass('hide');
$('.choosed-info').removeClass('hide');
$('.choosed-info').text(`已选:${valueList.join('、')}`);
} else {
$('.not-choose').removeClass('hide');
$('.choosed-info').addClass('hide');
}
if (selectSku) {
// 设置left-num文字
let cartInfo = self.data.cartInfo,
numText;
if (cartInfo.limit) {
numText = `限购${cartInfo.limit}件`;
} else if (selectSku.storage < 4) { // TODO 即将售罄 移到业务调用设置
numText = `剩余${selectSku.storage}件`;
} else {
numText = '';
}
$chosePanel.find('.left-num').text(numText);
}
},
_getSelectSku() {
let self = this,
selectValues,
selectSku;
if ($('.block.chosed').length !== self.props.length) {
return;
}
selectValues = Array.from($('.block.chosed').map((index, ele) => {
let $block = $(ele);
return {
propId: $block.data('prop-id'),
valueId: $block.data('value-id')
};
}));
selectSku = self.skus.find(sku => {
return selectValues
.map(value => {
return sku.prop[value.propId].valId === value.valueId;
})
.filter(match => match).length === self.props.length;
});
return selectSku;
}
};
module.exports = chosePanelObj;
... ...
... ... @@ -42,7 +42,17 @@ function innerScroll(e) {
}
}
function enableScroll($choseArea) {
$choseArea.off('touchstart');
$choseArea.off('touchmove');
$choseArea.off('mousewheel');
$(document).off('mousewheel', preventDefault);
$(document).off('touchmove', preventDefault);
}
function disableScroll($choseArea) {
enableScroll($choseArea);
var startX, startY;
// 内部可滚
... ... @@ -89,15 +99,6 @@ function disableScroll($choseArea) {
$(document).on('touchmove', preventDefault);
}
function enableScroll($choseArea) {
$choseArea.off('touchstart');
$choseArea.off('touchmove');
$choseArea.off('mousewheel');
$(document).off('mousewheel', preventDefault);
$(document).off('touchmove', preventDefault);
}
exports.enableScroll = enableScroll;
exports.disableScroll = disableScroll;
... ...
... ... @@ -6,14 +6,10 @@
var $ = require('yoho-jquery'),
tip = require('plugin/tip'),
chosePanel = require('cart/chose-panel');
tip = require('plugin/tip');
var productId = $('#productId').val();
var skn = $('#productSkn').val(),
productCode = $('#limitProductCode').val();
var C_ID = window._ChannelVary[window.cookie('_Channel')],
PRD_ID;
... ... @@ -93,18 +89,4 @@ $('#likeBtn').on('touchstart', function() {
return false;
});
$('#addtoCart').on('touchstart', function() {
$('.cart-bar').hide();
productCode && chosePanel.setLimitGoodModeWithSknId(productCode, skn);
chosePanel.show();
// 统计代码:用于统计用户加入购物车的动作
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
pd: productId,
by: 1
}, true);
}
return false;
});
... ...
require('product/detail/detail.page.css');
var $ = require('yoho-jquery');
var productId = $('#productId').val();
var goodsId = $('#goodsId').val();
var productSkn = $('#productSkn').val();
var brandId = $('#brand-id').val();
var bundleType = $('#bundleType').val();
let $ = require('yoho-jquery');
let productId = $('#productId').val();
let goodsId = $('#goodsId').val();
let productSkn = $('#productSkn').val();
let brandId = $('#brand-id').val();
let bundleType = $('#bundleType').val();
require('../common');
... ... @@ -20,10 +20,10 @@ require('./detail/recommend-for-you-product-desc');
window.rePosFooter && window.rePosFooter();
setTimeout(() => {
var Swiper = require('yoho-swiper');
let Swiper = require('yoho-swiper');
// 顶部swiper
var swiper = new Swiper('.banner-swiper', {
let swiper = new Swiper('.banner-swiper', {
preloadImages: false,
lazyLoading: true,
lazyLoadingInPrevNext: true,
... ... @@ -52,7 +52,7 @@ setTimeout(() => {
return;
}
var dbClass = 'data-bind',
let dbClass = 'data-bind',
infoDataHbs = require('product/detail/infodata.hbs'),
priceDataHbs = require('product/detail/pricedata.hbs');
... ... @@ -84,7 +84,7 @@ setTimeout(() => {
if (data.isDepositAdvance === 'Y') {
// 定金预售商品
var tip = require('../plugin/tip');
let tip = require('../plugin/tip');
setTimeout(function() {
$('#addtoCart').text('立即购买').off('touchstart').on('touchstart', function() {
... ... @@ -108,13 +108,13 @@ setTimeout(() => {
},
success: (data) => {
// 如果当前是秒杀商品,且不在秒杀路径下,跳到该商品的秒杀详情页
var reg = /\/product\/show_([\d]+)/;
var regPro = /\/product\/pro_([\d]+)_([\d]+)/;
var regSeckill = /\/product\/seckill/;
let reg = /\/product\/show_([\d]+)/;
let regPro = /\/product\/pro_([\d]+)_([\d]+)/;
let regSeckill = /\/product\/seckill/;
// var regProSeckill = /\/product\/seckill\/pro_([\d]+)_([\d]+)/;
var thisHref = window.location.href;
var thisRefer = document.referrer;
// let regProSeckill = /\/product\/seckill\/pro_([\d]+)_([\d]+)/;
let thisHref = window.location.href;
let thisRefer = document.referrer;
if (!regSeckill.test(thisRefer)) {
if (data.isSecKill === 'Y' && (reg.test(thisHref) || regPro.test(thisHref))) {
... ... @@ -134,8 +134,8 @@ setTimeout(() => {
require('./detail/like');
// 设定购物bar
var $cartBar = $('.cart-bar');
var timer = setInterval(function() {
let $cartBar = $('.cart-bar');
let timer = setInterval(function() {
if ($cartBar) {
window.reMarginFooter('.cart-bar');
clearInterval(timer);
... ... @@ -145,10 +145,37 @@ setTimeout(() => {
}, 500);
// 限购
var dialog = require('../plugin/dialog');
let dialog = require('../plugin/dialog');
let chosePanel = require('common/chose-panel-new');
$('#addtoCart').on('touchstart', function() {
let productCode = $('#limitProductCode').val();
$('.cart-bar').hide();
// productCode && chosePanel.setLimitGoodModeWithSknId(productCode, productSkn);
chosePanel.show({
data: data,
buttonText: '加入购物车'
}).then(() => {
console.log('choice')
}, () => {
$('.cart-bar').show();
console.log('cancel')
});
// 统计代码:用于统计用户加入购物车的动作
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
pd: productId,
by: 1
}, true);
}
return false;
});
$('#limit-sale').on('touchend', function(e) {
var loginUrl = $('#loginUrl').val(),
let loginUrl = $('#loginUrl').val(),
time,
ifr;
... ... @@ -163,7 +190,7 @@ setTimeout(() => {
rightBtnText: '打开Yoho!Buy有货APP'
}
}, function() {
var appUrl = $('input[name="limitCodeUrl"]').val();
let appUrl = $('input[name="limitCodeUrl"]').val();
ifr = document.createElement('iframe');
ifr.src = appUrl;
... ... @@ -202,15 +229,15 @@ setTimeout(() => {
*/
+ (function(skn, productId, brandId) { // eslint-disable-line
// 模版: 促销, feedback, 店铺
var promotionT = require('product/detail/promotion.hbs');
var feedbackT = require('product/detail/feedbacks.hbs');
var enterStoreT = require('product/detail/enterStore.hbs');
var bundleT = require('product/detail/bundle.hbs');
let promotionT = require('product/detail/promotion.hbs');
let feedbackT = require('product/detail/feedbacks.hbs');
let enterStoreT = require('product/detail/enterStore.hbs');
let bundleT = require('product/detail/bundle.hbs');
// placeholder
var $feedbackStore = $('#placeholder-feedback-store');
var $promotion = $('#placeholder-promotion');
var $bundle = $('#placeholder-bundle');
let $feedbackStore = $('#placeholder-feedback-store');
let $promotion = $('#placeholder-promotion');
let $bundle = $('#placeholder-bundle');
/**
* 渲染 feedback, 店铺, 替换placeholder
... ... @@ -221,11 +248,11 @@ setTimeout(() => {
* @param $placeholder
*/
function renderFeedbackStore(data, $placeholder) {
var feedbackHtml = feedbackT({
let feedbackHtml = feedbackT({
feedbacks: data.feedbacks
});
var enterStoreHtml = enterStoreT({
let enterStoreHtml = enterStoreT({
enterStore: data.enterStore
});
... ... @@ -242,7 +269,7 @@ setTimeout(() => {
* @param $placeholder
*/
function renderPromotion(data, $placeholder) {
var promotionHtml = promotionT({
let promotionHtml = promotionT({
promotion: data.promotion
});
... ... @@ -256,7 +283,7 @@ setTimeout(() => {
* @returns {*}
*/
function renderBundle(data, $placeholder) {
var bundleHtml = bundleT({
let bundleHtml = bundleT({
bundleData: data.bundleData
});
... ... @@ -264,10 +291,10 @@ setTimeout(() => {
}
function promotionInit() {
var $goodsDiscount = $('#goodsDiscount');
var $discountFirstItem = $goodsDiscount.find('.first-item');
var $discountFolder = $goodsDiscount.find('.discount-folder');
var $discountArrow = $goodsDiscount.find('.first-item span');
let $goodsDiscount = $('#goodsDiscount');
let $discountFirstItem = $goodsDiscount.find('.first-item');
let $discountFolder = $goodsDiscount.find('.discount-folder');
let $discountArrow = $goodsDiscount.find('.first-item span');
// 初始化goods-discount
if ($discountFolder.children().length === 0) {
... ... @@ -332,8 +359,8 @@ setTimeout(() => {
$(document).scroll(function() {
if ($(document).scrollTop() >= $(document).height() - $(window).height() - 120) {
var top = $('.back-to-top').offset().top - $('.float-top').offset().top + ($('.back-to-top').height() - $('.float-top').height()) / 2;
var left = $('.back-to-top').offset().left - $('.float-top').offset().left;
let top = $('.back-to-top').offset().top - $('.float-top').offset().top + ($('.back-to-top').height() - $('.float-top').height()) / 2;
let left = $('.back-to-top').offset().left - $('.float-top').offset().left;
$('.float-top').addClass('animation').css({
transform: 'translate(' + left + 'px, ' + top + 'px) scale(0, 0)',
... ...
... ... @@ -137,7 +137,6 @@
bottom: 0;
left: 0;
z-index: 5;
display: none;
height: 100%;
background: rgba(0, 0, 0, 0.3);
... ... @@ -198,6 +197,12 @@
float: none;
}
.choosed-info {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.name {
display: -webkit-box;
overflow: hidden;
... ... @@ -239,8 +244,7 @@
}
}
.color-list,
.size-list,
.block-list,
.num {
position: relative;
padding-left: 80px;
... ... @@ -290,16 +294,11 @@
}
}
.color-list,
.size-list {
.block-list {
border-bottom: 1PX solid #e6e6e6;
margin: 30px 0;
}
.size-list li.hide {
display: none;
}
.block {
display: block;
float: left;
... ...
... ... @@ -353,6 +353,70 @@ exports.processFilter = (list, options) => {
};
/**
* 解析skn数据
*/
exports.processSkusInfo = (origin) => {
let tickets = origin.attribute === 3;
let dest = {
productId: origin.product_id,
name: origin.product_name || '',
totalNum: origin.storage_sum,
skus: [],
props: [{
name: tickets ? '日期' : '颜色',
type: 'color',
values: []
}, {
name: tickets ? '区域' : '尺码',
type: 'size',
values: []
}]
};
_.each(origin.goods_list, color => {
_.each(color.size_list, size => {
let colorProp = dest.props.find(prop => prop.type === 'color'),
sizeProp = dest.props.find(prop => prop.type === 'size');
if (!_.some(colorProp.values, prop => prop.id === color.color_id)) {
colorProp.values.push({
id: color.color_id,
name: color.factory_goods_name || color.color_name
});
}
if (!_.some(sizeProp.values, prop => prop.id === size.size_id)) {
sizeProp.values.push({
id: size.size_id,
name: size.size_name
});
}
dest.skus.push({
skuId: size.product_sku,
sizeInfo: size.size_info,
storage: size.storage_number,
thumb: helpers.image(color.color_image, 300, 395),
prop: {
color: {
valId: color.color_id,
valName: color.factory_goods_name || color.color_name
},
size: {
valId: size.size_id,
valName: size.size_name
}
}
});
});
});
dest.defaultThumb = helpers.image(_.get(dest, 'skus[0].thumb', ''), 300, 395);
return dest;
};
/**
* 解析尺码弹出框数据
*/
exports.processSizeInfo = (origin) => {
... ...