<template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  <home-base :show="!special || !special['index/index'] || special['index/index']['editablePage']['editable_page_theme_config']['if_show_footer']==1"><view class="div">
  <special-index v-show="special && special['index/index']" :page-path="'index/index'" :item-id="''"></special-index>

  <view class="div container" v-show="!special || !special['index/index']">
    <home-common-search :from='"home"'></home-common-search>
    <index-banner v-if="banners && banners.length > 0" :items="banners"></index-banner>
    <index-menu  :items="navs"></index-menu>
	<index-promotion-list :items="xianshiProducts" title="秒杀" v-if="xianshiProducts && xianshiProducts.length > 0"></index-promotion-list>
    <index-article :items="articles"></index-article>
    <index-three-ads :items="promotionAds"></index-three-ads>
    <index-floor-ads v-if="floorAds" :ad="floorAds[0]"></index-floor-ads>
    <index-product-list
            :items="goodProducts"
            title="热门推荐"
            :type="popular"
            v-if="goodProducts && goodProducts.length > 0"
    ></index-product-list>
	<index-floor-ads v-if="floorAds" :ad="floorAds[1]"></index-floor-ads>
    <index-product-list
            :items="hotProducts"
            title="销量排行"
            :type="sale"
            v-if="hotProducts && hotProducts.length > 0"
    ></index-product-list>
    <index-floor-ads v-if="floorAds" :ad="floorAds[2]"></index-floor-ads>
    <index-product-list
            :items="recentlyProducts"
            title="新品上架"
            :type="recently"
            v-if="recentlyProducts && recentlyProducts.length > 0"
    ></index-product-list>
    <!-- 版权信息 -->
    <view class="div copyright" v-if="config">
        <view class="div"><text class="a link" href="http://www.beian.gov.cn/portal/registerSystemInfo" target="_blank">{{config.wab_number}}</text></view>
        <view class="div"><text class="a link" href="https://beian.miit.gov.cn" target="_blank">{{config.icp_number}}</text></view>
    <view class="div">{{config.flow_static_code}}</view>
    </view>
  </view>
  </view></home-base>
</template>

<script>
import {getFontSize} from '@/util/common'
import HomeBase from '../HomeBase'
import { mapState, mapActions } from 'vuex'
import SpecialIndex from '../special/Index'
import IndexProductList from './IndexProductList'
import IndexPromotionList from './IndexPromotionList'
import HomeCommonSearch from '../common/HomeCommonSearch'
import IndexBanner from './IndexBanner'
import IndexMenu from './IndexMenu'
import IndexFloorAds from './IndexFloorAds'
import IndexThreeAds from './IndexThreeAds'
import IndexArticle from './IndexArticle'
export default {
  name:'HomeIndex',
  data () {
    return {
      isshowBacktop: true,
      popular: '',
      sale: 'goods_salenum',
      recently: 'goods_addtime'
    }
  },
  components:{
    HomeBase,
    SpecialIndex,
    IndexProductList,
	IndexPromotionList,
    HomeCommonSearch,
    IndexBanner,
    IndexMenu,
    IndexFloorAds,
    IndexThreeAds,
    IndexArticle
  },
  mounted () {
  },
  onShareAppMessage(res) {
      return {
        title: this.config.site_name,
        path: "/pages/home/index/Index"
      }
    },
  onShareTimeline(res) {
      return {
        title: this.config.site_name,
        path: "/pages/home/index/Index"
      }
    },
  created: function () {
    this.fetchHomeAd({}).then(
      response => {
      },
      error => {
        uni.showToast({icon:'none',title: error.message})
      }
    )
    this.fetchHomeArticle({}).then(
      response => {
      },
      error => {
        uni.showToast({icon:'none',title: error.message})
      }
    )
    this.fetchHomeProduct({}).then(
      response => {
      },
      error => {
        uni.showToast({icon:'none',title: error.message})
      }
    )
    this.fetchConfig({}).then(
      response => {
        uni.setNavigationBarTitle({
        	title: this.config.site_name
        })
      },
      error => {
        uni.showToast({icon:'none',title: error.message})
      }
    )
  },
  computed:{
    fontSize(){
      return getFontSize()
    },
    ...mapState({
      special: state => state.home.special,
      config: state => state.config.config,
      banners: state => state.home.banners,
      navs: state => state.home.navs,
      floorAds: state => state.home.floorAds,
      promotionAds: state => state.home.promotionAds,
      articles: state => state.home.articles,
      hotProducts: state => state.home.hotProducts,
      recentlyProducts: state => state.home.recentlyProducts,
      goodProducts: state => state.home.goodProducts,
	  xianshiProducts: state => state.home.xianshiProducts
    })
  },
  methods: {
    ...mapActions({
      fetchHomeAd: 'fetchHomeAd',
      fetchHomeArticle: 'fetchHomeArticle',
      fetchHomeProduct: 'fetchHomeProduct',
      fetchConfig: 'fetchConfig'
    })
  }
}
</script>

<style scoped lang="scss">
.copyright{font-size:$fontSize;color:#c5c5c5;text-align: center;padding:.8rem 0;
  .link{color:#c5c5c5}
}
</style>
