controller.js
1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
import {
Controller
} from 'yoho-mvc';
import {
GetMore
} from './view';
import {
moreGoods as getMore
} from './model';
const lazyLoad = require('yoho-jquery-lazyload');
const goodContent = require('3party/material/goods.hbs');
class MaterialController extends Controller {
constructor() {
super();
lazyLoad($('img.lazy'));
this.more = new GetMore();
this.more.on('more', this.doMore.bind(this));
this.page = 1;
this.loading = false;
}
doMore() {
if (!this.end && !this.loading) {
this.page ++;
this.moreGood(this.page);
}
}
moreGood(page) {
this.loading = true;
$('.material-c').append('<p class="show-more good-more">加载更多...</p>');
getMore('//m.yohobuy.com/3party/material/moreGoods', {
page: page,
union_type: window.queryString.union_type
}).then(data => {
if (data.goods.length > 0) {
$('.goods-list').append(goodContent(data));
// 每次只lazyload倒数10
lazyLoad($('img.lazy'));
} else {
$('.material-c').append('<p class="show-more">没有更多了...</p>');
this.end = true;
}
}).catch(() => {}).finally(() => {
this.loading = false;
$('.good-more').remove();
});
}
}
module.exports = MaterialController;