<template>
  <view>
    <view v-if="isShow">
      <u-tabbar :value="currentTab" activeColor="#2D73F0" inactiveColor="#333" :border="true">
        <u-tabbar-item
          v-for="item in clientList"
          :key="item.name"
          :text="item.text"
          :name="item.name"
          @click="handTab(item)"
        >
          <image class="bar_img" slot="active-icon" :src="item.selectedIconPath" />
          <image class="bar_img" slot="inactive-icon" :src="item.iconPath" />
        </u-tabbar-item>
      </u-tabbar>
    </view>
    <view v-if="!isShow">
      <u-tabbar :value="currentTab" activeColor="#2D73F0" inactiveColor="#333" :border="true">
        <u-tabbar-item
          v-for="item in merchantList"
          :key="item.name"
          :text="item.text"
          :name="item.name"
          @click="handTab(item)"
        >
          <image class="bar_img" slot="active-icon" :src="item.selectedIconPath" />
          <image class="bar_img" slot="inactive-icon" :src="item.iconPath" />
        </u-tabbar-item>
      </u-tabbar>
    </view>
  </view>
</template>

<script>
// TODO： 商家端自定义tabbar待处理
export default {
  name: 'TabBar',
  props: {
    currentTab: {
      type: String,
      default: 'clientHome',
    },
  },

  data() {
    return {
      isShow: true,
      clientList: [
        {
          text: '首页',
          name: 'clientHome',
          pagePath: '/pages/client/tabBar/home/index',
          iconPath: '/static/images/home.png',
          selectedIconPath: '/static/images/home-select.png',
        },
        {
          text: '社区',
          name: 'clientCommunity',
          pagePath: '/pages/client/tabBar/community/index',
          iconPath: '/static/images/community.png',
          selectedIconPath: '/static/images/community-select.png',
        },
        {
          text: '消息',
          name: 'clientMessage',
          pagePath: '/pages/client/tabBar/message/index',
          iconPath: '/static/images/message.png',
          selectedIconPath: '/static/images/message-select.png',
        },
        {
          text: '我的',
          name: 'clientMine',
          pagePath: 'pages/client/tabBar/mine/index',
          iconPath: '/static/images/mine.png',
          selectedIconPath: '/static/images/mine-select.png',
        },
      ],
      merchantList: [
        {
          text: '订单',
          name: 'merchantOrder',
          pagePath: 'pages/merchant/tabBar/order/index',
          iconPath: '/static/images/home.png',
          selectedIconPath: '/static/images/home-select.png',
        },
        {
          text: '消息',
          name: 'merchantMessage',
          pagePath: 'pages/merchant/tabBar/message/index',
          iconPath: '/static/images/community.png',
          selectedIconPath: '/static/images/community-select.png',
        },
        {
          text: '推广',
          name: 'merchantExtend',
          pagePath: 'pages/merchant/tabBar/extend/index',
          iconPath: '/static/images/community.png',
          selectedIconPath: '/static/images/community-select.png',
        },
        {
          text: '店铺',
          name: 'merchantStore',
          pagePath: 'pages/merchant/tabBar/store/index',
          iconPath: '/static/images/message.png',
          selectedIconPath: '/static/images/message-select.png',
        },
        {
          text: '我的',
          name: 'merchantMine',
          pagePath: 'pages/merchant/tabBar/mine/index',
          iconPath: '/static/images/mine.png',
          selectedIconPath: '/static/images/mine-select.png',
        },
      ],
    };
  },
  mounted() {
    this.isShow = uni.getStorageSync('tabbar_type')
  },
  watch:{
    isShow(newValue){
      console.log('@@@newValue',newValue);
    }
  },
  methods: {
    handTab(row) {
      if(this.isShow){
        uni.switchTab({
          url: row.pagePath,
        });
      }else{
        uni.navigateTo({
          url: row.pagePath,
        });
      }

    },
  },
};
</script>

<style lang="scss" scoped>
.bar_img {
  width: 54rpx;
  height: 54rpx;
}

::deep .u-tabbar {
  border-top: 2rpx solid #dadbde;
}
</style>
