|
@@ -324,6 +324,14 @@ function convertTime(time) { |
|
@@ -324,6 +324,14 @@ function convertTime(time) { |
324
|
return `${h < 10 ? '0' : ''}${h}:${m < 10 ? '0' : ''}${m}:${s < 10 ? '0' : ''}${s}`;
|
324
|
return `${h < 10 ? '0' : ''}${h}:${m < 10 ? '0' : ''}${m}:${s < 10 ? '0' : ''}${s}`;
|
325
|
}
|
325
|
}
|
326
|
|
326
|
|
|
|
327
|
+function getGoodsInfo(skns) {
|
|
|
328
|
+ return $.ajax({
|
|
|
329
|
+ url: '//m.yohobuy.com/activity/feature/goods',
|
|
|
330
|
+ dataType: 'jsonp',
|
|
|
331
|
+ data: {skns}
|
|
|
332
|
+ });
|
|
|
333
|
+}
|
|
|
334
|
+
|
327
|
function timedCutProductInit() {
|
335
|
function timedCutProductInit() {
|
328
|
let $timedCut = $('.timed-cut-container');
|
336
|
let $timedCut = $('.timed-cut-container');
|
329
|
|
337
|
|
|
@@ -343,8 +351,8 @@ function timedCutProductInit() { |
|
@@ -343,8 +351,8 @@ function timedCutProductInit() { |
343
|
$price: $this.find('.now-price > span'),
|
351
|
$price: $this.find('.now-price > span'),
|
344
|
$time: $this.find('.limit-time > p'),
|
352
|
$time: $this.find('.limit-time > p'),
|
345
|
$bth: $this.find('.opt-btn'),
|
353
|
$bth: $this.find('.opt-btn'),
|
346
|
- startTimeStr: $this.find('.start-time').data('time'),
|
|
|
347
|
- endTimeStr: $this.find('.end-time').data('time'),
|
354
|
+ startTime: $this.find('.start-time').data('time'),
|
|
|
355
|
+ endTime: $this.find('.end-time').data('time'),
|
348
|
skn: skn,
|
356
|
skn: skn,
|
349
|
btnClass: '',
|
357
|
btnClass: '',
|
350
|
changeNowPrice: function(curPrice) {
|
358
|
changeNowPrice: function(curPrice) {
|
|
@@ -383,140 +391,148 @@ function timedCutProductInit() { |
|
@@ -383,140 +391,148 @@ function timedCutProductInit() { |
383
|
return;
|
391
|
return;
|
384
|
}
|
392
|
}
|
385
|
|
393
|
|
386
|
- $.ajax({
|
|
|
387
|
- url: '//m.yohobuy.com/activity/feature/goods',
|
|
|
388
|
- dataType: 'jsonp',
|
|
|
389
|
- data: {
|
|
|
390
|
- skns: skns.join(',')
|
|
|
391
|
- },
|
|
|
392
|
- success: function(res) {
|
394
|
+ function updateProductPriceBySkn(selfObj) {
|
|
|
395
|
+ if (!selfObj || !selfObj.skn) {
|
|
|
396
|
+ return;
|
|
|
397
|
+ }
|
|
|
398
|
+
|
|
|
399
|
+ getGoodsInfo(selfObj.skn).then(function(res) {
|
393
|
if (res.code !== 200 || !res.data || !res.data.length) {
|
400
|
if (res.code !== 200 || !res.data || !res.data.length) {
|
394
|
return;
|
401
|
return;
|
395
|
}
|
402
|
}
|
396
|
|
403
|
|
397
|
- let time = res.timestamp || Date.parse(new Date()) / 1000;
|
|
|
398
|
- let list = {};
|
404
|
+ selfObj.changeNowPrice && selfObj.changeNowPrice(res.data[0].saleprice);
|
|
|
405
|
+ });
|
|
|
406
|
+ }
|
399
|
|
407
|
|
|
|
408
|
+ getGoodsInfo(skns.join(',')).then(function(res) {
|
|
|
409
|
+ if (res.code !== 200 || !res.data || !res.data.length) {
|
|
|
410
|
+ return;
|
|
|
411
|
+ }
|
400
|
|
412
|
|
401
|
- res.data.forEach(value => {
|
|
|
402
|
- list[value.product_skn] = value;
|
|
|
403
|
- });
|
413
|
+ let time = res.timestamp || Date.parse(new Date()) / 1000;
|
|
|
414
|
+ let list = {};
|
404
|
|
415
|
|
405
|
- timedCutArr.forEach(value => {
|
|
|
406
|
- let info = list[value.skn] || {};
|
|
|
407
|
|
416
|
|
408
|
- value.plan = info.product_price_plan_list || [];
|
|
|
409
|
- value.stockNumber = +info.stock_number;
|
417
|
+ res.data.forEach(value => {
|
|
|
418
|
+ list[value.product_skn] = value;
|
|
|
419
|
+ });
|
410
|
|
420
|
|
411
|
- if (value.startTimeStr) {
|
|
|
412
|
- value.startTime = Date.parse(new Date(value.startTimeStr)) / 1000;
|
|
|
413
|
- }
|
421
|
+ timedCutArr.forEach(value => {
|
|
|
422
|
+ let info = list[value.skn] || {};
|
414
|
|
423
|
|
415
|
- if (value.endTimeStr) {
|
|
|
416
|
- value.endTime = Date.parse(new Date(value.endTimeStr)) / 1000;
|
|
|
417
|
- }
|
424
|
+ value.plan = info.product_price_plan_list || [];
|
|
|
425
|
+ value.stockNumber = +info.stock_number;
|
418
|
|
426
|
|
419
|
- if (!value.startTime) {
|
|
|
420
|
- value.startTime = value.plan[0] && value.plan[0].show_begin_time; // 活动开始时间
|
|
|
421
|
- }
|
|
|
422
|
-
|
|
|
423
|
- if (!value.endTime) {
|
|
|
424
|
- value.endTime = value.plan[0] && value.plan[0].show_begin_time; // 活动结束时间
|
|
|
425
|
- }
|
427
|
+ if (!value.startTime) {
|
|
|
428
|
+ value.startTime = value.plan[0] && value.plan[0].show_begin_time; // 活动开始时间
|
|
|
429
|
+ }
|
426
|
|
430
|
|
427
|
- let plan = [];
|
431
|
+ if (!value.endTime) {
|
|
|
432
|
+ value.endTime = value.plan[0] && value.plan[0].show_begin_time; // 活动结束时间
|
|
|
433
|
+ }
|
428
|
|
434
|
|
429
|
- value.plan.forEach(val => {
|
|
|
430
|
- if (+val.effect_time > +value.endTime || +val.end_time < +value.startTime) {
|
|
|
431
|
- return;
|
|
|
432
|
- }
|
435
|
+ let plan = [];
|
433
|
|
436
|
|
434
|
- plan.push(val);
|
|
|
435
|
- });
|
437
|
+ value.plan.forEach(val => {
|
|
|
438
|
+ if (+val.effect_time > +value.endTime || +val.end_time < +value.startTime) {
|
|
|
439
|
+ return;
|
|
|
440
|
+ }
|
436
|
|
441
|
|
437
|
- value.curEndTime = 0; // 当前价格档结束时间
|
|
|
438
|
- value.saleprice = info.saleprice; // 商品售价
|
442
|
+ plan.push(val);
|
439
|
});
|
443
|
});
|
440
|
|
444
|
|
441
|
- let timer;
|
|
|
442
|
- let changeProductStatus = () => {
|
|
|
443
|
- time++;
|
445
|
+ value.curEndTime = 0; // 当前价格档结束时间
|
|
|
446
|
+ value.saleprice = info.saleprice; // 商品售价
|
|
|
447
|
+ });
|
|
|
448
|
+
|
|
|
449
|
+ let timer;
|
|
|
450
|
+ let changeProductStatus = () => {
|
|
|
451
|
+ time++;
|
444
|
|
452
|
|
445
|
- let endNum = 0;
|
453
|
+ let endNum = 0;
|
446
|
|
454
|
|
447
|
- timedCutArr.forEach(value => {
|
|
|
448
|
- if (time > value.endTime) { // 【活动已结束】
|
|
|
449
|
- value.changeBtnClass(4);
|
455
|
+ timedCutArr.forEach(value => {
|
|
|
456
|
+ if (time > value.endTime) { // 【活动已结束】
|
|
|
457
|
+ value.changeBtnClass(4);
|
450
|
|
458
|
|
451
|
- // 活动已结束时价格恢复售价
|
459
|
+ // 活动已结束时价格恢复售价
|
|
|
460
|
+ if (value.curPrice) { // 在降价中的商品从服务端获取商品价格
|
|
|
461
|
+ updateProductPriceBySkn(value);
|
|
|
462
|
+ } else { // 未在降价中的商品直接取商品售价
|
452
|
value.changeNowPrice(value.saleprice);
|
463
|
value.changeNowPrice(value.saleprice);
|
|
|
464
|
+ }
|
453
|
|
465
|
|
454
|
- endNum++;
|
|
|
455
|
- } else if (time >= value.startTime) { // 【活动进行中】
|
|
|
456
|
- if (!value.stockNumber) { // 【活动进行中-售罄】
|
|
|
457
|
- value.changeBtnClass(3);
|
|
|
458
|
- return;
|
|
|
459
|
- }
|
466
|
+ endNum++;
|
|
|
467
|
+ } else if (time >= value.startTime) { // 【活动进行中】
|
|
|
468
|
+ if (!value.stockNumber) { // 【活动进行中-售罄】
|
|
|
469
|
+ value.changeBtnClass(3);
|
|
|
470
|
+ return;
|
|
|
471
|
+ }
|
|
|
472
|
+
|
|
|
473
|
+ let curPrice;
|
|
|
474
|
+ let isEndPlan;
|
460
|
|
475
|
|
461
|
- let curPrice;
|
476
|
+ value.changeBtnClass(2);
|
462
|
|
477
|
|
463
|
- value.changeBtnClass(2);
|
478
|
+ if (time >= value.curEndTime) {
|
|
|
479
|
+ let curEndTime,
|
|
|
480
|
+ curStartTime;
|
464
|
|
481
|
|
465
|
- if (time >= value.curEndTime) {
|
|
|
466
|
- let curEndTime,
|
|
|
467
|
- curStartTime;
|
482
|
+ value.plan.forEach((val, index) => {
|
|
|
483
|
+ if (!curEndTime && val.end_time - time > 0) {
|
|
|
484
|
+ curEndTime = +val.end_time;
|
|
|
485
|
+ curStartTime = +val.effect_time;
|
|
|
486
|
+ curPrice = +val.current_saleprice;
|
468
|
|
487
|
|
469
|
- value.plan.forEach(val => {
|
|
|
470
|
- if (!curEndTime && val.end_time - time > 0) {
|
|
|
471
|
- curEndTime = +val.end_time;
|
|
|
472
|
- curStartTime = +val.effect_time;
|
|
|
473
|
- curPrice = +val.current_saleprice;
|
488
|
+ if (!value.plan[index + 1]) {
|
|
|
489
|
+ isEndPlan = 1;
|
474
|
}
|
490
|
}
|
475
|
- });
|
491
|
+ }
|
|
|
492
|
+ });
|
476
|
|
493
|
|
477
|
- // 取不到下一档时价格恢复售价
|
|
|
478
|
- curPrice = curPrice || value.saleprice;
|
494
|
+ // 取不到下一档时价格恢复售价
|
|
|
495
|
+ curPrice = curPrice || value.saleprice;
|
479
|
|
496
|
|
480
|
- value.curStartTime = curStartTime;
|
|
|
481
|
- value.curEndTime = curEndTime;
|
|
|
482
|
- }
|
497
|
+ value.curStartTime = curStartTime;
|
|
|
498
|
+ value.curEndTime = curEndTime;
|
|
|
499
|
+ }
|
483
|
|
500
|
|
484
|
- let limitTime;
|
501
|
+ let limitTime;
|
485
|
|
502
|
|
486
|
- if (time >= value.curStartTime) {
|
|
|
487
|
- limitTime = value.curEndTime - time;
|
|
|
488
|
- } else {
|
|
|
489
|
- // 当前降价未开始时价格恢复售价
|
|
|
490
|
- curPrice = value.saleprice;
|
|
|
491
|
- limitTime = value.curStartTime - time;
|
|
|
492
|
- }
|
503
|
+ if (time >= value.curStartTime) {
|
|
|
504
|
+ limitTime = value.curEndTime - time;
|
|
|
505
|
+ } else {
|
|
|
506
|
+ // 当前降价未开始时价格恢复售价
|
|
|
507
|
+ curPrice = value.saleprice;
|
|
|
508
|
+ limitTime = value.curStartTime - time;
|
|
|
509
|
+ isEndPlan = 0;
|
|
|
510
|
+ updateProductPriceBySkn(value);
|
|
|
511
|
+ }
|
493
|
|
512
|
|
494
|
- value.changeNowPrice(curPrice);
|
|
|
495
|
- value.$time.text(`距离下次降价还剩 ${convertTime(limitTime)}`);
|
|
|
496
|
- } else { // 【活动未开始】
|
|
|
497
|
- value.changeBtnClass(1);
|
|
|
498
|
- value.changeNowPrice(value.saleprice);
|
513
|
+ value.changeNowPrice(curPrice);
|
|
|
514
|
+ value.$time.text(`距离${isEndPlan ? '活动结束' : '下次降价'}还剩 ${convertTime(limitTime)}`);
|
|
|
515
|
+ } else { // 【活动未开始】
|
|
|
516
|
+ value.changeBtnClass(1);
|
|
|
517
|
+ value.changeNowPrice(value.saleprice);
|
499
|
|
518
|
|
500
|
- if (value.startTime) {
|
|
|
501
|
- value.$time.text(`距离下次降价还剩 ${convertTime(value.startTime - time)}`);
|
|
|
502
|
- } else {
|
|
|
503
|
- value.$time.text('活动即将开始');
|
|
|
504
|
- }
|
519
|
+ if (value.startTime) {
|
|
|
520
|
+ value.$time.text(`距离下次降价还剩 ${convertTime(value.startTime - time)}`);
|
|
|
521
|
+ } else {
|
|
|
522
|
+ value.$time.text('活动即将开始');
|
505
|
}
|
523
|
}
|
506
|
- });
|
|
|
507
|
-
|
|
|
508
|
- // 所有活动结束,清除定时器
|
|
|
509
|
- if (timer && endNum === timedCutArr.length) {
|
|
|
510
|
- clearInterval(timer);
|
|
|
511
|
}
|
524
|
}
|
512
|
- };
|
|
|
513
|
-
|
|
|
514
|
- changeProductStatus();
|
|
|
515
|
- timer = setInterval(changeProductStatus, 1000);
|
|
|
516
|
- }
|
|
|
517
|
- });
|
525
|
+ });
|
518
|
|
526
|
|
|
|
527
|
+ // 所有活动结束,清除定时器
|
|
|
528
|
+ if (timer && endNum === timedCutArr.length) {
|
|
|
529
|
+ clearInterval(timer);
|
|
|
530
|
+ }
|
|
|
531
|
+ };
|
519
|
|
532
|
|
|
|
533
|
+ timer = setInterval(changeProductStatus, 1000);
|
|
|
534
|
+ changeProductStatus();
|
|
|
535
|
+ });
|
520
|
}
|
536
|
}
|
521
|
|
537
|
|
522
|
$(function() {
|
538
|
$(function() {
|