// 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: 'https://bigaka-xie.oss-cn-shanghai.aliyuncs.com/7_3_0/tab_bar_01_a.png', 
        pageUrl: '/shoppingGuid/page/pages/college/college',
        defaultUrl: 'https://bigaka-xie.oss-cn-shanghai.aliyuncs.com/7_3_0/tab_bar_01_d.png',
        isActive : false
      },
      {
        activeUrl: 'https://bigaka-xie.oss-cn-shanghai.aliyuncs.com/7_3_0/tab_bar_02_a.png',
        pageUrl: '/shoppingGuid/page/pages/qrcode/qrcode',
        defaultUrl: 'https://bigaka-xie.oss-cn-shanghai.aliyuncs.com/7_3_0/tab_bar_02_d.png',
        isActive: false
      },
      {
        activeUrl: 'https://bigaka-xie.oss-cn-shanghai.aliyuncs.com/7_3_0/tab_bar_03_a.png',
        pageUrl: '/shoppingGuid/page/pages/home/home',
        defaultUrl: 'https://bigaka-xie.oss-cn-shanghai.aliyuncs.com/7_3_0/tab_bar_03_d.png',
        isActive: true
      },
      {
        activeUrl: 'https://bigaka-xie.oss-cn-shanghai.aliyuncs.com/7_3_0/tab_bar_04_a.png',
        pageUrl: '/shoppingGuid/page/pages/welfare/welfare',
        defaultUrl: 'https://bigaka-xie.oss-cn-shanghai.aliyuncs.com/7_3_0/tab_bar_04_d.png',
        isActive: false
      },
      {
        activeUrl: 'https://bigaka-xie.oss-cn-shanghai.aliyuncs.com/7_3_0/tab_bar_05_a.png',
        pageUrl: '/shoppingGuid/page/pages/achievement/achievement',
        defaultUrl: 'https://bigaka-xie.oss-cn-shanghai.aliyuncs.com/7_3_0/tab_bar_05_d.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,
      });
    }
  }
})
