<template>
  <div class="index">
    <div v-if="isMobile">

    </div>
    <div v-else>
      <carousel>
        <kind-category @loadchild="loadProductKinds"></kind-category>
      </carousel>
      <advert></advert>
      <floor-list></floor-list>
      <news></news>
      <partner></partner>
    </div>
  </div>
</template>
<script>
  import { KindCategory, Carousel, Advert, FloorList, Partner, News } from '~components/home'

  export default {
    name: 'index',
    layout: 'main',
    fetch ({ store }) {
      return Promise.all([
        store.dispatch('loadFloors'),
        store.dispatch('loadBanners', {type: 'home'}),
        store.dispatch('loadProductKinds', { id: 0 }),
        store.dispatch('loadNewsSnapshot', { page: 1, pageSize: 10 }),
        store.dispatch('loadProductCounts', { _status: 'actived' })
      ])
    },
    components: {
      KindCategory,
      Carousel,
      Advert,
      FloorList,
      Partner,
      News
    },
    methods: {
      loadProductKinds (id) {
        this.$store.dispatch('loadAllProductKinds', {id})
      }
    },
    computed: {
      isMobile: function () {
        return this.$store.state.option.isMobile
      }
    }
  }
</script>
