...
|
...
|
@@ -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() {
|
...
|
...
|
|