Authored by 李奇

结果页上拉加载更多实现

@@ -112,7 +112,7 @@ class GroupService extends global.yoho.BaseModel { @@ -112,7 +112,7 @@ class GroupService extends global.yoho.BaseModel {
112 }); 112 });
113 113
114 return { 114 return {
115 - recommend 115 + ...recommend
116 }; 116 };
117 117
118 } catch (e) { 118 } catch (e) {
  1 +<div class="product-item" data-product-skn="{{productSkn}}" data-activity-id="{{activityId}}">
  2 + <img src="{{image2 defaultImages w=200 h=282 q=80}}" alt="商品图片" class="prd-item-img">
  3 + <div class="prd-info">
  4 + <div class="prd-name">{{#ifcond @root.data.joinLimit '==' 1}}<span class="tag"></span>{{/ifcond
  5 + }}{{productName}}</div>
  6 + <div class="price">
  7 + <span class="cprice">¥{{collagePrice}}</span>
  8 + <span class="mprice">¥{{marketPrice}}</span>
  9 + </div>
  10 + {{#ifcond joinPeopleNum '>' 0}}
  11 + <span class="joined">{{joinPeopleNum}} 人已參加</span>
  12 + {{/ifcond}}
  13 + <div class="buy-btn">
  14 + <span class="num">{{peopleNum}}人成团</span>
  15 + <span class="immediate">立即购买</span>
  16 + </div>
  17 + </div>
  18 +</div>
@@ -8,6 +8,7 @@ import dialog from 'js/plugin/dialog'; @@ -8,6 +8,7 @@ import dialog from 'js/plugin/dialog';
8 import lazyLoad from 'yoho-jquery-lazyload'; 8 import lazyLoad from 'yoho-jquery-lazyload';
9 import yoSdk from 'yoho-activity-sdk'; 9 import yoSdk from 'yoho-activity-sdk';
10 let yoho = require('js/yoho-app'); 10 let yoho = require('js/yoho-app');
  11 +let recItem = require('hbs/activity/group/progress-rec-item.hbs');
11 12
12 class GroupProgress extends Page { 13 class GroupProgress extends Page {
13 constructor() { 14 constructor() {
@@ -30,6 +31,7 @@ class GroupProgress extends Page { @@ -30,6 +31,7 @@ class GroupProgress extends Page {
30 groupPrice: '', 31 groupPrice: '',
31 shareImgUrl: '' 32 shareImgUrl: ''
32 }; 33 };
  34 + this.page = 2;
33 this.loading = false; 35 this.loading = false;
34 this.loadedAll = false; 36 this.loadedAll = false;
35 37
@@ -50,7 +52,6 @@ class GroupProgress extends Page { @@ -50,7 +52,6 @@ class GroupProgress extends Page {
50 let self = this; 52 let self = this;
51 53
52 window.onscroll = function() { 54 window.onscroll = function() {
53 -  
54 if (timeout !== null) { 55 if (timeout !== null) {
55 clearTimeout(timeout); 56 clearTimeout(timeout);
56 } 57 }
@@ -82,7 +83,7 @@ class GroupProgress extends Page { @@ -82,7 +83,7 @@ class GroupProgress extends Page {
82 } 83 }
83 84
84 bindEvents() { 85 bindEvents() {
85 - this.selector.$productItem.on('click', this.goDetail.bind(this)); 86 + $(document).on('click', '.product-item', this.goDetail.bind(this));
86 this.selector.$goJoin.on('click', this.goJoin.bind(this)); 87 this.selector.$goJoin.on('click', this.goJoin.bind(this));
87 this.selector.$joinGroup.on('click', this.joinGroup.bind(this)); 88 this.selector.$joinGroup.on('click', this.joinGroup.bind(this));
88 this.selector.$inviteJoin.on('click', this.inviteJoin.bind(this)); 89 this.selector.$inviteJoin.on('click', this.inviteJoin.bind(this));
@@ -326,7 +327,7 @@ class GroupProgress extends Page { @@ -326,7 +327,7 @@ class GroupProgress extends Page {
326 } 327 }
327 328
328 loadMoreData() { 329 loadMoreData() {
329 - if (this.loading && !this.loadedAll) { 330 + if (this.loading || this.loadedAll) {
330 return; 331 return;
331 } 332 }
332 333
@@ -334,15 +335,35 @@ class GroupProgress extends Page { @@ -334,15 +335,35 @@ class GroupProgress extends Page {
334 this.ajax({ 335 this.ajax({
335 url: '/activity/group/groupResultRec', 336 url: '/activity/group/groupResultRec',
336 data: { 337 data: {
337 - page: 2,  
338 - limit: 2 338 + page: this.page,
  339 + limit: 4
  340 + }
  341 + }).then(result => {
  342 + if (!result.collageProductVoList) {
  343 + this.loading = false;
  344 + this.loadedAll = true;
  345 + return;
339 } 346 }
340 - }).then(() => { 347 +
  348 + this.page = this.page + 1;
  349 + this.renderMoreData(result.collageProductVoList);
341 this.loading = false; 350 this.loading = false;
342 }).catch(() => { 351 }).catch(() => {
343 this.loading = false; 352 this.loading = false;
344 }); 353 });
345 } 354 }
  355 +
  356 + renderMoreData(list) {
  357 + console.log('render data');
  358 +
  359 + let appendHtml = '';
  360 +
  361 + list.forEach(item => {
  362 + appendHtml += recItem(item);
  363 + });
  364 +
  365 + $('.recommend').append(appendHtml);
  366 + }
346 } 367 }
347 368
348 $(() => { 369 $(() => {