Blame view

apps/pages/article/article-nice.vue 2.09 KB
yyq authored
1 2 3 4 5 6 7
<template>
  <Article
    ref="article"
    type="niceGoods"
    :title="title"
    :thumbs="articleNiceThumbList"
    :on-fetch="onFetch"
陈峰 authored
8
    :no-header="noHeader"
lea guo authored
9 10
    :pos-id="sceneId"
  >
yyq authored
11 12 13 14
  </Article>
</template>

<script>
lea guo authored
15
import { get } from 'lodash';
yyq authored
16
import Article from './components/article/article';
lea guo authored
17
import { createNamespacedHelpers, mapState } from 'vuex';
yyq authored
18
import YAS from 'utils/yas-constants';
lea guo authored
19 20 21
const { mapState: articleMapState, mapActions } = createNamespacedHelpers(
  'article'
);
yyq authored
22 23 24 25 26

export default {
  name: 'ArticleNicePage',
  data() {
    return {
lea guo authored
27
      title: '',
yyq authored
28 29 30
      sceneId: YAS.scene.list
    };
  },
lea guo authored
31
  mounted() {
lea guo authored
32 33 34 35
    // 自定义title
    const { title = '' } = this.$route.query || {};

    this.title = title || '发现好货';
lea guo authored
36
  },
yyq authored
37 38 39 40 41 42 43 44
  async serverPrefetch() {
    return this.fetchFindNiceGoodsArticles({
      page: 1,
      limit: 3,
      thumb: true
    });
  },
  computed: {
陈峰 authored
45 46 47
    ...articleMapState(['articleNiceThumbList']),
    ...mapState(['yoho']),
    noHeader() {
陈峰 authored
48
      return this.yoho.context.env.isChat;
陈峰 authored
49
    }
yyq authored
50 51 52 53 54 55 56 57 58 59 60 61 62
  },
  methods: {
    ...mapActions(['fetchFindNiceGoodsArticles']),
    init() {
      this.page = 1;
      this.$refs.article.init();
    },
    async onFetch() {
      if (this.fetching) {
        return [];
      }

      this.fetching = true;
yyq authored
63
      this.page = this.page || 1;
yyq authored
64 65 66 67 68 69

      const result = await this.fetchFindNiceGoodsArticles({
        page: this.page
      });

      let list = [];
ityuany authored
70
yyq authored
71 72 73 74 75
      let end = false;

      if (result.code === 200) {
        this.page++;
陈峰 authored
76
        if (get(result, 'data.detailList' || []).length) {
yyq authored
77 78 79 80 81 82 83
          list = result.data.detailList;
        }

        if (this.page > get(result, 'data.totalPage')) {
          end = true;
        }
      } else {
lea guo authored
84 85 86 87 88 89
        this.$createToast &&
          this.$createToast({
            txt: result.message || '服务器开小差了',
            type: 'warn',
            time: 1000
          }).show();
yyq authored
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
      }
      this.fetching = false;

      return end ? false : list;
    }
  },
  components: {
    Article
  }
};
</script>

<style lang="scss" scoped>
.article-page {
  background-color: #f0f0f0;
}
</style>