<template>
  <div id="app">
    <el-container>
      <el-header height="60px" style="background-color: #333; color: white; display: flex; align-items: center; justify-content: space-between;">
        <h1 style="margin: 0; font-size: 18px;">租房管理系统</h1>
        <el-button type="primary" plain @click="logout">退出</el-button>
      </el-header>
      <el-container>
        <el-aside width="200px" style="background-color: #f0f2f5; min-height: calc(100vh - 60px);">
          <el-menu
            :default-active="activeIndex"
            class="el-menu-vertical-demo"
            @select="handleSelect"
            background-color="#f0f2f5"
            text-color="#333"
            active-text-color="#409EFF"
          >
            <el-menu-item index="dashboard">
              <i class="el-icon-s-home"></i>
              <span>首页</span>
            </el-menu-item>
            <el-menu-item index="region-list">
              <i class="el-icon-location"></i>
              <span>区域管理</span>
            </el-menu-item>
            <el-menu-item index="apartment-list">
              <i class="el-icon-office-building"></i>
              <span>公寓管理</span>
            </el-menu-item>
            <el-menu-item index="room-list">
              <i class="el-icon-menu"></i>
              <span>房间管理</span>
            </el-menu-item>
            <el-menu-item index="rental-list">
              <i class="el-icon-key"></i>
              <span>租房管理</span>
            </el-menu-item>
            <el-menu-item index="rent-statistics">
              <i class="el-icon-data-analysis"></i>
              <span>租金统计</span>
            </el-menu-item>
            <el-menu-item index="room-statistics">
              <i class="el-icon-data-analysis"></i>
              <span>房间状态统计</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main style="padding: 20px;">
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      activeIndex: 'dashboard'
    }
  },
  methods: {
    handleSelect(key, keyPath) {
      this.activeIndex = key
      // 根据选择的菜单项导航到对应的路由
      const routeMap = {
        'dashboard': '/',
        'region-list': '/region/list',
        'region-add': '/region/add',
        'apartment-list': '/apartment/list',
        'apartment-add': '/apartment/add',
        'room-list': '/room/list',
        'room-add': '/room/add',
        'rental-list': '/rental/list',
        'rental-add': '/rental/add',
        'rent-statistics': '/statistics/rent',
        'room-statistics': '/statistics/room'
      }
      if (routeMap[key] && this.$route.path !== routeMap[key]) {
        this.$router.push(routeMap[key])
      }
    },
    logout() {
      // 退出登录逻辑
      this.$message.success('退出成功')
    }
  }
}
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
</style>