<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: 120px;
  height: 120px;
  border-top: 1px solid #505462;
  border-bottom: 1px solid #505462;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  flex-direction: column;
  justify-content: center;
}

.active {
  background-color: #132138;
}

.inActive {
  background-color: #4ea381;
}

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