Showing
1 changed file
with
80 additions
and
15 deletions
@@ -321,13 +321,17 @@ const _getBoysSingleHot = (args, type) => { | @@ -321,13 +321,17 @@ const _getBoysSingleHot = (args, type) => { | ||
321 | * @return {Object} | 321 | * @return {Object} |
322 | */ | 322 | */ |
323 | const _getGirlsSingleHot = args => { | 323 | const _getGirlsSingleHot = args => { |
324 | - let goods = args[2].data; | 324 | + let goods = args[2] && args[2].data; |
325 | let skns = ''; | 325 | let skns = ''; |
326 | 326 | ||
327 | + if (goods) { | ||
328 | + _.forEach(goods, good => { | ||
329 | + skns += good.id + ' '; | ||
330 | + }); | ||
331 | + } else { | ||
332 | + return; | ||
333 | + } | ||
327 | 334 | ||
328 | - _.forEach(goods, good => { | ||
329 | - skns += good.id + ' '; | ||
330 | - }); | ||
331 | 335 | ||
332 | return searchApi.get('/search.json', { | 336 | return searchApi.get('/search.json', { |
333 | client_type: 'web', | 337 | client_type: 'web', |
@@ -360,12 +364,13 @@ const _getSingleHotFloorData = (args, type) => { | @@ -360,12 +364,13 @@ const _getSingleHotFloorData = (args, type) => { | ||
360 | /** | 364 | /** |
361 | * 处理异步获取的人气单品数据 | 365 | * 处理异步获取的人气单品数据 |
362 | * @param {[Object]} args 参数列表 | 366 | * @param {[Object]} args 参数列表 |
367 | + * @param {String} originQuery 原始skns | ||
363 | * @param {Object} queryResult 异步获取的数据 | 368 | * @param {Object} queryResult 异步获取的数据 |
364 | * @param {String} type 频道类型 | 369 | * @param {String} type 频道类型 |
365 | * @return {Object} | 370 | * @return {Object} |
366 | */ | 371 | */ |
367 | -const _getSingehotViaResult = (args, queryResult, type) => { | ||
368 | - const data = { | 372 | +const _getSingehotViaResult = (args, originQuery, queryResult, type) => { |
373 | + let data = { | ||
369 | singlehot: { | 374 | singlehot: { |
370 | name: args[0].data.text, | 375 | name: args[0].data.text, |
371 | navs: [], | 376 | navs: [], |
@@ -374,28 +379,59 @@ const _getSingehotViaResult = (args, queryResult, type) => { | @@ -374,28 +379,59 @@ const _getSingehotViaResult = (args, queryResult, type) => { | ||
374 | } | 379 | } |
375 | }; | 380 | }; |
376 | 381 | ||
382 | + let pos = 0; | ||
383 | + | ||
384 | + | ||
385 | + const getIndex = skn => { | ||
386 | + const originQueryArr = originQuery.split(' '); | ||
387 | + let index; | ||
388 | + | ||
389 | + | ||
390 | + _.forEach(originQueryArr, (query, idx) => { | ||
391 | + if (query.toString() === skn.toString()) { | ||
392 | + index = idx; | ||
393 | + } | ||
394 | + }); | ||
395 | + | ||
396 | + return index; | ||
397 | + }; | ||
398 | + | ||
377 | if (args[3].template_name === 'app_icon_list') { | 399 | if (args[3].template_name === 'app_icon_list') { |
378 | data.singlehot.brands = args[3].data; | 400 | data.singlehot.brands = args[3].data; |
379 | } | 401 | } |
380 | 402 | ||
381 | if (queryResult.data) { | 403 | if (queryResult.data) { |
382 | - _.forEach(queryResult.data.product_list || [], (it, index) => { | 404 | + _.forEach(queryResult.data.product_list || [], it => { |
383 | const formatData = processProduct(it, { | 405 | const formatData = processProduct(it, { |
384 | width: 280, | 406 | width: 280, |
385 | height: 373 | 407 | height: 373 |
386 | }); | 408 | }); |
387 | 409 | ||
388 | - if (index > 12) { | 410 | + if (pos > 12) { |
389 | return; | 411 | return; |
390 | } | 412 | } |
391 | 413 | ||
392 | - if (index < 3) { | ||
393 | - formatData.tip = 'TOP' + (index + 1); | ||
394 | - } | ||
395 | 414 | ||
396 | - data.singlehot.imgHot.push(formatData); | 415 | + if (it.product_id) { |
416 | + formatData.idx = getIndex(it.product_skn); | ||
417 | + | ||
418 | + data.singlehot.imgHot.push(formatData); | ||
419 | + pos +=1 ; | ||
420 | + } | ||
397 | }); | 421 | }); |
398 | } | 422 | } |
423 | + | ||
424 | + data.singlehot.imgHot = _.sortBy(data.singlehot.imgHot, item => { | ||
425 | + return item.idx; | ||
426 | + }); | ||
427 | + | ||
428 | + pos = 1; | ||
429 | + _.forEach(data.singlehot.imgHot, item => { | ||
430 | + if (pos < 4 && item) { | ||
431 | + item.tip = 'TOP' + pos; | ||
432 | + pos += 1; | ||
433 | + } | ||
434 | + }); | ||
399 | data.singlehot.navs = args[1].data; | 435 | data.singlehot.navs = args[1].data; |
400 | _setChannelType(data.singlehot, type); | 436 | _setChannelType(data.singlehot, type); |
401 | return data; | 437 | return data; |
@@ -405,19 +441,20 @@ const _getSingehotViaResult = (args, queryResult, type) => { | @@ -405,19 +441,20 @@ const _getSingehotViaResult = (args, queryResult, type) => { | ||
405 | * 异步获取人气单品 | 441 | * 异步获取人气单品 |
406 | * @param {[Object]} rawData 接口返回的原始数据 | 442 | * @param {[Object]} rawData 接口返回的原始数据 |
407 | * @param {[Object]} floorData 已经经过处理的楼层数据 | 443 | * @param {[Object]} floorData 已经经过处理的楼层数据 |
444 | + * @param {String} originQuery 原始的query数据 | ||
408 | * @param {Object} queryResult 接口中用于请求人气单品的数据 | 445 | * @param {Object} queryResult 接口中用于请求人气单品的数据 |
409 | * @param {String} title 人气单品楼层的标题 | 446 | * @param {String} title 人气单品楼层的标题 |
410 | * @param {Type} type 人气单品楼层的类型 | 447 | * @param {Type} type 人气单品楼层的类型 |
411 | * @return {Object} | 448 | * @return {Object} |
412 | */ | 449 | */ |
413 | -const _processFloorDataWithQueryReusult = (rawData, queryResult, title, type) => { | 450 | +const _processFloorDataWithQueryReusult = (rawData, originQuery, queryResult, title, type) => { |
414 | let data = {}; | 451 | let data = {}; |
415 | 452 | ||
416 | _.forEach(rawData, (subData, index) => { | 453 | _.forEach(rawData, (subData, index) => { |
417 | const text = subData.data.text && _getText(subData.data.text); | 454 | const text = subData.data.text && _getText(subData.data.text); |
418 | 455 | ||
419 | if (text === title) { | 456 | if (text === title) { |
420 | - data = _getSingehotViaResult(rawData.slice(index, index + 4), queryResult, type); | 457 | + data = _getSingehotViaResult(rawData.slice(index, index + 4), originQuery, queryResult, type); |
421 | } | 458 | } |
422 | }); | 459 | }); |
423 | 460 | ||
@@ -523,12 +560,33 @@ const floorMap = { | @@ -523,12 +560,33 @@ const floorMap = { | ||
523 | }; | 560 | }; |
524 | 561 | ||
525 | 562 | ||
563 | +const needQuery = { | ||
564 | + 'GIRL KIDS': true, | ||
565 | + 'BOY KIDS': true, | ||
566 | + 人气单品: true, | ||
567 | + ACCESSORIES: true | ||
568 | +} | ||
569 | + | ||
570 | +const getQuery = args => { | ||
571 | + let goods = args[2] && args[2].data; | ||
572 | + let skns = ''; | ||
573 | + | ||
574 | + if (goods) { | ||
575 | + _.forEach(goods, good => { | ||
576 | + skns += good.id + ' '; | ||
577 | + }); | ||
578 | + } | ||
579 | + | ||
580 | + return skns; | ||
581 | +} | ||
582 | + | ||
526 | 583 | ||
527 | const _processFloorData = (rawData, type) => { | 584 | const _processFloorData = (rawData, type) => { |
528 | let floorList = []; | 585 | let floorList = []; |
529 | let searchPromise = []; | 586 | let searchPromise = []; |
530 | let singlehotFloorIndex = []; | 587 | let singlehotFloorIndex = []; |
531 | let singlehotFloorTitle = []; | 588 | let singlehotFloorTitle = []; |
589 | + let queryParam = ''; | ||
532 | 590 | ||
533 | // 定义各种楼层需要用到的接口返回的数组中元素的个数 | 591 | // 定义各种楼层需要用到的接口返回的数组中元素的个数 |
534 | const bigFloorLength = 5; | 592 | const bigFloorLength = 5; |
@@ -553,6 +611,10 @@ const _processFloorData = (rawData, type) => { | @@ -553,6 +611,10 @@ const _processFloorData = (rawData, type) => { | ||
553 | floorData = floorMap[text] && | 611 | floorData = floorMap[text] && |
554 | floorMap[text].call(null, rawData.slice(index, lastIndex), type); | 612 | floorMap[text].call(null, rawData.slice(index, lastIndex), type); |
555 | 613 | ||
614 | + if (needQuery[text]) { | ||
615 | + queryParam = getQuery(rawData.slice(index, lastIndex)); | ||
616 | + } | ||
617 | + | ||
556 | } else if (data.template_name === 'debrisSlider') { // 处理girls的banner | 618 | } else if (data.template_name === 'debrisSlider') { // 处理girls的banner |
557 | floorData = floorMap.debrisSlide.call(null, data.data); | 619 | floorData = floorMap.debrisSlide.call(null, data.data); |
558 | } | 620 | } |
@@ -591,6 +653,7 @@ const _processFloorData = (rawData, type) => { | @@ -591,6 +653,7 @@ const _processFloorData = (rawData, type) => { | ||
591 | return { | 653 | return { |
592 | floors: floorList, | 654 | floors: floorList, |
593 | promise: _.reverse(searchPromise), | 655 | promise: _.reverse(searchPromise), |
656 | + queryParam: queryParam, | ||
594 | singlehotFloorTitle: _.reverse(singlehotFloorTitle), | 657 | singlehotFloorTitle: _.reverse(singlehotFloorTitle), |
595 | singlehotFloorIndex: _.reverse(singlehotFloorIndex) | 658 | singlehotFloorIndex: _.reverse(singlehotFloorIndex) |
596 | }; | 659 | }; |
@@ -730,7 +793,7 @@ const getNewArrival = channel => { | @@ -730,7 +793,7 @@ const getNewArrival = channel => { | ||
730 | sales: 'Y', | 793 | sales: 'Y', |
731 | attribute_not: 2, | 794 | attribute_not: 2, |
732 | stocknumber: 3, | 795 | stocknumber: 3, |
733 | - shelve_time: _getShelveTime(20) | 796 | + shelve_time: _getShelveTime(2) |
734 | }; | 797 | }; |
735 | 798 | ||
736 | params.gender = channelMap[channel].gender; | 799 | params.gender = channelMap[channel].gender; |
@@ -798,6 +861,7 @@ const getContent = type => { | @@ -798,6 +861,7 @@ const getContent = type => { | ||
798 | searchPromise: processResult.promise, | 861 | searchPromise: processResult.promise, |
799 | singlehotFloorIndex: processResult.singlehotFloorIndex, | 862 | singlehotFloorIndex: processResult.singlehotFloorIndex, |
800 | singlehotFloorTitle: processResult.singlehotFloorTitle, | 863 | singlehotFloorTitle: processResult.singlehotFloorTitle, |
864 | + queryParam: processResult.queryParam, | ||
801 | channelType: type | 865 | channelType: type |
802 | }; | 866 | }; |
803 | 867 | ||
@@ -811,6 +875,7 @@ const getContent = type => { | @@ -811,6 +875,7 @@ const getContent = type => { | ||
811 | .splice(result.singlehotFloorIndex[index], 0, | 875 | .splice(result.singlehotFloorIndex[index], 0, |
812 | _processFloorDataWithQueryReusult( | 876 | _processFloorDataWithQueryReusult( |
813 | result.rawData, | 877 | result.rawData, |
878 | + result.queryParam, | ||
814 | data, | 879 | data, |
815 | result.singlehotFloorTitle[index], | 880 | result.singlehotFloorTitle[index], |
816 | result.channelType | 881 | result.channelType |
-
Please register or login to post a comment