<template>
  <div class="operation-inspection">
    <div class="navigation-tabs">
      <div class="nav-tab" @click="handleInspection1">待办事项</div>
      <div class="nav-tab active" @click="handleInspection2">巡检管理</div>
      <div class="nav-tab">试验管理</div>
      <div class="nav-tab">报修管理</div>
      <div class="nav-tab">抢修管理</div>
      <div class="nav-tab">工单管理</div>
    </div>
    <div style="display: flex; align-items: center; gap: 1200px">
      <TitleComponent title="运维巡检管理" subtitle="制定巡检计划，安排巡检任务，跟进巡检记录"></TitleComponent>
      <div style="display: flex; align-items: center; gap: 10px">
        <el-button type="primary" class="export-btn">筛选</el-button>
        <el-button type="primary" class="create-btn">导入数据</el-button>
      </div>
    </div>

    <!-- 选项卡和按钮组合 -->
    <div class="tabs-wrapper">
      <div style="display: flex; align-items: center; gap: 10px">
        <el-button type="primary" @click="handleInspectionManagement1">巡检计划</el-button>
        <el-button type="primary" @click="handleInspectionManagement2">巡检任务</el-button>
        <el-button type="primary" @click="handleInspectionManagement3">巡检记录</el-button>
      </div>
    </div>

    <!-- 筛选栏 -->
    <div class="filter-bar">
      <div class="filter-item">
        <el-select v-model="filterStatus" placeholder="状态" clearable>
          <el-option label="全部状态" value="all"></el-option>
          <el-option label="正常" value="normal"></el-option>
          <el-option label="需关注" value="attention"></el-option>
          <el-option label="有问题" value="problem"></el-option>
        </el-select>
      </div>
      <div class="filter-item">
        <el-select v-model="filterType" placeholder="巡检类型" clearable>
          <el-option label="全部类型" value="all"></el-option>
          <el-option label="数据库" value="database"></el-option>
          <el-option label="服务器" value="server"></el-option>
          <el-option label="网络设备" value="network"></el-option>
        </el-select>
      </div>
      <div class="filter-item">
        <el-date-picker
          v-model="dateRange"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="YYYY-MM-DD"
        ></el-date-picker>
      </div>
      <div class="filter-actions">
        <el-button type="primary" class="search-btn">搜索</el-button>
      </div>
    </div>

    <!-- 主内容区 -->
    <div class="grid grid-cols-1 lg:grid-cols-3 gap-6" style="grid-auto-rows: 1fr">
      <!-- 左侧和中间内容区 -->
      <div class="lg:col-span-2 space-y-6">
        <!-- 巡检记录与报告卡片 -->
        <div class="content-card">
          <div class="card-header">
            <h2 class="card-title">巡检记录与报告</h2>
            <div class="flex space-x-2">
              <button
                class="px-3 py-1 text-sm rounded-md hover:bg-gray-200 transition"
                :class="{ 'bg-gray-100 text-gray-700': timeRange === 'month', 'bg-white text-gray-500': timeRange !== 'month' }"
                @click="handleTimeRangeChange('month')"
              >
                月
              </button>
              <button
                class="px-3 py-1 text-sm rounded-md hover:bg-gray-100 transition"
                :class="{ 'bg-gray-100 text-gray-700': timeRange === 'week', 'bg-white text-gray-500': timeRange !== 'week' }"
                @click="handleTimeRangeChange('week')"
              >
                周
              </button>
              <button
                class="px-3 py-1 text-sm rounded-md hover:bg-gray-100 transition"
                :class="{ 'bg-gray-100 text-gray-700': timeRange === 'day', 'bg-white text-gray-500': timeRange !== 'day' }"
                @click="handleTimeRangeChange('day')"
              >
                日
              </button>
            </div>
          </div>

          <!-- 数据卡片 -->
          <div class="card-body">
            <div class="grid grid-cols-2 md:grid-cols-4 gap-4">
              <div class="stat-card">
                <p class="stat-label">本月完成巡检</p>
                <p class="stat-value">42</p>
              </div>
              <div class="stat-card">
                <p class="stat-label">发现问题数</p>
                <p class="stat-value">7</p>
              </div>
              <div class="stat-card">
                <p class="stat-label">已解决问题</p>
                <p class="stat-value">5</p>
              </div>
              <div class="stat-card">
                <p class="stat-label">平均完成时间</p>
                <p class="stat-value">45分钟</p>
              </div>
            </div>

            <div class="divider"></div>

            <!-- 图表区域 -->
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6 py-4">
              <!-- 饼图 - 本月巡检完成情况 -->
              <div class="md:col-span-1">
                <p class="chart-title">本月完成巡检</p>
                <div class="relative w-32 h-32 mx-auto">
                  <!-- 饼图使用SVG绘制 - 显示本月巡检完成情况 -->
                  <svg class="w-full h-full" viewBox="0 0 100 100">
                    <!-- 背景圆环 -->
                    <circle cx="50" cy="50" r="45" fill="none" stroke="#f3f4f6" stroke-width="10" />
                    <!-- 已完成部分 (72%) -->
                    <circle
                      cx="50"
                      cy="50"
                      r="45"
                      fill="none"
                      stroke="#10b981"
                      stroke-width="10"
                      stroke-dasharray="282.74"
                      stroke-dashoffset="113.1"
                      transform="rotate(-90 50 50)"
                    />
                    <!-- 未完成部分 (28%) -->
                    <circle
                      cx="50"
                      cy="50"
                      r="45"
                      fill="none"
                      stroke="#f97316"
                      stroke-width="10"
                      stroke-dasharray="113.1"
                      stroke-dashoffset="0"
                      transform="rotate(-90 50 50)"
                    />
                  </svg>
                  <!-- 饼图中心显示 -->
                  <div class="absolute inset-0 flex flex-col items-center justify-center">
                    <p class="text-sm text-gray-500">已解决问题</p>
                    <p class="text-lg font-bold text-gray-800">72%</p>
                  </div>
                </div>
                <!-- 饼图图例 -->
                <div class="mt-3 flex justify-center space-x-4">
                  <div class="flex items-center">
                    <div class="w-3 h-3 rounded-full bg-green-500 mr-1"></div>
                    <span class="text-xs text-gray-600">已解决</span>
                  </div>
                  <div class="flex items-center">
                    <div class="w-3 h-3 rounded-full bg-orange-500 mr-1"></div>
                    <span class="text-xs text-gray-600">未解决</span>
                  </div>
                </div>
              </div>

              <!-- 进度条 -->
              <div class="md:col-span-2 flex flex-col justify-center">
                <div class="space-y-4">
                  <div>
                    <div class="flex justify-between text-sm mb-1">
                      <span class="text-gray-600">完成率</span>
                      <span class="font-medium text-gray-800">68%</span>
                    </div>
                    <div class="w-full bg-gray-200 rounded-full h-2">
                      <div class="bg-red-500 h-2 rounded-full" style="width: 68%"></div>
                    </div>
                  </div>
                  <div>
                    <div class="flex justify-between text-sm mb-1">
                      <span class="text-gray-600">解决率</span>
                      <span class="font-medium text-gray-800">72%</span>
                    </div>
                    <div class="w-full bg-gray-200 rounded-full h-2">
                      <div class="bg-green-500 h-2 rounded-full" style="width: 72%"></div>
                    </div>
                  </div>
                  <div>
                    <div class="flex justify-between text-sm mb-1">
                      <span class="text-gray-600">及时率</span>
                      <span class="font-medium text-gray-800">60%</span>
                    </div>
                    <div class="w-full bg-gray-200 rounded-full h-2">
                      <div class="bg-gray-500 h-2 rounded-full" style="width: 60%"></div>
                    </div>
                  </div>
                </div>
              </div>
            </div>

            <div class="divider"></div>

            <!-- 发现问题种类 -->
            <div class="py-4">
              <h3 class="section-title">发现问题种类</h3>
              <div class="space-y-4">
                <div>
                  <div class="flex justify-between text-sm mb-1">
                    <span class="text-gray-600">温度异常率</span>
                    <span class="text-gray-500">85%</span>
                  </div>
                  <div class="w-full bg-gray-200 rounded-full h-2">
                    <div class="bg-blue-500 h-2 rounded-full" style="width: 85%"></div>
                  </div>
                </div>
                <div>
                  <div class="flex justify-between text-sm mb-1">
                    <span class="text-gray-600">内存使用率</span>
                    <span class="text-gray-500">62%</span>
                  </div>
                  <div class="w-full bg-gray-200 rounded-full h-2">
                    <div class="bg-blue-500 h-2 rounded-full" style="width: 62%"></div>
                  </div>
                </div>
                <div>
                  <div class="flex justify-between text-sm mb-1">
                    <span class="text-gray-600">CPU负载</span>
                    <span class="text-gray-500">45%</span>
                  </div>
                  <div class="w-full bg-gray-200 rounded-full h-2">
                    <div class="bg-blue-500 h-2 rounded-full" style="width: 45%"></div>
                  </div>
                </div>
                <div>
                  <div class="flex justify-between text-sm mb-1">
                    <span class="text-gray-600">响应时间</span>
                    <span class="text-gray-500">30%</span>
                  </div>
                  <div class="w-full bg-gray-200 rounded-full h-2">
                    <div class="bg-blue-500 h-2 rounded-full" style="width: 30%"></div>
                  </div>
                </div>
                <div>
                  <div class="flex justify-between text-sm mb-1">
                    <span class="text-gray-600">磁盘空间状态</span>
                    <span class="text-gray-500">15%</span>
                  </div>
                  <div class="w-full bg-gray-200 rounded-full h-2">
                    <div class="bg-blue-500 h-2 rounded-full" style="width: 15%"></div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 右侧最近巡检结果 -->
      <div class="lg:col-span-1" style="display: flex; flex-direction: column; height: 100%">
        <div class="content-card" style="flex: 1; display: flex; flex-direction: column">
          <div class="card-header">
            <h2 class="card-title">最近巡检结果</h2>
          </div>

          <!-- 巡检结果列表 -->
          <div class="card-body" style="flex: 1; overflow-y: auto">
            <div class="inspection-results space-y-4">
              <!-- 结果1：正常 -->
              <div class="inspection-card bg-white border border-gray-200 rounded-lg p-4 shadow-sm">
                <div class="flex justify-between items-start mb-4">
                  <h3 class="text-lg font-medium text-gray-800">数据库性能巡检</h3>
                  <span class="status-tag status-normal px-3 py-1 text-xs">正常</span>
                </div>
                <p class="text-sm text-gray-500 mb-3">2025-06-15 14:00-16:45 张明</p>

                <div class="flex justify-between items-center mb-4">
                  <div class="flex flex-col items-center">
                    <i class="fas fa-check-circle text-green-500 text-lg mb-1"></i>
                    <span class="text-xs text-gray-600 mb-1">系统连接量</span>
                    <span class="text-sm font-medium">128<500</span>
                  </div>
                  <div class="flex flex-col items-center">
                    <i class="fas fa-check-circle text-green-500 text-lg mb-1"></i>
                    <span class="text-xs text-gray-600 mb-1">查询响应时间</span>
                    <span class="text-sm font-medium">平均0.3S</span>
                  </div>
                  <div class="flex flex-col items-center">
                    <i class="fas fa-check-circle text-green-500 text-lg mb-1"></i>
                    <span class="text-xs text-gray-600 mb-1">表空间使用率</span>
                    <span class="text-sm font-medium">75%</span>
                  </div>
                  <div class="flex flex-col items-center">
                    <i class="fas fa-check-circle text-green-500 text-lg mb-1"></i>
                    <span class="text-xs text-gray-600 mb-1">日志文件</span>
                    <span class="text-sm font-medium">正常轮转</span>
                  </div>
                </div>

                <div class="flex justify-end gap-2">
                  <el-button size="small" class="text-sm border-gray-300 text-gray-600">查看详情</el-button>
                  <el-button type="primary" size="small" class="text-sm">生成报告</el-button>
                </div>
              </div>

              <!-- 结果2：需关注 -->
              <div class="inspection-card bg-white border border-gray-200 rounded-lg p-4 shadow-sm">
                <div class="flex justify-between items-start mb-4">
                  <h3 class="text-lg font-medium text-gray-800">生产服务器日常巡检</h3>
                  <span class="status-tag status-attention px-3 py-1 text-xs">需关注</span>
                </div>
                <p class="text-sm text-gray-500 mb-3">2025-06-15 14:00-16:45 张明</p>

                <div class="flex justify-between items-center mb-4">
                  <div class="flex flex-col items-center">
                    <i class="fas fa-check-circle text-green-500 text-lg mb-1"></i>
                    <span class="text-xs text-gray-600 mb-1">CPU使用率</span>
                    <span class="text-sm font-medium">平均35%，峰值59%</span>
                  </div>
                  <div class="flex flex-col items-center">
                    <i class="fas fa-exclamation-circle text-yellow-500 text-lg mb-1"></i>
                    <span class="text-xs text-gray-600 mb-1">内存使用率</span>
                    <span class="text-sm font-medium">85%</span>
                  </div>
                  <div class="flex flex-col items-center">
                    <i class="fas fa-check-circle text-green-500 text-lg mb-1"></i>
                    <span class="text-xs text-gray-600 mb-1">磁盘空间</span>
                    <span class="text-sm font-medium">62%</span>
                  </div>
                  <div class="flex flex-col items-center">
                    <i class="fas fa-check-circle text-green-500 text-lg mb-1"></i>
                    <span class="text-xs text-gray-600 mb-1">服务状态</span>
                    <span class="text-sm font-medium">正常运行</span>
                  </div>
                </div>

                <div class="bg-yellow-50 border border-yellow-200 rounded-md p-3 mb-4">
                  <div class="flex items-start">
                    <i class="fas fa-info-circle text-yellow-500 mt-0.5 mr-2"></i>
                    <p class="text-xs text-yellow-800">已创建问题单 #PRB-2023061501，计划于今晚进行内存扩容</p>
                  </div>
                </div>

                <div class="flex justify-end gap-2">
                  <el-button size="small" class="text-sm border-gray-300 text-gray-600">查看详情</el-button>
                  <el-button type="primary" size="small" class="text-sm">生成报告</el-button>
                </div>
              </div>

              <!-- 结果3：有问题 -->
              <div class="inspection-card bg-white border border-gray-200 rounded-lg p-4 shadow-sm">
                <div class="flex justify-between items-start mb-4">
                  <h3 class="text-lg font-medium text-gray-800">网络设备安全巡检</h3>
                  <span class="status-tag status-problem px-3 py-1 text-xs">有问题</span>
                </div>
                <p class="text-sm text-gray-500 mb-3">2025-06-14 10:00-11:30 李华</p>

                <div class="grid grid-cols-2 gap-2 mb-4">
                  <div class="flex flex-col items-center">
                    <i class="fas fa-times-circle text-red-500 text-lg mb-1"></i>
                    <span class="text-xs text-gray-600 mb-1">防火墙规则</span>
                    <span class="text-sm font-medium">部分规则异常</span>
                  </div>
                  <div class="flex flex-col items-center">
                    <i class="fas fa-exclamation-circle text-yellow-500 text-lg mb-1"></i>
                    <span class="text-xs text-gray-600 mb-1">安全补丁</span>
                    <span class="text-sm font-medium">需更新</span>
                  </div>
                  <div class="flex flex-col items-center">
                    <i class="fas fa-check-circle text-green-500 text-lg mb-1"></i>
                    <span class="text-xs text-gray-600 mb-1">访问控制</span>
                    <span class="text-sm font-medium">正常</span>
                  </div>
                  <div class="flex flex-col items-center">
                    <i class="fas fa-check-circle text-green-500 text-lg mb-1"></i>
                    <span class="text-xs text-gray-600 mb-1">流量监控</span>
                    <span class="text-sm font-medium">正常</span>
                  </div>
                </div>

                <div class="flex justify-end gap-2">
                  <el-button size="small" class="text-sm border-gray-300 text-gray-600">查看详情</el-button>
                  <el-button type="primary" size="small" class="text-sm">生成报告</el-button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import router from '@/router';
import TitleComponent from '@/views/demo/components/TitleComponent.vue';

// 筛选条件
const filterStatus = ref('all');
const filterType = ref('all');
const dateRange = ref([]);

// 时间范围选择
const timeRange = ref('month'); // 默认选中"月"

// 时间范围切换函数
const handleTimeRangeChange = (range) => {
  timeRange.value = range;
  // 在实际应用中，这里应该根据选择的时间范围重新获取数据
  console.log(`切换到${range}视图`);
};

// 导航方法
const handleInspection1 = () => {
  router.push('/rili/rili');
};
const handleInspection2 = () => {
  router.push('/rili/InspectionManagement');
};
const handleInspectionManagement1 = () => {
  router.push('/rili/InspectionManagement');
};
const handleInspectionManagement2 = () => {
  router.push('/rili/xunjianrenwu');
};
const handleInspectionManagement3 = () => {
  router.push('/rili/xunjianjihua');
};
</script>

<style scoped>
/* 主容器样式 */
.operation-inspection {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
}

/* 导航栏样式 */
.navigation-tabs {
  display: flex;
  margin-bottom: 20px;
  background-color: #fff;
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  padding: 2px;
}

.nav-tab {
  padding: 12px 24px;
  cursor: pointer;
  transition: all 0.3s ease;
  border-radius: 4px;
  font-size: 14px;
  color: #606266;
  border-right: 1px solid #f0f0f0;
  flex: 1;
  text-align: center;
}

.nav-tab:last-child {
  border-right: none;
}

.nav-tab:hover {
  color: #409eff;
  background-color: #ecf5ff;
}

.nav-tab.active {
  background-color: #409eff;
  color: #fff;
  box-shadow: 0 2px 4px rgba(64, 158, 255, 0.3);
}

.nav-tab {
  cursor: pointer;
  user-select: none;
}

/* 选项卡样式 */
.tabs-wrapper {
  background-color: #fff;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 16px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* 筛选栏样式 */
.filter-bar {
  background-color: #fff;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 16px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.filter-item {
  flex-shrink: 0;
}

.filter-bar .el-select,
.filter-bar .el-date-picker {
  width: 150px;
  height: 36px;
}

.filter-actions {
  margin-left: auto;
  display: flex;
  gap: 10px;
}

.search-btn,
.export-btn,
.create-btn {
  height: 36px;
  border-radius: 4px;
}

/* 内容卡片样式 */
.content-card {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  overflow: hidden;
}

.card-header {
  padding: 20px;
  border-bottom: 1px solid #e4e7ed;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-title {
  font-size: 16px;
  font-weight: 500;
  color: #303133;
  margin: 0;
}

.card-body {
  padding: 0 20px;
}

/* 统计卡片样式 */
.stat-card {
  background-color: #f5f7fa;
  border-radius: 6px;
  padding: 16px;
}

.stat-label {
  font-size: 14px;
  color: #606266;
  margin: 0 0 8px 0;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
  color: #303133;
  margin: 0;
}

/* 分隔线 */
.divider {
  height: 1px;
  background-color: #e4e7ed;
  margin: 16px 0;
}

/* 图表标题 */
.chart-title {
  font-size: 14px;
  color: #606266;
  margin: 0 0 8px 0;
}

/* 区域标题 */
.section-title {
  font-size: 14px;
  font-weight: 500;
  color: #303133;
  margin: 0 0 12px 0;
}

/* 记录列表样式 */
.record-list {
  margin: 0;
  padding: 0;
}

.record-item {
  padding: 16px 0;
}

.record-title {
  font-size: 14px;
  font-weight: 500;
  color: #303133;
  margin: 0;
}

.record-time,
.record-type {
  font-size: 12px;
  color: #909399;
  margin: 4px 0 0 0;
}

/* 状态标签 */
.status-tag {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
}

.status-normal {
  background-color: #f0f9eb;
  color: #52c41a;
  border: 1px solid #e1f3d8;
}

.status-attention {
  background-color: #fffbe6;
  color: #faad14;
  border: 1px solid #fff1b8;
}

.status-problem {
  background-color: #fff2f0;
  color: #f5222d;
  border: 1px solid #ffe3e0;
}

/* 操作按钮 */
.action-btn {
  color: #409eff;
  font-size: 12px;
  padding: 4px 8px;
}

.action-btn:hover {
  color: #66b1ff;
  background-color: #ecf5ff;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-actions {
    margin-left: 0;
    justify-content: flex-end;
  }
}
</style>
