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
59
60
61
62
63
64
| /**
| * 数据加载监听
| */
| module.exports = Behavior({
| data: {
| cPage: 1,
| tPage: 1,
| totalCount: 0,
| loading: false,
| needLoadMore: false
| },
| observers: {
| 'loading': function (loading) {
| if (loading) {
| this._loadStart()
| this._loading()
| } else {
| this._loadComplete()
| }
| },
| 'cPage, tPage': function (cPage, tPage) {
| this.setData({
| needLoadMore: cPage < tPage
| })
| },
| 'reachBottom': function(reachBottom) {
| if (reachBottom) {
| this._onReachBottom()
| }
| },
| },
| methods: {
| _onReachBottom() {
| console.log('_onReachBottom');
| let {cPage, tPage, loading} = this.data
| if (!loading && cPage < tPage) {
| if (typeof this.loadmore === 'function') {
| this.loadmore(cPage)
| }
| }
| },
| // 加载开始通知
| _loadStart() {
| this.triggerEvent('loadStart')
| if (typeof this.loadStart === 'function') {
| this.loadStart()
| }
| },
| // 加载中通知
| _loading() {
| this.triggerEvent('loading')
| if (typeof this.loading === 'function') {
| this.loading()
| }
| },
| // 加载完成通知
| _loadComplete() {
| this.triggerEvent('loadComplete')
| if (typeof this.loadComplete === 'function') {
| this.loadComplete()
| }
| }
| }
| })
|
|