<template>
  <div>
    <div class="inspection-tasks">
      <!-- 导航栏 -->
      <div class="navigation-tabs">
        <div class="nav-tab" @click="handleInspection1">待办事项</div>
        <div class="nav-tab" @click="handleInspection2">巡检管理</div>
        <div class="nav-tab" @click="handleInspection3">试验管理</div>
        <div class="nav-tab" @click="handleInspection4">报修管理</div>
        <div class="nav-tab active" @click="handleInspection5">抢修管理</div>
        <div class="nav-tab" @click="handleInspection6">工单管理</div>
        <div class="nav-tab" @click="handleInspection7">运维组织</div>
      </div>

      <!-- 页面标题和操作区 -->
      <div class="header-section">
        <TitleComponent title="抢修管理模块" subtitle="处理紧急抢修任务，跟踪抢修进度和记录"></TitleComponent>
        <div class="header-actions">
          <el-button class="filter-btn" @click="showFilter = !showFilter">
            筛选
            <i class="el-icon-arrow-down ml-1"></i>
          </el-button>
          <el-button type="primary" class="export-btn" @click="handleExport"> 导出数据 </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>
        </div>
      </div>

      <!-- 筛选栏 (默认隐藏) -->
      <div class="filter-bar" v-if="showFilter">
        <div class="filter-container">
          <div class="filter-item">
            <el-select v-model="taskStatus" placeholder="任务状态">
              <el-option label="待执行" value="pending"></el-option>
              <el-option label="处理中" value="processing"></el-option>
              <el-option label="已完成" value="completed"></el-option>
            </el-select>
          </div>
          <div class="filter-item">
            <el-select v-model="priority" placeholder="紧急程度">
              <el-option label="紧急" value="urgent"></el-option>
              <el-option label="常规" value="normal"></el-option>
            </el-select>
          </div>
          <div class="filter-item">
            <el-select v-model="executor" placeholder="抢修人员">
              <el-option label="全部人员" value="all"></el-option>
              <el-option label="李明" value="liming"></el-option>
              <el-option label="王伟" value="wangwei"></el-option>
            </el-select>
          </div>
          <div class="filter-item">
            <el-date-picker
              v-model="dateRange"
              type="datetimerange"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              format="YYYY-MM-DD HH:mm"
              value-format="YYYY-MM-DD HH:mm"
            />
          </div>
          <div class="filter-actions">
            <el-button type="primary" class="search-btn" @click="handleSearch"> 搜索 </el-button>
          </div>
        </div>
      </div>

      <!-- 统计卡片区域 -->
      <div class="statistics-container">
        <div class="stat-card">
          <div class="stat-info">
            <p class="stat-label">本月抢修总数</p>
            <p class="stat-value">18</p>
            <p class="stat-trend up">较上月 +8.7%</p>
          </div>
          <div class="stat-icon">
            <img src="@/assets/images/qiangxiu.png" alt="本月抢修总数" class="stat-image" />
          </div>
        </div>

        <div class="stat-card">
          <div class="stat-info">
            <p class="stat-label">平均抢修时长</p>
            <p class="stat-value">58分钟</p>
            <p class="stat-trend down">较上月 -2.5分钟</p>
          </div>
          <div class="stat-icon">
            <img src="@/assets/images/qiangxiushijian.png" alt="平均抢修时长" class="stat-image" />
          </div>
        </div>

        <div class="stat-card">
          <div class="stat-info">
            <p class="stat-label">待处理抢修</p>
            <p class="stat-value">3</p>
            <p class="stat-trend warning">需要尽快处理</p>
          </div>
          <div class="stat-icon warning">
            <img src="@/assets/images/weiqiangxiu.png" alt="待处理抢修" class="stat-image" />
          </div>
        </div>

        <div class="stat-card">
          <div class="stat-info">
            <p class="stat-label">按时完成率</p>
            <p class="stat-value">92%</p>
            <p class="stat-trend up">较上月 +2.4%</p>
          </div>
          <div class="stat-icon success">
            <img src="@/assets/images/qiangxiuwancheng.png" alt="按时完成率" class="stat-image" />
          </div>
        </div>
      </div>

      <!-- 抢修记录表格 -->
      <div class="table-container">
        <el-table :data="repairRecords" border style="width: 100%" class="record-table">
          <el-table-column align="center" prop="reportNo" label="抢修单号" min-width="120"></el-table-column>
          <el-table-column align="center" prop="content" label="抢修内容" min-width="200"></el-table-column>
          <el-table-column align="center" prop="reporter" label="报修人" min-width="80"></el-table-column>
          <el-table-column align="center" prop="reportTime" label="报修时间" min-width="140"></el-table-column>
          <el-table-column align="center" prop="handler" label="抢修人员" min-width="80"></el-table-column>
          <el-table-column align="center" prop="priority" label="紧急程度" min-width="80">
            <template #default="scope">
              <span :class="`priority-tag ${scope.row.priorityClass}`">{{ scope.row.priority }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="status" label="处理状态" min-width="80">
            <template #default="scope">
              <span :class="`status-tag ${scope.row.statusClass}`">{{ scope.row.status }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="duration" label="处理时长" min-width="80"></el-table-column>
          <el-table-column align="center" label="操作" min-width="120">
            <template #default="scope">
              <el-button type="text" class="detail-btn" @click="handleDetail(scope.row)"> 详情 </el-button>
              <el-button type="text" :class="scope.row.actionClass" @click="handleAction(scope.row)">
                {{ scope.row.actionText }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!-- 分页区域 -->
      <div class="pagination-section">
        <div class="pagination-controls">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="pageSize"
            layout="prev, pager, next, jumper"
            :total="total"
            background
          >
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue';
import router from '@/router';
import TitleComponent from './TitleComponent.vue';

// 筛选条件
const taskStatus = ref('');
const priority = ref('');
const executor = ref('');
const dateRange = ref([]);
const showFilter = ref(false);

// 分页相关
const currentPage = ref(3);
const pageSize = ref(10);
const total = ref(187);

// 抢修记录数据
const repairRecords = ref([
  {
    reportNo: 'R-2025-0620-001',
    content: '网络主干交换机故障AAAAAA',
    reporter: '陈明',
    reportTime: '2025-06-20 08:30',
    handler: '李明',
    priority: '紧急',
    priorityClass: 'urgent',
    status: '已完成',
    statusClass: 'completed',
    duration: '10分钟',
    actionText: '详情',
    actionClass: 'detail-btn'
  },
  {
    reportNo: 'R-2025-0620-002',
    content: '实验室水管爆裂',
    reporter: '陈明',
    reportTime: '2025-06-20 08:30',
    handler: '李明',
    priority: '紧急',
    priorityClass: 'urgent',
    status: '抢修中',
    statusClass: 'processing',
    duration: '4分钟',
    actionText: '查看',
    actionClass: 'follow-btn'
  },
  {
    reportNo: 'R-2025-0620-003',
    content: '主配电室线路故障',
    reporter: '陈明',
    reportTime: '2025-06-20 08:30',
    handler: '李明',
    priority: '紧急',
    priorityClass: 'urgent',
    status: '已完成',
    statusClass: 'completed',
    duration: '10分钟',
    actionText: '详情',
    actionClass: 'detail-btn'
  },
  {
    reportNo: 'R-2025-0620-004',
    content: '网络主干交换机故障AAAAAA',
    reporter: '陈明',
    reportTime: '2025-06-20 08:30',
    handler: '李明',
    priority: '常规',
    priorityClass: 'normal',
    status: '已完成',
    statusClass: 'completed',
    duration: '10分钟',
    actionText: '详情',
    actionClass: 'detail-btn'
  },
  {
    reportNo: 'R-2025-0620-005',
    content: '网络主干交换机故障AAAAAA',
    reporter: '陈明',
    reportTime: '2025-06-20 08:30',
    handler: '李明',
    priority: '紧急',
    priorityClass: 'urgent',
    status: '已完成',
    statusClass: 'completed',
    duration: '10分钟',
    actionText: '详情',
    actionClass: 'detail-btn'
  },
  {
    reportNo: 'R-2025-0620-006',
    content: '网络主干交换机故障AAAAAA',
    reporter: '陈明',
    reportTime: '2025-06-20 08:30',
    handler: '李明',
    priority: '紧急',
    priorityClass: 'urgent',
    status: '已完成',
    statusClass: 'completed',
    duration: '10分钟',
    actionText: '详情',
    actionClass: 'detail-btn'
  },
  {
    reportNo: 'R-2025-0620-007',
    content: '网络主干交换机故障AAAAAA',
    reporter: '陈明',
    reportTime: '2025-06-20 08:30',
    handler: '李明',
    priority: '紧急',
    priorityClass: 'urgent',
    status: '已完成',
    statusClass: 'completed',
    duration: '10分钟',
    actionText: '详情',
    actionClass: 'detail-btn'
  }
]);

// 搜索处理
const handleSearch = () => {
  currentPage.value = 1; // 重置到第一页
  // 实际应用中这里会根据筛选条件过滤数据
};

// 导出数据
const handleExport = () => {
  console.log('导出抢修记录数据');
  // 实际应用中添加导出逻辑
};

// 分页事件
const handleSizeChange = (val) => {
  pageSize.value = val;
  currentPage.value = 1;
};

const handleCurrentChange = (val) => {
  currentPage.value = val;
};

// 查看详情
const handleDetail = (record) => {
  console.log('查看详情:', record);
};

// 处理操作
const handleAction = (record) => {
  console.log('执行操作:', record.actionText, record);
};

// 选项卡切换
const handleTaskTab = () => {
  // 抢修任务选项卡逻辑
};

const handleRecordTab = () => {
  router.push('/rili/qiangxiujiilu');
};

// 导航事件
const handleInspection1 = () => {
  router.push('/rili/rili');
};

const handleInspection2 = () => {
  router.push('/rili/InspectionManagement');
};

const handleInspection3 = () => {
  router.push('/rili/shiyanguanli');
};

const handleInspection4 = () => {
  router.push('/rili/baoxiuguanli');
};

const handleInspection5 = () => {
  router.push('/rili/qiangxiuguanli');
};

const handleInspection6 = () => {
  router.push('/rili/gongdanliebiao');
};
const handleInspection7 = () => {
  router.push('/rili/renyuanzhuangtai');
};

const handleInspectionManagement1 = () => {
  router.push('/rili/qiangxiuguanli');
};

const handleInspectionManagement2 = () => {
  router.push('/rili/qiangxiujilu');
};
</script>

<style scoped>
.inspection-tasks {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
}

/* 头部标题和操作区 */
.header-section {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.filter-btn {
  background-color: #fff;
  color: #303133;
  border-color: #dcdfe6;
}

.export-btn {
  background-color: #165dff;
  border-color: #165dff;
}

/* 选项卡样式 */
.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;
  border-radius: 8px;
  margin-bottom: 24px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
  padding: 16px 24px;
  transition: all 0.3s ease;
}

.filter-container {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  width: 100%;
}

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

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

.filter-bar .el-select .el-input__inner,
.filter-bar .el-date-picker .el-input__inner {
  border-radius: 4px;
  border-color: #dcdfe6;
  transition: all 0.2s ease;
}

.filter-bar .el-select .el-input__inner:focus,
.filter-bar .el-date-picker .el-input__inner:focus {
  border-color: #165dff;
  box-shadow: 0 0 0 2px rgba(22, 93, 255, 0.1);
}

.filter-actions {
  margin-left: auto;
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

.search-btn {
  background-color: #f2f3f5;
  color: #303133;
  border-color: #f2f3f5;
  transition: all 0.2s ease;
}

.search-btn:hover {
  background-color: #e5e6eb;
  color: #303133;
  border-color: #e5e6eb;
}

/* 统计卡片样式 */
.statistics-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: transform 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-3px);
}

.stat-info {
  flex: 1;
}

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

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

.stat-trend {
  font-size: 12px;
  margin: 0;
  display: flex;
  align-items: center;
}

.stat-trend.up {
  color: #00b42a;
}

.stat-trend.up::before {
  content: '↑';
  margin-right: 4px;
}

.stat-trend.down {
  color: #ff4d4f;
}

.stat-trend.down::before {
  content: '↓';
  margin-right: 4px;
}

.stat-trend.warning {
  color: #fa8c16;
}

.stat-icon {
  width: 55px;
  height: 55px;
  border-radius: 50%;
  background-color: #ffebe6;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-image {
  width: 45px;
  height: 45px;
  object-fit: contain;
}
.table-container {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
  padding: 16px;
  margin-bottom: 24px;
}

.record-table {
  border-collapse: separate;
  border-spacing: 0;
}

.record-table th {
  background-color: #f7f8fa;
  color: #4e5969;
  font-weight: 500;
  font-size: 14px;
}

.record-table td {
  color: #1d2129;
  font-size: 14px;
}

.status-tag {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
}

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

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

.priority-tag {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.priority-tag.urgent {
  background-color: #ffebe6;
  color: #ff4d4f;
  border: 1px solid #ffccc7;
}

.priority-tag.normal {
  background-color: #e6f7ff;
  color: #1890ff;
  border: 1px solid #b3d8ff;
}

.detail-btn {
  color: #165dff;
}

.follow-btn {
  color: #fa8c16;
}

/* 分页区域样式 */
.pagination-section {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

.pagination-controls .el-pagination {
  margin: 0;
}

.pagination-controls .el-pagination button,
.pagination-controls .el-pagination .el-pager li {
  min-width: 36px;
  height: 36px;
  line-height: 36px;
  border-radius: 4px;
}

.pagination-controls .el-pagination .el-pager li.active {
  background-color: #165dff;
  color: #fff;
}

/* 导航栏样式 */
.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;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .statistics-container {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .inspection-tasks {
    padding: 16px;
  }

  .header-section {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .filter-container {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-actions {
    margin-left: 0;
    justify-content: flex-end;
  }

  .filter-bar .el-select,
  .filter-bar .el-date-picker {
    width: 100%;
  }

  .statistics-container {
    grid-template-columns: 1fr;
  }

  .table-container {
    overflow-x: auto;
  }
}
</style>
