<template>
  <div class="detail-page">
    <!-- 顶部导航栏 -->
    <div class="nav-bar">
      <van-icon name="arrow-left" class="nav-back" @click="goBack" />
      <div class="nav-title">重点检测详情</div>
      <div class="nav-placeholder"></div>
    </div>

    <!-- 检测信息卡片 -->
    <div class="detail-card">
      <div class="card-header">
        <div class="detail-type" :class="detail.typeClass">
          {{ detail.typeText }}
        </div>
        <div class="detail-status" :class="detail.statusClass">
          {{ detail.statusText }}
        </div>
      </div>

      <div class="card-body">
        <div class="info-row">
          <span class="label">检测对象：</span>
          <span class="value">{{ detail.objectInfo }}</span>
        </div>
        <div class="info-row">
          <span class="label">发布时间：</span>
          <span class="value">{{ detail.issueTime }}</span>
        </div>
        <div class="info-row">
          <span class="label">发布人：</span>
          <span class="value">{{ detail.issuer }}</span>
        </div>
        <div class="info-row">
          <span class="label">联系方式：</span>
          <span class="value link">{{ detail.contact }}</span>
        </div>
      </div>

      <div class="card-desc">
        <div class="desc-title">详细描述</div>
        <div class="desc-content">{{ detail.description }}</div>
      </div>
    </div>

    <!-- 处理记录 -->
    <div class="record-card" v-if="detail.records && detail.records.length > 0">
      <div class="card-title">处理记录</div>
      <div class="record-list">
        <div v-for="(record, index) in detail.records" :key="index" class="record-item">
          <div class="record-dot"></div>
          <div class="record-content">
            <div class="record-time">{{ record.time }}</div>
            <div class="record-text">{{ record.content }}</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 底部操作按钮 -->
    <div class="action-bar">
      <van-button block round type="primary" class="action-btn" @click="handleReport">
        上报处理结果
      </van-button>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { useRouter, useRoute } from "vue-router";
import { Toast } from "vant";

const router = useRouter();
const route = useRoute();

// 检测详情数据
const detail = ref({
  id: "",
  type: "vehicle",
  typeText: "重点车辆监控",
  typeClass: "type-vehicle",
  status: "unread",
  statusText: "未读",
  statusClass: "status-unread",
  objectInfo: "鄂A88888号车辆为重点监控对象",
  issueTime: "2026/03/27 10:30",
  issuer: "指挥中心",
  contact: "027-88888888",
  description: "该车辆为重点监控对象，发现请立即上报处理。近期有多次违章记录，需重点关注。",
  records: []
});

// 返回
function goBack() {
  router.back();
}

// 上报处理结果
function handleReport() {
  router.push("/dataReport");
}

onMounted(() => {
  const detection = route.query;
  if (detection.id) {
    detail.value.id = detection.id;
  }
});
</script>

<style lang="scss" scoped>
.detail-page {
  min-height: 100vh;
  background: #f5f5f5;
  padding-bottom: 100px;
}

.nav-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
  border-bottom: 1px solid #e5e5e5;
  padding: 12px 16px;

  .nav-back {
    font-size: 20px;
    color: #333;
  }

  .nav-title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
  }

  .nav-placeholder {
    width: 20px;
  }
}

.detail-card,
.record-card {
  background: white;
  margin: 16px;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

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

.detail-type {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;

  &.type-vehicle {
    background: #fef3c7;
    color: #d97706;
  }

  &.type-person {
    background: #e0e7ff;
    color: #4f46e5;
  }
}

.detail-status {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  border: 1px solid;

  &.status-unread {
    background: #fee2e2;
    color: #dc2626;
    border-color: #fecaca;
  }

  &.status-read {
    background: #f0fdf4;
    color: #16a34a;
    border-color: #bbf7d0;
  }
}

.card-body {
  .info-row {
    display: flex;
    margin-bottom: 10px;
    font-size: 14px;

    &:last-child {
      margin-bottom: 0;
    }

    .label {
      color: #999;
      width: 80px;
      flex-shrink: 0;
    }

    .value {
      color: #333;
      flex: 1;

      &.link {
        color: #2563eb;
      }
    }
  }
}

.card-desc {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #f0f0f0;

  .desc-title {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
  }

  .desc-content {
    font-size: 14px;
    color: #666;
    line-height: 1.6;
  }
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: #333;
  margin-bottom: 16px;
}

.record-list {
  position: relative;
  padding-left: 20px;

  &::before {
    content: "";
    position: absolute;
    left: 5px;
    top: 8px;
    bottom: 8px;
    width: 2px;
    background: #e5e5e5;
  }

  .record-item {
    position: relative;
    padding-bottom: 16px;

    &:last-child {
      padding-bottom: 0;
    }

    .record-dot {
      position: absolute;
      left: -17px;
      top: 4px;
      width: 10px;
      height: 10px;
      background: #2563eb;
      border-radius: 50%;
    }

    .record-content {
      .record-time {
        font-size: 12px;
        color: #999;
        margin-bottom: 4px;
      }

      .record-text {
        font-size: 14px;
        color: #333;
      }
    }
  }
}

.action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid #e5e5e5;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.action-btn {
  height: 44px;
  font-size: 16px;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  border: none;
}
</style>
