<template>
  <div class="app-main app-content">
    <app-swiper
      v-if="!$util.isEmpty(ad)"
      :list="ad"
      @detail="adDetailFn"
    />
    <!-- <div @click="pageTo({url: '/pages/home/recent'})">返回首页</div> -->
    <block v-if="!$util.isEmpty(category)">
      <div
        class="goods-module"
        v-for="(item, index) in category"
        :key="index"
      >
        <goods-list-big
          v-if="item.showRow == 1"
          :info="item"
        />
        <goods-list-small
          v-if="item.showRow == 2"
          :info="item"
        />
      </div>
    </block>
    <app-trademark />
    <tab-bar :current="0"></tab-bar>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import AppSwiper from "@/components/app-swiper";
import AppTrademark from "@/components/module/app-trademark";
import goodsListBig from "@/pages/home/components/goods-list-big";
import goodsListMiddle from "@/pages/home/components/goods-list-middle";
import goodsListSmall from "@/pages/home/components/goods-list-small";
import { getMainIndex } from "@/api/home";
import { getOrderShop } from "@/utils/config";
import { getShopUser } from "@/utils/auth";
import { share } from "@/mixins";
export default {
  name: "home",
  components: {
    AppSwiper,
    AppTrademark,
    goodsListBig,
    goodsListMiddle,
    goodsListSmall
  },
  mixins: [share],
  data () {
    return {
      data: {},
      ad: [],
      category: [],
      columnStyle: null,
      currentTabIndex: 0,
      account: '',
      pageTitle: ''
    };
  },
  computed: {
    ...mapGetters({ orderShop: "getOrderShop" })
  },
  onLoad (option) {},
  mounted () { },
  onShow () {
    uni.hideTabBar();
    // this.init();
  },
  methods: {
    init () {
      getOrderShop().then(res => {
      })
      this._detail().then(res => {
        let account = uni.getStorageSync('account')
        console.log(this.pageTitle)
        getShopUser().then(res => {
          // 设置分享
          let shareParams = {
            title: this.pageTitle, // 分享标题
            desc: "", // 分享内容
            imgUrl: '',
            // #ifndef H5
            pagePath: `/pages/home/index?fromUserId=${res.id}&account=${account}`
            // #endif
          }
          this.jweixinFn(shareParams)
          console.log('分享地址',`/pages/home/index?fromUserId=${res.id}&account=${account}`)
        })
      })
    },
    _detail () {
      return getMainIndex().then(res => {
        this.data = res.data;
        if (this.$util.isEmpty(res.data)) return false;
        this.ad = res.data.ad.map(e => {
          e.img = e.adImg;
          return e;
        });
        this.pageTitle = res.data.sj.name
        uni.setNavigationBarTitle({
          title: this.pageTitle
        })
        this.category = res.data.category;
        this.columnStyle = res.data.columnStyle;
      });
    },
    adDetailFn (item) {
      // #ifdef H5
      location.href = item.url;
      // #endif
    },
    tabClick (index) {
      this.currentTabIndex = index
    }
  }
};
</script>

<style lang="scss" scoped>
.goods-module {
  padding: 0 20px;
  margin-top: 40px;
  /deep/.buy-com-btn {
    font-size: 24px;
    padding: 10px 20px 12px;
    box-shadow: 8px 8px 20px #eee;
  }
}
</style>
