// subPackage/component/tabBar/tabBar.js

var app = getApp()
const wxService = require('../../../utils/wxService')
const utils = require('../../../utils/util')
const utilLink = require('../../../utils/currentLinkRouter')
const envInfo = require('../../../config/index').envInfo

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    index : {
      type : Number,
      value : 0
    }
  },

  attached(){
    this.data.tabBar.forEach(item => {
      item.isActive = false;
    });

    this.data.tabBar[this.data.index].isActive = true;
    this.setData({
      tabBar: this.data.tabBar
    });
  },

  /**
   * 组件的初始数据
   */
  data: {
    tabBar : [
      { 
        activeUrl: '/assets/imgs/shoppingGuide/home_active.png', 
        pageUrl: '/shoppingGuid/page/pages/home/home',
        defaultUrl: '/assets/imgs/shoppingGuide/home_default.png',
        isActive : true
      },
      {
        activeUrl: '/assets/imgs/shoppingGuide/kpi_active.png',
        pageUrl: '/shoppingGuid/page/pages/kpi/kpi',
        defaultUrl: '/assets/imgs/shoppingGuide/kpi_default.png',
        isActive: false
      },
      {
        activeUrl: '/assets/imgs/shoppingGuide/welfare_active.png',
        pageUrl: '/shoppingGuid/page/pages/welfare/welfare',
        defaultUrl: '/assets/imgs/shoppingGuide/welfare_default.png',
        isActive: false
      },
      {
        activeUrl: '/assets/imgs/shoppingGuide/achievement_active.png',
        pageUrl: '/shoppingGuid/page/pages/achievement/achievement',
        defaultUrl: '/assets/imgs/shoppingGuide/achievement_default.png',
        isActive: false
      },
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //点击
    onTapToPage(e){
      let item = e.currentTarget.dataset.item;
      let index = e.currentTarget.dataset.index;
      //如果点击是本页面，则不进行任何跳转
      if(this.data.index == index){
        return ;
      }
      wx.redirectTo({
        url: item.pageUrl,
      });
    }
  }
})
