Authored by huangyi

Merge branches 'feature/redpack' and 'release/6.7.9' of http://git.yoho.cn/fe/yo…

…hobuywap-node into feature/redpack
... ... @@ -245,11 +245,15 @@ class featureModel extends global.yoho.BaseModel {
if (componentType === 'cutPriceSkn' && f.param.bgimg) {
// 阶梯降价楼层显示信息位置严重依赖图片尺寸
// 将楼层背景图提取到component内部以便对其尺寸控制
//
let skn = f.component[0].SKN;
f.component[0].producturl = `//m.yohobuy.com/product/${skn}.html?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${skn}","from_page_name":"${yasProcess.getPname(self.ctx.req)}","from_page_param":"${_.get(self.ctx, 'req.url', '')}"}}`, // eslint-disable-line
f.component[0].bgImg = f.param.bgimg;
let component0 = f.component[0];
let skn = component0.SKN;
component0.producturl = `//m.yohobuy.com/product/${skn}.html?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${skn}","from_page_name":"${yasProcess.getPname(self.ctx.req)}","from_page_param":"${_.get(self.ctx, 'req.url', '')}"}}`, // eslint-disable-line
component0.bgImg = f.param.bgimg;
component0.beginTimeInt = Date.parse(new Date(component0.beginTime)) / 1000;
component0.endTimeInt = Date.parse(new Date(component0.endTime)) / 1000;
f.param.bgimg = '';
}
... ...
<div class="timed-cut-container" {{#if bgImg}} style="background-image:url({{image2 bgImg w=750 h=460 q=85}});"{{/if}} data-skn="{{SKN}}">
<a href="{{producturl}}">
<div class="act-time">
<p class="start-time" data-time="{{beginTime}}">开始时间:<span>{{beginTime}}</span></p>
<p class="end-time" data-time="{{endTime}}">结束时间:{{endTime}}</p>
<p class="start-time" data-time="{{beginTimeInt}}">开始时间:<span>{{beginTime}}</span></p>
<p class="end-time" data-time="{{endTimeInt}}">结束时间:{{endTime}}</p>
</div>
<div class="now-price">¥<span></span></div>
<div class="limit-time"><p></p></div>
... ...
... ... @@ -324,6 +324,14 @@ function convertTime(time) {
return `${h < 10 ? '0' : ''}${h}:${m < 10 ? '0' : ''}${m}:${s < 10 ? '0' : ''}${s}`;
}
function getGoodsInfo(skns) {
return $.ajax({
url: '//m.yohobuy.com/activity/feature/goods',
dataType: 'jsonp',
data: {skns}
});
}
function timedCutProductInit() {
let $timedCut = $('.timed-cut-container');
... ... @@ -343,8 +351,8 @@ function timedCutProductInit() {
$price: $this.find('.now-price > span'),
$time: $this.find('.limit-time > p'),
$bth: $this.find('.opt-btn'),
startTimeStr: $this.find('.start-time').data('time'),
endTimeStr: $this.find('.end-time').data('time'),
startTime: $this.find('.start-time').data('time'),
endTime: $this.find('.end-time').data('time'),
skn: skn,
btnClass: '',
changeNowPrice: function(curPrice) {
... ... @@ -383,140 +391,148 @@ function timedCutProductInit() {
return;
}
$.ajax({
url: '//m.yohobuy.com/activity/feature/goods',
dataType: 'jsonp',
data: {
skns: skns.join(',')
},
success: function(res) {
function updateProductPriceBySkn(selfObj) {
if (!selfObj || !selfObj.skn) {
return;
}
getGoodsInfo(selfObj.skn).then(function(res) {
if (res.code !== 200 || !res.data || !res.data.length) {
return;
}
let time = res.timestamp || Date.parse(new Date()) / 1000;
let list = {};
selfObj.changeNowPrice && selfObj.changeNowPrice(res.data[0].saleprice);
});
}
getGoodsInfo(skns.join(',')).then(function(res) {
if (res.code !== 200 || !res.data || !res.data.length) {
return;
}
res.data.forEach(value => {
list[value.product_skn] = value;
});
let time = res.timestamp || Date.parse(new Date()) / 1000;
let list = {};
timedCutArr.forEach(value => {
let info = list[value.skn] || {};
value.plan = info.product_price_plan_list || [];
value.stockNumber = +info.stock_number;
res.data.forEach(value => {
list[value.product_skn] = value;
});
if (value.startTimeStr) {
value.startTime = Date.parse(new Date(value.startTimeStr)) / 1000;
}
timedCutArr.forEach(value => {
let info = list[value.skn] || {};
if (value.endTimeStr) {
value.endTime = Date.parse(new Date(value.endTimeStr)) / 1000;
}
value.plan = info.product_price_plan_list || [];
value.stockNumber = +info.stock_number;
if (!value.startTime) {
value.startTime = value.plan[0] && value.plan[0].show_begin_time; // 活动开始时间
}
if (!value.endTime) {
value.endTime = value.plan[0] && value.plan[0].show_begin_time; // 活动结束时间
}
if (!value.startTime) {
value.startTime = value.plan[0] && value.plan[0].show_begin_time; // 活动开始时间
}
let plan = [];
if (!value.endTime) {
value.endTime = value.plan[0] && value.plan[0].show_begin_time; // 活动结束时间
}
value.plan.forEach(val => {
if (+val.effect_time > +value.endTime || +val.end_time < +value.startTime) {
return;
}
let plan = [];
plan.push(val);
});
value.plan.forEach(val => {
if (+val.effect_time > +value.endTime || +val.end_time < +value.startTime) {
return;
}
value.curEndTime = 0; // 当前价格档结束时间
value.saleprice = info.saleprice; // 商品售价
plan.push(val);
});
let timer;
let changeProductStatus = () => {
time++;
value.curEndTime = 0; // 当前价格档结束时间
value.saleprice = info.saleprice; // 商品售价
});
let timer;
let changeProductStatus = () => {
time++;
let endNum = 0;
let endNum = 0;
timedCutArr.forEach(value => {
if (time > value.endTime) { // 【活动已结束】
value.changeBtnClass(4);
timedCutArr.forEach(value => {
if (time > value.endTime) { // 【活动已结束】
value.changeBtnClass(4);
// 活动已结束时价格恢复售价
// 活动已结束时价格恢复售价
if (value.curPrice) { // 在降价中的商品从服务端获取商品价格
updateProductPriceBySkn(value);
} else { // 未在降价中的商品直接取商品售价
value.changeNowPrice(value.saleprice);
}
endNum++;
} else if (time >= value.startTime) { // 【活动进行中】
if (!value.stockNumber) { // 【活动进行中-售罄】
value.changeBtnClass(3);
return;
}
endNum++;
} else if (time >= value.startTime) { // 【活动进行中】
if (!value.stockNumber) { // 【活动进行中-售罄】
value.changeBtnClass(3);
return;
}
let curPrice;
let isEndPlan;
let curPrice;
value.changeBtnClass(2);
value.changeBtnClass(2);
if (time >= value.curEndTime) {
let curEndTime,
curStartTime;
if (time >= value.curEndTime) {
let curEndTime,
curStartTime;
value.plan.forEach((val, index) => {
if (!curEndTime && val.end_time - time > 0) {
curEndTime = +val.end_time;
curStartTime = +val.effect_time;
curPrice = +val.current_saleprice;
value.plan.forEach(val => {
if (!curEndTime && val.end_time - time > 0) {
curEndTime = +val.end_time;
curStartTime = +val.effect_time;
curPrice = +val.current_saleprice;
if (!value.plan[index + 1]) {
isEndPlan = 1;
}
});
}
});
// 取不到下一档时价格恢复售价
curPrice = curPrice || value.saleprice;
// 取不到下一档时价格恢复售价
curPrice = curPrice || value.saleprice;
value.curStartTime = curStartTime;
value.curEndTime = curEndTime;
}
value.curStartTime = curStartTime;
value.curEndTime = curEndTime;
}
let limitTime;
let limitTime;
if (time >= value.curStartTime) {
limitTime = value.curEndTime - time;
} else {
// 当前降价未开始时价格恢复售价
curPrice = value.saleprice;
limitTime = value.curStartTime - time;
}
if (time >= value.curStartTime) {
limitTime = value.curEndTime - time;
} else {
// 当前降价未开始时价格恢复售价
curPrice = value.saleprice;
limitTime = value.curStartTime - time;
isEndPlan = 0;
updateProductPriceBySkn(value);
}
value.changeNowPrice(curPrice);
value.$time.text(`距离下次降价还剩 ${convertTime(limitTime)}`);
} else { // 【活动未开始】
value.changeBtnClass(1);
value.changeNowPrice(value.saleprice);
value.changeNowPrice(curPrice);
value.$time.text(`距离${isEndPlan ? '活动结束' : '下次降价'}还剩 ${convertTime(limitTime)}`);
} else { // 【活动未开始】
value.changeBtnClass(1);
value.changeNowPrice(value.saleprice);
if (value.startTime) {
value.$time.text(`距离下次降价还剩 ${convertTime(value.startTime - time)}`);
} else {
value.$time.text('活动即将开始');
}
if (value.startTime) {
value.$time.text(`距离下次降价还剩 ${convertTime(value.startTime - time)}`);
} else {
value.$time.text('活动即将开始');
}
});
// 所有活动结束,清除定时器
if (timer && endNum === timedCutArr.length) {
clearInterval(timer);
}
};
changeProductStatus();
timer = setInterval(changeProductStatus, 1000);
}
});
});
// 所有活动结束,清除定时器
if (timer && endNum === timedCutArr.length) {
clearInterval(timer);
}
};
timer = setInterval(changeProductStatus, 1000);
changeProductStatus();
});
}
$(function() {
... ...
... ... @@ -9,7 +9,7 @@ require('jquery-lazyload');
const rawLazyload = (selector, options) => {
let $imgs;
let params = {
threshold: 700 * 2 // 一页大概700 ,提前加载三、四页
threshold: 700 * 3 // 一页大概700 ,提前加载三、四页
};
if (selector instanceof $) {
... ...