Authored by 梁志锋

modify

@@ -9,8 +9,12 @@ new Swiper('.swiper-container', { @@ -9,8 +9,12 @@ new Swiper('.swiper-container', {
9 autoplay: 3000 9 autoplay: 3000
10 }); 10 });
11 11
12 -//img-lazyload  
13 -function lazyLoad(imgs) { 12 +/**
  13 + * 初始化页面功能
  14 + */
  15 +exports.init = function (url) {
  16 + //img-lazyload
  17 + function lazyLoad(imgs) {
14 var $imgs; 18 var $imgs;
15 if (typeof imgs === 'undefined') { 19 if (typeof imgs === 'undefined') {
16 $imgs = $('img.lazy'); 20 $imgs = $('img.lazy');
@@ -22,41 +26,83 @@ function lazyLoad(imgs) { @@ -22,41 +26,83 @@ function lazyLoad(imgs) {
22 effect_speed: 10, 26 effect_speed: 10,
23 placeholder: 'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==' 27 placeholder: 'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=='
24 }); 28 });
25 -} 29 + }
26 30
27 -lazyLoad(); 31 + lazyLoad();
28 32
29 33
30 -var $newArrival = $('.new-arrival:last'); 34 + var $newArrival = $('.new-arrival:last');
31 35
32 -// 无最新单品推荐模块时直接返回  
33 -if ($newArrival.length === 0) { 36 + // 无最新单品推荐模块时直接返回
  37 + if ($newArrival.length === 0) {
34 return; 38 return;
35 -} 39 + }
36 40
37 -var isLogin = $('#is-login').val();  
38 -isLogin = isLogin ? isLogin : 'N';  
39 -//登录提示变量  
40 -var $loginTip = $('#login-tip'); 41 + var isLogin = $('#is-login').val();
  42 + isLogin = isLogin ? isLogin : 'N';
  43 + //登录提示变量
  44 + var $loginTip = $('#login-tip');
41 45
42 -var winH = $(window).height(), 46 + var winH = $(window).height(),
43 loading = false, 47 loading = false,
44 end = false, 48 end = false,
45 page = 1, 49 page = 1,
46 tpl; 50 tpl;
47 -  
48 -var $goodList = $newArrival.children('.goods-list'),  
49 - mblTop = $newArrival.offset().top; //页面内容固定,可以预先求出高度  
50 -  
51 -//read good-info template  
52 -$.get('/common/goodinfo', function (data) { 51 + var $father = $('.new-arrival-content');
  52 + //var $goodList = $newArrival.children('.goods-list'),
  53 + var mblTop = $newArrival.offset().top; //页面内容固定,可以预先求出高度
  54 +
  55 + tpl = ["<div class=\"good-info\" data-id=\"{{id}}\">",
  56 + " <div class=\"tag-container clearfix\">",
  57 + " {{# tags}}",
  58 + " {{# isNew}}",
  59 + " <p class=\"good-tag new-tag\">NEW</p>",
  60 + " {{/ isNew}}",
  61 + " {{# isReNew}}",
  62 + " <p class=\"good-tag renew-tag\">再到着</p>",
  63 + " {{/ isReNew}}",
  64 + " {{# isSale}}",
  65 + " <p class=\"good-tag sale-tag\">SALE</p>",
  66 + " {{/ isSale}}",
  67 + " {{# isYohood}}",
  68 + " <div class=\"good-tag yohood-tag\"></div>",
  69 + " {{/ isYohood}}",
  70 + " {{# isLimit}}",
  71 + " <p class=\"good-tag limit-tag\">限量商品</p>",
  72 + " {{/ isLimit}}",
  73 + " {{/ tags}}",
  74 + " </div>",
  75 + " <div class=\"good-detail-img\">",
  76 + " <a class=\"good-islike {{# isLike}}good-like{{/ isLike}} iconfont\" href=\"{{likeUrl}}\">&#xe605;</a>",
  77 + " <a class=\"good-thumb\" href=\"{{url}}\">",
  78 + " <img class=\"lazy\" data-original=\"{{src}}\">",
  79 + " </a>",
  80 + " {{# isFew}}",
  81 + " <p class=\"few-tag\">即将售罄</p>",
  82 + " {{/ isFew}}",
  83 + " </div>",
  84 + " <div class=\"good-detail-text\">",
  85 + " <div class=\"name\">",
  86 + " <a href=\"{{url}}\">{{name}}</a>",
  87 + " </div>",
  88 + " <div class=\"price\">",
  89 + " <span class=\"sale-price {{^price}}no-price{{/price}}\">¥{{salePrice}}</span>",
  90 + " {{#price}}",
  91 + " <span class=\"market-price\">¥{{.}}</span>",
  92 + " {{/price}}",
  93 + " </div>",
  94 + " </div>",
  95 + "</div>"].join("");
  96 + tpl = '{{# goods}}' + tpl + '{{/ goods}}';
  97 + //read good-info template
  98 + /*$.get('/common/goodinfo', function (data) {
53 tpl = '{{# goods}}' + data + '{{/ goods}}'; 99 tpl = '{{# goods}}' + data + '{{/ goods}}';
54 Mustache.parse(tpl); 100 Mustache.parse(tpl);
55 -});  
56 - 101 + });*/
  102 + Mustache.parse(tpl);
57 103
58 -//srcoll to load more  
59 -$(window).scroll(function () { 104 + //srcoll to load more
  105 + $(window).scroll(function () {
60 var num; 106 var num;
61 if (end || loading) { 107 if (end || loading) {
62 return; 108 return;
@@ -67,10 +113,10 @@ $(window).scroll(function () { @@ -67,10 +113,10 @@ $(window).scroll(function () {
67 } 113 }
68 114
69 loading = true; 115 loading = true;
70 - num = $goodList.children('.good-info').length; 116 + num = $father.children('.good-info').length;
71 $.ajax({ 117 $.ajax({
72 type: 'GET', 118 type: 'GET',
73 - url: '/goods/more', 119 + url: url,
74 data: { 120 data: {
75 //gender: 0, //性别 121 //gender: 0, //性别
76 page: page + 1 122 page: page + 1
@@ -84,19 +130,18 @@ $(window).scroll(function () { @@ -84,19 +130,18 @@ $(window).scroll(function () {
84 if (res.end) { 130 if (res.end) {
85 end = res.end; 131 end = res.end;
86 } 132 }
87 -  
88 - $goodList.append(Mustache.render(tpl, { 133 + console.log("aaa");
  134 + $father.append(Mustache.render(tpl, {
89 goods: res.goods 135 goods: res.goods
90 })); 136 }));
91 137
92 //lazyLoad 138 //lazyLoad
93 - lazyLoad($goodList.children('.good-info:gt(' + (num - 1) + ')').find('img.lazy')); 139 + lazyLoad($father.children('.good-info:gt(' + (num - 1) + ')').find('img.lazy'));
94 140
95 loading = false; 141 loading = false;
96 page++; 142 page++;
97 } 143 }
98 }); 144 });
99 -});  
100 -  
101 - 145 + });
  146 +};
102 147
1 <script src="http://localhost:8000/public/js/new-festival.js"></script> 1 <script src="http://localhost:8000/public/js/new-festival.js"></script>
2 <script type="text/javascript"> 2 <script type="text/javascript">
3 - seajs.use('public/js/new-festival'); 3 + seajs.use('public/js/new-festival',function(newfestival){
  4 + newfestival.init('url');
  5 + });
4 </script> 6 </script>