<template>
  <xd-layout
    title="商品分类"
    background="#f8f8f8"
    :show-back="false"
    @back="back"
    @onDone="handleDone"
  >
    <view
      v-if="layoutInfo"
      :style="{height: layoutInfo.bodyMinHeight}"
    >
      <xd-store-product-type
        :default-index="0"
        @onNavList="handleNavList"
        @onAdsList="handleAdsList"
        @onSubNavList="handleSubNavList"
        @onToDetail="handleToDetail"
      ></xd-store-product-type>
    </view>
  </xd-layout>
</template>

<script>
  import XdLayout from "@/components/XdLayout/XdLayout";
  import XdStoreProductType from "@/dome/components/XdStoreProductType/XdStoreProductType";

  export default {
    name: "XdCartInde",
    components: {
      XdStoreProductType,
      XdLayout,
    },
    data() {
      return {
        isFirst: false,
        layoutInfo: null
      }
    },
    created(){

    },

    methods: {
      handleDone(layoutInfo){
        this.layoutInfo = layoutInfo;
        console.log('layoutInfo', layoutInfo)
      },

      back(){
        this.$xdUniHelper.navigateBack()
      },

      /**
       * @description 获取一级分类列表
       * @param resolve 成功回调事件 null=> 使用测试数据  array => 正式数控
       */
      handleNavList(resolve) {
        this.$xdShowLoading({})
        setTimeout(() => {
          resolve(null);
          this.$xdHideLoading();
        }, 1000)
      },

      /**
       * @description 获取分类推广广告
       * @param resolve 成功回调事件 null=> 使用测试数据  object => 正式数控
       * @param item
       */
      handleAdsList({item},resolve){
        if(this.isFirst) this.$xdShowLoading({})
        setTimeout(() => {
          resolve(null);
          if(!this.isFirst) this.isFirst = true;
          if(this.isFirst) this.$xdHideLoading()
        }, 1000)
      },

      /**
       * @description 获取二级分类列表
       * @param item 当前点击连接对象
       * @param resolve 当前快速连接所在列表位置
       */
      handleSubNavList({item}, resolve){
        console.log('handleSubNavList', item);
        setTimeout(() => {
          resolve(null);
        }, 1000)
      },


      /**
       * @description 切换配送地址
       * @param item 分类对象数据
       */
      handleToDetail(item) {
        console.log('handleToDetail', item);
      }


    }
  }
</script>

<style scoped lang="less">

</style>
