<template>
  <div class="tab-bar-item" :class="isActive? 'inActive':'active'" @click="itemClick">
    <div v-if="!isActive" style='text-align: center;'>
      <slot name="item-icon"></slot>
    </div>
    <div v-else style='text-align: center;'>
      <slot name="item-icon-active"></slot>
    </div>
    <div :style="activeStyle">
      <slot name="item-text"></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: "TarBarItem",
  props: {
    path: String,
    activeColor: {
      type: String,
      /*如果没有参数 则这个为默认的颜色*/
      default: '#ffffff'
    },
    curTab: String
  },
  data() {
    return {
      // isActive: true
    }
  },
  computed: {
    isActive() {
      return this.curTab === this.path
    },
    activeStyle() {
      return this.isActive ? {color: this.activeColor} : {}
    }
  },
  methods: {
    itemClick() {
      uni.$emit('switchTab', this.path);
    }
  }
}
</script>

<style scoped>
.tab-bar-item {
  text-align: center;
  vertical-align: middle;
  padding: 0 15px;
  width: 100px;
  height: 100px;
}

.active {
  background-color: #132138;
}

.inActive {
  background-color: #0285ff;
}

.tab-bar-item img {
  width: 60px;
  height: 40px;
}
</style>
