// pages/shop-tabbar/shop-tabbar.js


// components/production/production.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    currentTab:{
      type:Number
    }
  },


  /**
   * 组件的初始数据
   */
  data: {

    list: [{
        text: "店铺首页",
        iconPath: "../../images/tabbar/shop-home.png",
        selectedIconPath: "../../images/tabbar/shop-home-sel.png"
      },

      {

        text: "全部商品",
        iconPath: "../../images/tabbar/shop-prods.png",
        selectedIconPath: "../../images/tabbar/shop-prods-sel.png"
      },
      {
        text: "商品分类",
        iconPath: "../../images/tabbar/shop-category.png",
        selectedIconPath: "../../images/tabbar/shop-category-sel.png"
      },
      {

        text: "店内搜索",
        iconPath: "../../images/tabbar/shop-search.png",
        selectedIconPath: "../../images/tabbar/shop-search-sel.png"
      }
    ],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    toProdPage: function(e) {
      var prodid = e.currentTarget.dataset.prodid;
      wx.navigateTo({
        url: '/pages/prod/prod?prodid=' + prodid,
      })
    },
    // tabbar切换
    tabChange(e) {
      const {
        index
      } = e.currentTarget.dataset
      this.setData({
        currentTab: index
      })
      if (this.data.currentTab == 0) {
        wx.redirectTo({
          url: '/pages/shopPage/shopPage',
        })

      } else if (this.data.currentTab == 1) {
        wx.redirectTo({
          url: '/pages/shopProds/shopProds',
        })
      } else if (this.data.currentTab == 2) {
        wx.redirectTo({
          url: '/pages/shopCategory/shopCategory',
        })
      } else if (this.data.currentTab == 3) {
        wx.redirectTo({
          url: '/pages/shopSearch/shopSearch',
        })
      }
    },
  },

  /**
   * 组件生命周期
   */
    lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      console.log(this.properties.currentTab)
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },
})