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 { @@ -245,11 +245,15 @@ class featureModel extends global.yoho.BaseModel {
245 if (componentType === 'cutPriceSkn' && f.param.bgimg) { 245 if (componentType === 'cutPriceSkn' && f.param.bgimg) {
246 // 阶梯降价楼层显示信息位置严重依赖图片尺寸 246 // 阶梯降价楼层显示信息位置严重依赖图片尺寸
247 // 将楼层背景图提取到component内部以便对其尺寸控制 247 // 将楼层背景图提取到component内部以便对其尺寸控制
248 - //  
249 - let skn = f.component[0].SKN;  
250 248
251 - 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  
252 - f.component[0].bgImg = f.param.bgimg; 249 + let component0 = f.component[0];
  250 + let skn = component0.SKN;
  251 +
  252 + 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
  253 + component0.bgImg = f.param.bgimg;
  254 +
  255 + component0.beginTimeInt = Date.parse(new Date(component0.beginTime)) / 1000;
  256 + component0.endTimeInt = Date.parse(new Date(component0.endTime)) / 1000;
253 257
254 f.param.bgimg = ''; 258 f.param.bgimg = '';
255 } 259 }
1 <div class="timed-cut-container" {{#if bgImg}} style="background-image:url({{image2 bgImg w=750 h=460 q=85}});"{{/if}} data-skn="{{SKN}}"> 1 <div class="timed-cut-container" {{#if bgImg}} style="background-image:url({{image2 bgImg w=750 h=460 q=85}});"{{/if}} data-skn="{{SKN}}">
2 <a href="{{producturl}}"> 2 <a href="{{producturl}}">
3 <div class="act-time"> 3 <div class="act-time">
4 - <p class="start-time" data-time="{{beginTime}}">开始时间:<span>{{beginTime}}</span></p>  
5 - <p class="end-time" data-time="{{endTime}}">结束时间:{{endTime}}</p> 4 + <p class="start-time" data-time="{{beginTimeInt}}">开始时间:<span>{{beginTime}}</span></p>
  5 + <p class="end-time" data-time="{{endTimeInt}}">结束时间:{{endTime}}</p>
6 </div> 6 </div>
7 <div class="now-price">¥<span></span></div> 7 <div class="now-price">¥<span></span></div>
8 <div class="limit-time"><p></p></div> 8 <div class="limit-time"><p></p></div>
@@ -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() {
@@ -9,7 +9,7 @@ require('jquery-lazyload'); @@ -9,7 +9,7 @@ require('jquery-lazyload');
9 const rawLazyload = (selector, options) => { 9 const rawLazyload = (selector, options) => {
10 let $imgs; 10 let $imgs;
11 let params = { 11 let params = {
12 - threshold: 700 * 2 // 一页大概700 ,提前加载三、四页 12 + threshold: 700 * 3 // 一页大概700 ,提前加载三、四页
13 }; 13 };
14 14
15 if (selector instanceof $) { 15 if (selector instanceof $) {