<template>
  <div class="task-schedule-container">

    <!-- 表格主体 -->
    <el-table :data="taskScheduleData" size="small" class="task-table" :header-cell-style="headerCellStyle"
      :cell-style="cellStyle" :row-class-name="tableRowClassName" highlight-current-row @row-click="handleRowClick"
      style="height: 420px;">
      <!-- 序号列 -->
      <el-table-column type="index" label="序号" width="60" align="center" />

      <!-- 任务调度时间 -->
      <el-table-column prop="scheduleTime" label="任务调度时间" width="120" align="center" />

      <!-- 任务调度目标 -->
      <el-table-column prop="target" label="任务调度目标" width="120" align="center" />

      <!-- 目标内容 -->
      <el-table-column prop="content" label="目标内容" min-width="220">
        <template #default="scope">
          <div class="content-cell">
            <el-tooltip effect="dark" :content="scope.row.content">
              <span>{{ scope.row.content }}</span>
            </el-tooltip>
          </div>
        </template>
      </el-table-column>

      <!-- 任务持续时间 -->
      <el-table-column prop="duration" label="任务持续时间" width="140" align="center">
        <template #default="scope">
          <div class="content-cell">
            <el-tooltip effect="dark" :content="scope.row.duration">
              <span>{{ scope.row.duration }}</span>
            </el-tooltip>
          </div>
        </template>
      </el-table-column>

      <!-- 损伤记录 -->
      <el-table-column prop="damageRecord" label="损伤记录" width="100" align="center">
        <template #default="scope">
          <span class="record-text">
            {{ scope.row.damageRecord || '-' }}
            <!-- <span v-if="scope.row.damageRecord && scope.row.damageRecord !== '-'">
              <el-icon class="warning-icon"><WarningFilled /></el-icon>
            </span> -->
          </span>
        </template>
      </el-table-column>

      <!-- 维修记录 -->
      <el-table-column prop="repairRecord" label="维修记录" width="100" align="center">
        <template #default="scope">
          <span class="record-text">
            {{ scope.row.repairRecord || '-' }}
            <!-- <span v-if="scope.row.repairRecord && scope.row.repairRecord !== '-'">
              <el-icon class="check-icon"><Check /></el-icon>
            </span> -->
          </span>
        </template>
      </el-table-column>

      <!-- 记录视频 -->
      <el-table-column label="记录视频" width="90" align="center">
        <template #default="scope">
          <el-button type="text" class="view-btn" @click="handleViewVideo(scope.row)" :icon="VideoPlay">
            查看
          </el-button>
        </template>
      </el-table-column>

      <!-- 操作列 -->
      <el-table-column label="操作" width="140" align="center">
        <template #default="scope">
          <el-button type="text" class="export-btn" @click="handleExportFile(scope.row)" :icon="Download">
            导出文件
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <div>
      <el-dialog class="dialogbig" v-model="img_video_dialogVisible" style="background-color: rgba(0, 0, 0, 0) ;">
        <div class="media-container">
          <!-- 图片展示行 -->
          <div class="image-row">
            <h3>图片</h3>
            <div class="image-list" v-if="images.length">
              <div v-for="item in images" class="image-item">
                <img src="../../static/image/loginback.png" :alt="item.name" />

                {{ typeof item.url }}--{{ item }}

              </div>
            </div>
            <div v-else> 暂无图片数据</div>
          </div>

          <!-- 视频展示行 -->
          <div class="video-row" v-if="videos">
            <h3>视频</h3>
            <div class="video-list" v-if="videos.length">
              <div v-for="(video, index) in videos" :key="index" class="video-item">
                <video :src="video.url" controls :poster="video.poster">
                  您的浏览器不支持视频播放
                </video>
              </div>
            </div>
            <div v-else> 暂无视频数据</div>
          </div>
        </div>
      </el-dialog>
    </div>


  </div>
</template>

<script setup>
import { ref } from 'vue'
import { Search, VideoPlay, Download, WarningFilled, Check } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
// import { ElMessageBox } from 'element-plus/lib/components/index.js'


// 表格数据
const taskScheduleData = ref([
  {
    scheduleTime: '2025-4-1',
    target: '1号楼405',
    content: '位于405室靠走廊部分，当前火势较大，可能在段时间能向走廊蔓延',
    duration: '一个小时四十五分钟',
    damageRecord: '-',
    repairRecord: '-',
  },
  {
    scheduleTime: '2025-4-4',
    target: '5号楼405',
    content: '位于405室靠走廊部分，当前火势较大，可能在段时间能向走廊蔓延,位于405室靠走廊部分，当前火势较大，可能在段时间能向走廊蔓延,位于405室靠走廊部分，当前火势较大，可能在段时间能向走廊蔓延',
    duration: '两个小时,两个小时,两个小时',
    damageRecord: '-',
    repairRecord: '-',
  },
  {
    scheduleTime: '-',
    target: '-',
    content: '-',
    duration: '-',
    damageRecord: '2025-5-1',
    repairRecord: '-',
  },
  {
    scheduleTime: '-',
    target: '-',
    content: '-',
    duration: '-',
    damageRecord: '-',
    repairRecord: '2025-5-1',
  }
  ,
  {
    scheduleTime: '2025-4-4',
    target: '5号楼405',
    content: '位于405室靠走廊部分，当前火势较大，可能在段时间能向走廊蔓延',
    duration: '两个小时',
    damageRecord: '-',
    repairRecord: '-',
  },
  {
    scheduleTime: '-',
    target: '-',
    content: '-',
    duration: '-',
    damageRecord: '2025-5-1',
    repairRecord: '-',
  },
  {
    scheduleTime: '-',
    target: '-',
    content: '-',
    duration: '-',
    damageRecord: '-',
    repairRecord: '2025-5-1',
  },
  {
    scheduleTime: '2025-4-4',
    target: '5号楼405',
    content: '位于405室靠走廊部分，当前火势较大，可能在段时间能向走廊蔓延',
    duration: '两个小时',
    damageRecord: '-',
    repairRecord: '-',
  },
  {
    scheduleTime: '-',
    target: '-',
    content: '-',
    duration: '-',
    damageRecord: '2025-5-1',
    repairRecord: '-',
  },
  {
    scheduleTime: '-',
    target: '-',
    content: '-',
    duration: '-',
    damageRecord: '-',
    repairRecord: '2025-5-1',
  }
])
const images = ref([])
const videos = ref([])

// 声明一个响应式变量searchText，用于存储搜索框中的内容
const searchText = ref('')

// 声明一个响应式变量img_video_dialogVisible，用于控制图片视频对话框的显示与隐藏
const img_video_dialogVisible = ref(false)
// 表头样式
const headerCellStyle = {

  'font-weight': '600',
  'text-align': 'center',
  'color': '#1d2129',

  'padding': '10px 0'
}

// 单元格样式
const cellStyle = {

  'padding': '12px 0',
  'transition': 'all 0.2s ease'
}

// 行样式
const tableRowClassName = ({ row, rowIndex }) => {
  return rowIndex % 2 === 0 ? 'row-even' : 'row-odd'
}

// 行点击事件
const handleRowClick = (row) => {
  console.log('点击行数据:', row)
}

// 查看视频按钮事件
const handleViewVideo = (rowFnfo) => {
  // 查看视频逻辑
  console.log('补充查看视频逻辑', rowFnfo)
  img_video_dialogVisible.value = true

}

// 导出文件按钮事件
const handleExportFile = (rowFnfo) => {
  // 导出文件逻辑
  console.log('补充导出文件逻辑', rowFnfo)
  ElMessage({
    type: 'info',
    message: `正在请求${rowFnfo.target}文件: `,
  })
}
</script>

<style scoped lang="scss">
.task-schedule-container {
  background: rgba(16, 42, 77, 0.7);
  /* 修改容器背景色 */
  border-radius: 8px;
  // box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3); /* 加深阴影增强对比 */
  display: flex;
  flex-direction: column;
  height: 100%;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  padding: 2px;
  /* 添加内边距 */
}

/* 修改表头样式 */
:deep(.el-table__header) {
  th {

    background-color: rgb(11, 31, 58) !important;
    /* 加深表头背景 */
    color: #ffffff !important;
    /* 浅色文字 */

    // border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
  }
}

/* 修改表格整体样式 */
.task-table {
  width: 100%;
  height: calc(100vh - 180px);
  max-height: 600px;
  overflow: auto;
  // background-color: transparent !important; /* 透明背景 */
  color: #ffffff;
  /* 浅色文字 */

  /* 修改单元格样式 */
  :deep(.el-table__body) {
    tr {
      td {
        background-color: rgba(16, 42, 77);
        ;
        // border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        color: #ffffff;
        // padding: 10px 0;
      }
    }
  }

  /* 修改斑马纹样式 */
  .row-even {
    background-color: rgba(146, 231, 9, 1.5) !important;
  }

  .row-odd {
    background-color: rgba(185, 143, 28, 0.3) !important;
  }

  /* 修改悬停效果 */
  :deep(.el-table__row:hover td) {
    background-color: rgba(22, 36, 58, 0.7) !important;
  }

  /* 修改按钮样式 */
  .view-btn {
    color: #69c0ff !important;

    &:hover {
      color: #40a9ff !important;
    }
  }

  .export-btn {
    color: #ffc069 !important;

    &:hover {
      color: #ffa940 !important;
    }
  }

  /* 修改文字颜色 */
  .content-cell,
  .record-text {
    color: #ffffff !important;
    max-height: 30px;

    white-space: nowrap;
    /* 禁止文本换行 */
    overflow: hidden;
    /* 隐藏溢出的内容 */
    text-overflow: ellipsis;
    /* 使用省略号表示被截断的文本 */
    max-width: 100%;
    /* 设置最大宽度，可以根据需要调整 */

  }
}

/* 修改分页样式 */
.table-pagination {
  margin-top: auto;
  // padding: 16px 0;

  :deep(.el-pagination) {
    color: #ffffff;

    .btn-prev,
    .btn-next,
    .el-pager li {
      // background-color: transparent;
      color: #ffffff;
    }

    .el-pager li.active {
      color: #69c0ff;
    }

    .el-pagination__total,
    .el-pagination__jump {
      color: #e6f7ff;
    }


  }
}


.horizontal-container {
  margin: 20px 0 10px 0;
  display: flex;
  align-items: center;
  /* 垂直居中对齐 */
}

.media-container {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  background: rgb(4, 33, 54);
  border-radius: 10px;
}

/* 图片行样式 */
.image-row {
  margin-bottom: 40px;
}

.image-list {
  display: flex;
  gap: 15px;
  overflow-x: auto;
  padding: 10px 0;
}

.image-item {
  position: relative;
  flex-shrink: 0;
  width: 200px;
  height: 150px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  cursor: pointer;
}

.image-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.image-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.image-item:hover .image-overlay {
  opacity: 1;
}

/* 视频行样式 */
.video-row {
  margin-bottom: 20px;
}

.video-list {
  display: flex;
  gap: 15px;
  overflow-x: auto;
  padding: 10px 0;
}

.video-item {
  flex-shrink: 0;
  width: 300px;
  border-radius: 8px;
  overflow: hidden;
  /* box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); */
  /* background: white; */
}

.video-item video {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.video-info {
  padding: 10px;
  background: white;
  text-align: center;
  font-weight: 500;
  color: #333;
}

/* 图片模态框 */
.image-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
}

.modal-content img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}

.close-btn {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: white;
  border: none;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 标题样式 */
h3 {
  color: #fcfcfc;
  margin-bottom: 15px;
  font-size: 20px;
  font-weight: 600;
  padding-left: 10px;
  border-left: 4px solid #007bff;
}

/* 滚动条美化 */
// .image-list::-webkit-scrollbar,
// .video-list::-webkit-scrollbar {
//   height: 8px;
// }

// .image-list::-webkit-scrollbar-track,
// .video-list::-webkit-scrollbar-track {
//   background: #f1f1f1;
//   border-radius: 4px;
// }

// .image-list::-webkit-scrollbar-thumb,
// .video-list::-webkit-scrollbar-thumb {
//   background: #154e8a;
//   border-radius: 4px;
// }

// .image-list::-webkit-scrollbar-thumb:hover,
// .video-list::-webkit-scrollbar-thumb:hover {
//   background: #3b5775;
// }

/* 响应式设计 */
@media (max-width: 768px) {
  .media-container {
    padding: 15px;
  }

  .image-item {
    width: 150px;
    height: 120px;
  }

  .video-item {
    width: 250px;
  }

  .video-item video {
    height: 150px;
  }
}

/* 定制整个滚动条 */
::-webkit-scrollbar {
  width: 10px;
  /* 滚动条宽度 */
}

/* 定制滚动条轨道 */
::-webkit-scrollbar-track {
  background: #023375;
  border-radius: 10px;

  /* 轨道颜色 */
}

/* 定制滚动条的滑块（thumb） */
::-webkit-scrollbar-thumb {
  background: #0d68c1;
  border-radius: 10px;

  /* 滑块颜色 */
}

/* 当鼠标悬停在滑块上 */
::-webkit-scrollbar-thumb:hover {
  background: #DDDEE0;
  /* 滑块悬停颜色 */
}
</style>