<template>
  <div class="index">
    <div v-if="isMobile">
      <Home></Home>
    </div>
    <div v-if="!isMobile">
     <!-- <christmas v-if="isOpen" @listenopen="listenOpen" :hasNewYear="hasNewYear"></christmas>-->
     <!-- <new-year></new-year>-->
      <carousel>
        <kind-category @loadchild="loadProductKinds"></kind-category>
        <display-card></display-card>
      </carousel>
      <!--<advert></advert>-->
      <floor-list></floor-list>
      <img class="banner-img" src="/images/all/banner-home2.jpg" style="margin: 44px auto 24px;" alt="">
      <news></news>
      <partner></partner>
    </div>
  </div>
</template>
<script>
  import { KindCategory, displayCard, Carousel, FloorList, Partner, News } from '~components/home'
//  import { Christmas, NewYear } from '~components/default'
  import { Home } from '~components/mobile'
  export default {
    name: 'index',
    // middleware: 'wechatInfo',
    layout (context) {
      return context.store.state.option.isMobile ? 'mobile' : 'main'
    },
    data () {
      return {
        isOpen: false,
        hasNewYear: false
      }
    },
    components: {
      KindCategory,
      displayCard,
      Carousel,
      // Advert,
      FloorList,
      Partner,
      News,
//      Christmas,
//      NewYear,
      Home
    },
    fetch ({store}) {
//      let today = new Date()
//      let nowYear = today.getFullYear()
//      let nowMonth = today.getMonth() + 1
//      let LastMonth = today.getMonth()
      return !store.state.option.isMobile ? Promise.all([
        store.dispatch('loadCounterData'),
        store.dispatch('loadNewFloors', {type: 'home_floor_f1,home_floor_f2,home_floor_f3,home_floor_f4,home_floor_f5,home_expand_f1,home_expand_f2'}),
        store.dispatch('loadBanners', {type: 'home_banner_carousel'}),
        store.dispatch('loadProductKinds', { id: 0 }),
        store.dispatch('loadNewsSnapshot', { page: 1, pageSize: 10 }),
        store.dispatch('loadInquirySheet'),
        store.dispatch('applyPurchase/loadPurchaseManList', {pageNumber: 1, pageSize: 50, enUU: store.state.option.user.data.enterprise ? store.state.option.user.data.enterprise.uu : null}),
        store.dispatch('loadStoreStatus', { op: 'check' })
      ]) : Promise.all([
        store.dispatch('loadCounterData'),
        store.dispatch('loadInquirySheet'),
        store.dispatch('applyPurchase/loadMobileHomeList', {pageNumber: 1, pageSize: 5, enUU: store.state.option.user.data.enterprise ? store.state.option.user.data.enterprise.uu : null})
      ])
    },
    computed: {
      user () {
        return this.$store.state.option.user
      },
      isMobile: function () {
        return this.$store.state.option.isMobile
      }
  },
    methods: {
      listenOpen () {
        this.isOpen = false
      },
      loadProductKinds (id) {
        this.$store.dispatch('loadAllProductKinds', {id})
      }
    }
  }
</script>
