Authored by 梁志锋

Merge branch 'develop' of git.dev.yoho.cn:web/yohobuy into develop

framework @ 75bbc3b0
1 -Subproject commit 119c247f5cf929aa1e059e40609bb16dd6b58f05 1 +Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2
@@ -31,6 +31,12 @@ if (kidsType) { @@ -31,6 +31,12 @@ if (kidsType) {
31 //srcoll to load more 31 //srcoll to load more
32 $(window).scroll(function () { 32 $(window).scroll(function () {
33 if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) { 33 if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) {
  34 +
  35 + // 没数据了,就不再加载
  36 + if (loading) {
  37 + return;
  38 + }
  39 +
34 loading = true; 40 loading = true;
35 num = $goodList.children('.good-info').length; 41 num = $goodList.children('.good-info').length;
36 $.ajax({ 42 $.ajax({
@@ -40,6 +46,11 @@ $(window).scroll(function () { @@ -40,6 +46,11 @@ $(window).scroll(function () {
40 page: page + 1 46 page: page + 1
41 }, 47 },
42 success: function(data) { 48 success: function(data) {
  49 + if (data === ' ') {
  50 + loading = true;
  51 + return;
  52 + }
  53 +
43 $goodList.append(data); 54 $goodList.append(data);
44 55
45 //lazyLoad 56 //lazyLoad
@@ -5,9 +5,16 @@ var $ = require('yoho.zepto'), @@ -5,9 +5,16 @@ var $ = require('yoho.zepto'),
5 var $curNav, 5 var $curNav,
6 $navList = $('#discount-nav'), 6 $navList = $('#discount-nav'),
7 $newArrivalList = $('#discount-goods-list'), 7 $newArrivalList = $('#discount-goods-list'),
8 - $goods = $newArrivalList.children('.goods-list'); 8 + $goods = $newArrivalList.children('.goods-list'),
  9 + $goodList = $('.goods-list');
9 10
10 var swiper; 11 var swiper;
  12 +var index = 0,
  13 + winH = $(window).height(),
  14 + loadMoreH = $('#load-more').height(),
  15 + loading = false,
  16 + page = 0,
  17 + pd = "";
11 18
12 swiper = new Swiper('.swiper-container', { 19 swiper = new Swiper('.swiper-container', {
13 lazyLoading: true, 20 lazyLoading: true,
@@ -19,14 +26,14 @@ $curNav = $navList.children('.focus'); @@ -19,14 +26,14 @@ $curNav = $navList.children('.focus');
19 26
20 $('#discount-nav').delegate('li', 'touchstart', function() { 27 $('#discount-nav').delegate('li', 'touchstart', function() {
21 var $this = $(this), 28 var $this = $(this),
22 - $content,  
23 - index; 29 + $content;
24 30
25 if ($this.hasClass('focus')) { 31 if ($this.hasClass('focus')) {
26 return; 32 return;
27 } 33 }
28 34
29 index = $this.index(); 35 index = $this.index();
  36 + pd = getSalePdByChoose(index);
30 37
31 $this.addClass('focus'); 38 $this.addClass('focus');
32 $curNav.removeClass('focus'); 39 $curNav.removeClass('focus');
@@ -38,4 +45,70 @@ $('#discount-nav').delegate('li', 'touchstart', function() { @@ -38,4 +45,70 @@ $('#discount-nav').delegate('li', 'touchstart', function() {
38 $curNav = $this; 45 $curNav = $this;
39 46
40 $(document).trigger('scroll'); //Trigger lazyLoad 47 $(document).trigger('scroll'); //Trigger lazyLoad
41 -});  
  48 +});
  49 +
  50 +//srcoll to load more
  51 +$(window).scroll(function () {
  52 + if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) {
  53 + if (loading) {
  54 + return;
  55 + }
  56 + loading = true;
  57 + num = $goodList.children('.good-info').length;
  58 + $.ajax({
  59 + type: 'GET',
  60 + url: '/product/newsale/selectNewSale',
  61 + data: {
  62 + p_d: pd,
  63 + page: page + 1
  64 + },
  65 + success: function(data) {
  66 + if (data === ' ') {
  67 +
  68 + //opt.end = true;
  69 + loading = false;
  70 + return;
  71 + }
  72 +
  73 + $goodList.append(data);
  74 +
  75 + //lazyLoad
  76 + //lazyLoad($goodList.children('.good-info:gt(' + (num - 1) + ')').find('img.lazy'));
  77 + lazyLoad($('.good-info').find('img.lazy'));
  78 +
  79 + loading = false;
  80 + page++;
  81 + },
  82 + error: function() {
  83 + tip.show('网络断开连接了~');
  84 + loading = false;
  85 + }
  86 + });
  87 + }
  88 +
  89 +});
  90 +
  91 +/**
  92 + * 根据用户的选择获取商品折扣值
  93 + *
  94 + * @param int index
  95 + * @return string
  96 + */
  97 +function getSalePdByChoose(index) {
  98 + var pd = "0.1,0.3";
  99 + switch (index) {
  100 + case 0:
  101 + pd = "0.1,0.3";
  102 + break;
  103 + case 1:
  104 + pd = "0.4,0.6";
  105 + break;
  106 + case 2:
  107 + pd = "0.7,0.9";
  108 + break;
  109 + case 3:
  110 + pd = "0.1,0.9";
  111 + break;
  112 + }
  113 + return pd;
  114 +}
@@ -59,8 +59,9 @@ $(window).scroll(function () { @@ -59,8 +59,9 @@ $(window).scroll(function () {
59 num = $goodList.children('.good-info').length; 59 num = $goodList.children('.good-info').length;
60 $.ajax({ 60 $.ajax({
61 type: 'GET', 61 type: 'GET',
62 - url: '/product/newsale/selectNewSale?dayLimit' + (index + 1), 62 + url: '/product/newsale/selectNewSale',
63 data: { 63 data: {
  64 + dayLimit: index + 1,
64 page: page + 1 65 page: page + 1
65 }, 66 },
66 success: function(data) { 67 success: function(data) {