<template>
  <div class="home-page">
    <div class="task-body">
      <!-- 左侧菜单 -->
      <div class="menu">
        <div class="taskManager">任务管理</div>
        <div
          v-for="(item, index) in menuItems"
          :key="index"
          class="menu-item"
          @click="selectMenu(item.value)"
        >
          <img :src="item.url" alt="" class="menu-img" />
          <div v-if="item.badge !== 0">
            <el-badge :value="item.badge" class="badge">
              <div
                :class="['menu-text', {active: selectedMenu === item.value}]"
              >
                {{ item.label }}
              </div>
            </el-badge>
          </div>
          <div
            v-else
            :class="['menu-text', {active: selectedMenu === item.value}]"
          >
            {{ item.label }}
          </div>
        </div>
      </div>
      <!-- 右侧内容 -->
      <div class="content">
        <div v-if="taskList.length > 0" class="task-relative">
          <div>
            <div
              v-for="(item, index) in taskList"
              :key="item.id"
              class="task-item"
              :title="item.content"
              @click="taskChange(item)"
            >
              <span class="task-content"
                >{{ index + 1 }}.{{ item.content }}</span
              >
              <span class="task-date">{{ item.date }}</span>
            </div>
          </div>
          <div class="task-page">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="page"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="10"
              layout="total, sizes, prev, pager, next, jumper"
              :total="taskList.length"
            >
            </el-pagination>
          </div>
        </div>
        <el-empty v-else description="暂无数据" class="task-empty"></el-empty>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      selectedMenu: 'todo',
      menuItems: [
        {
          label: '待办事项',
          value: 'todo',
          url: require('@/assets/img/homePage/manage1.png'),
          badge: 5
        },
        {
          label: '超时任务',
          value: 'timeout',
          url: require('@/assets/img/homePage/manage2_s.png'),
          badge: 1
        },
        {
          label: '已办事项',
          value: 'done',
          url: require('@/assets/img/homePage/manage3_s.png'),
          badge: 0
        },
        {
          label: '全部事项',
          value: 'all',
          url: require('@/assets/img/homePage/manage4_s.png'),
          badge: 0
        }
      ],
      taskList: [
        {
          id: '1',
          content: '待办事项XXXXXXXXXXXXXXXXXXXXXXX',
          date: '2025-01-25'
        },
        {
          id: '2',
          content: '待办事项XXXXXXXXXXXXXXXXXXXXXXX',
          date: '2025-01-25'
        },
        {
          id: '3',
          content: '待办事项XXXXXXXXXXXXXXXXXXXXXXX',
          date: '2025-01-25'
        },
        {
          id: '4',
          content: '待办事项XXXXXXXXXXXXXXXXXXXXXXX',
          date: '2025-01-25'
        },
        {
          id: '5',
          content: '待办事项XXXXXXXXXXXXXXXXXXXXXXX',
          date: '2025-01-25'
        }
      ],
      page: 1
    }
  },
  methods: {
    // 左边菜单点击
    selectMenu(value) {
      this.selectedMenu = value
      if (value === 'timeout') {
        this.taskList = [
          {
            id: '6',
            content: '超时任务XXXXXXXXXXXXXXXXXXXXXXX',
            date: '2025-01-25'
          }
        ]
      } else if (value === 'done') {
        this.taskList = []
      } else if (value === 'all') {
        this.taskList = []
      } else {
        this.taskList = [
          {
            id: 1,
            content: '待办事项XXXXXXXXXXXXXXXXXXXXXXX',
            date: '2025-01-25'
          },
          {
            id: 2,
            content: '待办事项XXXXXXXXXXXXXXXXXXXXXXX',
            date: '2025-01-25'
          },
          {
            id: 3,
            content: '待办事项XXXXXXXXXXXXXXXXXXXXXXX',
            date: '2025-01-25'
          },
          {
            id: 4,
            content: '待办事项XXXXXXXXXXXXXXXXXXXXXXX',
            date: '2025-01-25'
          },
          {
            id: 5,
            content: '待办事项XXXXXXXXXXXXXXXXXXXXXXX',
            date: '2025-01-25'
          }
        ]
      }
    },
    // 右边内容点击
    taskChange(item) {
      this.$router.push({path: '/gateway/detailsPage', query: {id: item.id}})
    },
    handleSizeChange() {},
    handleCurrentChange() {}
  }
}
</script>

<style scoped lang="scss">
.home-page {
  width: 100%;
  background: #f5f8fa;
  display: flex;
  justify-content: center;
  .task-body {
    width: 1200px;
    display: flex;
    margin: 16px 0;
  }
}
.menu {
  width: 200px;
  padding: 16px;
  box-sizing: border-box;
  margin-right: 10px;
  background-color: #ffffff;
  border-radius: 10px;
  .taskManager {
    text-align: center;
    font-size: 22px;
    font-weight: 700;
    color: #333333;
    padding-bottom: 16px;
    border-bottom: 1px solid #e6e6e6;
  }
  .menu-item {
    display: flex;
    align-items: center;
    padding: 16px;
    box-sizing: border-box;
    cursor: pointer;
    .menu-img {
      width: 16px;
      height: 16px;
      margin-right: 10px;
    }
    .menu-text {
      transition: all 0.3s;
      color: #999999;
      font-size: 18px;
      font-family: Microsoft YaHei, Microsoft YaHei;
    }
  }
  .menu-item:hover {
    box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
  }
  .menu-item:hover .menu-text {
    color: #1150a0;
  }
  .menu-item .active {
    color: #1150a0;
  }
}
.content {
  width: 990px;
  padding: 16px;
  border-radius: 10px;
  box-sizing: border-box;
  background-color: #fff;
  .task-relative {
    position: relative;
    top: 0;
    left: 0;
  }
  .task-page {
    width: calc(990px - 32px);
    text-align: center;
    position: fixed;
    bottom: 32px;
  }
  .task-empty {
    margin-top: 150px;
  }
  .task-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 32px 16px 32px 16px;
    border-bottom: 1px solid;
    border-image: linear-gradient(270deg, #ffffff, #d0dded) 1;
    cursor: pointer;
    .task-content {
      font-size: 20px;
      color: #333333;
      font-weight: 700;
    }
    .task-date {
      font-size: 15px;
      color: #909399;
    }
  }
  .task-item:hover {
    border-radius: 6px;
    box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
  }
  .task-item:hover .task-content {
    color: #1150a0;
  }
  .task-item:first-child {
    padding: 16px 16px 32px 16px;
  }
  .task-item:last-child {
    border: none;
  }
}
</style>
