article-nice.vue
1.79 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<template>
<Article
ref="article"
type="niceGoods"
:title="title"
:thumbs="articleNiceThumbList"
:on-fetch="onFetch"
:pos-id="sceneId">
</Article>
</template>
<script>
import {get} from 'lodash';
import Article from './components/article/article';
import {createNamespacedHelpers} from 'vuex';
import YAS from 'utils/yas-constants';
const {mapState, mapActions} = createNamespacedHelpers('article');
export default {
name: 'ArticleNicePage',
data() {
return {
title: '发现好货',
sceneId: YAS.scene.list
};
},
async serverPrefetch() {
return this.fetchFindNiceGoodsArticles({
page: 1,
limit: 3,
thumb: true
});
},
computed: {
...mapState(['articleNiceThumbList'])
},
methods: {
...mapActions(['fetchFindNiceGoodsArticles']),
init() {
this.page = 1;
this.$refs.article.init();
},
async onFetch() {
if (this.fetching) {
return [];
}
this.fetching = true;
this.page = this.page || 1;
const result = await this.fetchFindNiceGoodsArticles({
page: this.page
});
let list = [];
let end = false;
if (result.code === 200) {
this.page++;
if (get(result, 'data.detailList'|| []).length) {
list = result.data.detailList;
}
if (this.page > get(result, 'data.totalPage')) {
end = true;
}
} else {
this.$createToast && this.$createToast({
txt: result.message || '服务器开小差了',
type: 'warn',
time: 1000
}).show();
}
this.fetching = false;
return end ? false : list;
}
},
components: {
Article
}
};
</script>
<style lang="scss" scoped>
.article-page {
background-color: #f0f0f0;
}
</style>