<template>
  <div class="navitem">
    <el-radio-group class="logo">
      <IconSvg :W="44" :H="44" name="item-logo" />
    </el-radio-group>
    <el-menu
      text-color="#fff"
      background-color="rgba(41, 109, 227, 1)"
      :default-active="$route.path"
      class="el-menu-vertical-demo"
      @select="handleOpen"
      :collapse="isCollapse"
      router
    >
      <el-menu-item v-for="item in roles" :key="item.route" :index="'/'+item.route">
        <div class="icons">
          <div v-if="ItemIndex== `/${item.route}`">
            <IconSvg :W="26" :H="25" :name="`${item.route}-active`" />
          </div>
          <div v-else>
            <IconSvg :W="26" :H="25" :name="item.route" />
          </div>
          <!-- <IconSvg
            :W="26"
            :H="25"
            :name="ItemIndex == `/${item.route}`  ? `${item.route}-active` : `${item.route}`"
          />-->
        </div>
        <span slot="title">{{item.title}}</span>
      </el-menu-item>
      <!-- <el-menu-item index="/order">
        <div class="icons">
          <IconSvg :W="26" :H="25" :name="ItemIndex == '/order' ? 'order-active' : 'order'" />
        </div>
        <span slot="title">订单管理</span>
      </el-menu-item>
      <el-menu-item index="/staff">
        <div class="icons">
          <IconSvg :W="26" :H="25" :name="ItemIndex == '/staff' ? 'staff-active' : 'staff'" />
        </div>
        <span slot="title">员工管理</span>
      </el-menu-item>
      <el-menu-item index="/account">
        <div class="icons">
          <IconSvg :W="26" :H="25" :name="ItemIndex == '/account' ? 'account-active' : 'account'" />
        </div>
        <span slot="title">账号管理</span>
      </el-menu-item>
      <el-menu-item index="/stat">
        <div class="icons">
          <IconSvg :W="26" :H="25" :name="ItemIndex == '/stat' ? 'stat-active' : 'stat'" />
        </div>
        <span slot="title">统计报表</span>
      </el-menu-item>
      <el-menu-item index="/system">
        <div class="icons">
          <IconSvg :W="26" :H="25" :name="ItemIndex == '/system' ? 'system-active' : 'system'" />
        </div>
        <span slot="title">系统设置</span>
      </el-menu-item>-->
    </el-menu>
  </div>
</template>

<script>
export default {
  name: "NavbarItem",
  data() {
    return {
      isCollapse: false,
      roles: []
    };
  },
  created() {
    this.getData();
  },
  computed: {
    ItemIndex: {
      get() {
        return this.$route.path;
      },
      set(val) {}
    }
  },
  methods: {
    handleOpen(index, indexPath) {
      // console.log(index, indexPath);
    },

    getData() {
      // console.log(this.$store.state.user.roles);
      this.$store.state.user.roles.forEach((item, index) => {
        if (item == "home") {
          this.roles[index] = { route: item, title: "房态管理" };
        } else if (item == "order") {
          this.roles[index] = { route: item, title: "订单管理" };
        } else if (item == "staff") {
          this.roles[index] = { route: item, title: "员工管理" };
        } else if (item == "account") {
          this.roles[index] = { route: item, title: "账号管理" };
        } else if (item == "stat") {
          this.roles[index] = { route: item, title: "统计报表" };
        } else if (item == "system") {
          this.roles[index] = { route: item, title: "系统设置" };
        }
      });
      // console.log(this.roles);
    }
  }
};
</script>

<style scoped lang="scss">
.navitem {
  width: 260px;

  .logo {
    height: 96px;
    border-bottom: 1px solid rgba(255, 255, 255, 1);
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .el-menu {
    margin-top: 33px;

    .is-active {
      background-color: #fff !important;
      color: rgba(41, 109, 227, 1);
    }

    .el-menu-item {
      height: 52px;
      line-height: 0;
      margin-bottom: 13px;
      font-size: 18px;
      display: flex;
      align-items: center;
      border: 1px solid transparent;
      box-sizing: border-box;

      .icons {
        margin-left: 27px;
      }

      span {
        width: 87px;
        height: 26px;
        display: flex;
        align-items: center;
        padding-left: 16px;
      }
    }
  }
}
</style>