// commpents/mobile-frame/mobile-main.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  options: { multipleSlots: true },
  properties: {
    tabSelectid: { type: 'string', value: '' }
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached: function () { }, // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready: function () { },
  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show: function () { this.search() },
    hide: function () { },
    resize: function () { },
  },
  /**
   * 组件的初始数据
   */
  data: {
    active: 0,
    one: {
      normal: '/image/shouye.png',
      active: '/image/shouye-01.png',
    },
    two: {
      normal: '/image/saishi.png',
      active: '/image/saishi-01.png',
    },
    three: {
      normal: '/image/miaobiao.png',
      active: '/image/miaobiao-01.png',
    },
    four: {
      normal: '/image/duiwu.png',
      active: '/image/duiwu-01.png',
    },
    five: {
      normal: '/image/wodexiao.png',
      active: '/image/wodexiao-01.png',
    },
  },
  /**
   * 组件的方法列表
   */
  methods: {
    // 跳转
    tabPath(e) {
      this.setData({ active: e.detail })
      let route = e.detail == 0 ? 'home' : e.detail == 1 ? 'search' : e.detail == '2' ? 'administration' : e.detail == '3' ? 'team' : e.detail == '4' ? 'me' : '';
      this.triggerEvent('tabPath', route)
    },
    search() {
      let pages = getCurrentPages();
      let currentPage = pages[pages.length - 1];
      if (currentPage.route == 'pages/home/index') {
        this.setData({ active: 0 })
      } else if (currentPage.route == 'pages/search/index') {
        this.setData({ active: 1 })
      } else if (currentPage.route == 'pages/administration/index') {
        this.setData({ active: 2 })
      } else if (currentPage.route == 'pages/team/index') {
        this.setData({ active: 3 })
      } else if (currentPage.route == 'pages/me/index') {
        this.setData({ active: 4 })
      }
    }
  }
})

