Component({
  data: {
    selected: 0,
    "color": "#AAAFC4",
    "selectedColor": "#0BC3AA",
    list: [{
      "pagePath": "/pages/index/index",
      "text": "控制主页",
      "iconPath": "/static/tabs/home@2x.png",
      "selectedIconPath": "/static/tabs/home-active@2x.png"
    },
    {
      "pagePath": "/pages/shop/shop",
      "text": "商城",
      "iconPath": "/static/tabs/report@2x.png",
      "selectedIconPath": "/static/tabs/report-active@2x.png"
    },
    {
      "pagePath": "/pages/data/data",
      "text": "睡眠报告",
      "iconPath": "/static/tabs/report@2x.png",
      "selectedIconPath": "/static/tabs/report-active@2x.png"
    },
    {
      "pagePath": "/pages/mine/mine",
      "text": "我的",
      "iconPath": "/static/tabs/mine@2x.png",
      "selectedIconPath": "/static/tabs/mine-active@2x.png"
    }]
  },
  attached() {
    const app = getApp();
    this.setData({
      selected: app.globalData.selectedTabIndex || 0
    })
    console.log("da=>", app.globalData.selectedTabIndex);
  },

  methods: {
    switchTab(e) {
      const data = e.currentTarget.dataset
      const url = data.path
      if (url === "/pages/shop/shop") {
        wx.showToast({
          icon: "none",
          title: '暂未开通',
        })
        return
      }
      console.log("data.index", data.index);
      wx.switchTab({ url })

      const app = getApp();
      app.globalData.selectedTabIndex = data.index;

    }
  }
})