Authored by hf

do new sale js ajax call paging

framework @ 75bbc3b0
1 -Subproject commit 119c247f5cf929aa1e059e40609bb16dd6b58f05 1 +Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2
@@ -28,6 +28,12 @@ if (kidsType) { @@ -28,6 +28,12 @@ if (kidsType) {
28 //srcoll to load more 28 //srcoll to load more
29 $(window).scroll(function () { 29 $(window).scroll(function () {
30 if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) { 30 if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) {
  31 +
  32 + // 没数据了,就不再加载
  33 + if (loading) {
  34 + return;
  35 + }
  36 +
31 loading = true; 37 loading = true;
32 num = $goodList.children('.good-info').length; 38 num = $goodList.children('.good-info').length;
33 $.ajax({ 39 $.ajax({
@@ -37,6 +43,11 @@ $(window).scroll(function () { @@ -37,6 +43,11 @@ $(window).scroll(function () {
37 page: page + 1 43 page: page + 1
38 }, 44 },
39 success: function(data) { 45 success: function(data) {
  46 + if (data === ' ') {
  47 + loading = true;
  48 + return;
  49 + }
  50 +
40 $goodList.append(data); 51 $goodList.append(data);
41 52
42 //lazyLoad 53 //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) {
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 </div> 15 </div>
16 16
17 <div id="load-more-info" class="load-more-info"> 17 <div id="load-more-info" class="load-more-info">
18 - <div class="loading status"> 18 + <div class="loading status hide">
19 正在加载... 19 正在加载...
20 </div> 20 </div>
21 <span class="no-more status hide">没有更多啦</span> 21 <span class="no-more status hide">没有更多啦</span>