<template>
  <div
    :class="{ 'has-logo': showLogo }"
    :style="{
      backgroundColor:
        settings.sideTheme === 'theme-dark'
          ? variables.menuBackground
          : variables.menuLightBackground,
    }"
  >
    <logo v-if="showLogo && setting" :collapse="isCollapse" />
    <!-- 首页切换系统 -->
    <div v-else class="Logo" style="padding: 8px 12px">
      <!-- <el-select v-model="activeId" size="mini" @change="handleDirectToProject">
        <el-option
          v-for="item in menuList"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        />
      </el-select> -->
    </div>
    <el-scrollbar :class="settings.sideTheme" wrap-class="scrollbar-wrapper">
      <el-menu
        :default-active="activeMenu"
        :collapse="isCollapse"
        :background-color="
          settings.sideTheme === 'theme-dark'
            ? variables.menuBackground
            : variables.menuLightBackground
        "
        :text-color="
          settings.sideTheme === 'theme-dark'
            ? variables.menuColor
            : variables.menuLightColor
        "
        :unique-opened="true"
        :active-text-color="settings.theme"
        :collapse-transition="false"
        mode="vertical"
      >
        <sidebar-item
          v-for="(route, index) in sidebarRouters"
          :key="route.path + index"
          :item="route"
          :base-path="route.path"
        />
      </el-menu>
    </el-scrollbar>
  </div>
</template>

<script>
import { mapGetters, mapState } from "vuex";
import Logo from "./Logo";
import SidebarItem from "./SidebarItem";
import variables from "@/assets/styles/variables.scss";
import { systemMenu } from "@/api/system/menu";

export default {
  components: { SidebarItem, Logo },
  data() {
    return {
      activeId: 2,
      menuList: [],
    };
  },
  computed: {
    ...mapState(["settings"]),
    ...mapGetters(["sidebarRouters", "sidebar"]),
    activeMenu() {
      const route = this.$route;
      const { meta, path } = route;
      // if set path, the sidebar will highlight the path you set
      if (meta.activeMenu) {
        return meta.activeMenu;
      }
      return path;
    },
    showLogo() {
      return this.$store.state.settings.sidebarLogo;
    },
    setting() {
      return process.env.VUE_APP_TITLE === "东旭达WMS管理系统";
    },
    variables() {
      return variables;
    },
    isCollapse() {
      return !this.sidebar.opened;
    },
  },
  mounted() {
    this.getSystemMenuList();
  },
  methods: {
    async getSystemMenuList() {
      return;
      const { data } = await systemMenu({ pagesize: 10 });
      // this.menuList = data?.list
      this.menuList = [
        {
          name: "WMS(仓储管理系统)",
          enableFlag: true,
          id: 2,
          createTime: 1702454281000,
        },
        {
          name: "MES(制造执行系统）",
          enableFlag: true,
          id: 1,
          createTime: 1702454273000,
        },
      ];
    },
    handleDirectToProject() {
      let locationUrl;
      // const token = {
      //   accessToken: getAccessToken(),
      //   refreshToken: getRefreshToken()
      // }
      if (
        window.location.hostname === "192.168.1.163" ||
        window.location.hostname === "localhost"
      ) {
        switch (this.activeId) {
          case 1:
            locationUrl = process.env.VUE_APP_MES_URL;
            break;
          case 2:
            locationUrl = process.env.VUE_APP_WMS_URL;
            break;
          case 3:
            locationUrl = process.env.VUE_APP_ETM_URL;
            break;
          case 0:
            locationUrl = process.env.VUE_APP_SYSTEM_URL;
            break;
        }
      } else if (
        window.location.hostname === "113.105.183.190" &&
        process.env.VUE_APP_TITLE === "东旭达WMS管理系统"
      ) {
        switch (this.activeId) {
          case 1:
            locationUrl = "http://113.105.183.190:8167/index";
            break;
          case 2:
            locationUrl = "http://113.105.183.190:8267/index";
            break;
        }
      }
      window.location.href = locationUrl;
      // const open = (window.location.href = locationUrl)
      // setTimeout(() => {
      //   open.postMessage(token, locationUrl)
      // }, 2500)
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-input__inner {
  background-color: #2e3e52;
  border-color: transparent;
  border-radius: 0;
  color: white;
}
</style>
