<script setup lang="ts">
/**
 * 排水户详情（二维码扫码入口）
 *
 * 通过扫码获取排水户 ID，展示详细信息及二维码。
 */
import { ref, computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'

const route = useRoute()
const router = useRouter()
const pshId = computed(() => route.params.id as string | undefined)

interface PshDetail {
  id: string
  name: string
  type: string
  address: string
  contact: string
  phone: string
  licenseNo: string
  drainType: string
  qrCodeUrl: string
}

const detail = ref<PshDetail>({
  id: pshId.value || 'PSH-001',
  name: '万达广场（城北店）',
  type: '商业',
  address: '城北区东风路 128 号',
  contact: '张经理',
  phone: '138****5678',
  licenseNo: '排许字第2024-0031号',
  drainType: '雨污分流',
  qrCodeUrl: '',
})
</script>

<template>
  <div class="page">
    <!-- NavBar -->
    <van-nav-bar
      title="排水户详情"
      left-arrow
      fixed
      placeholder
      @click-left="router.back()"
    />

    <!-- QR Code Card -->
    <div class="qr-card">
      <div class="qr-box">
        <van-image
          v-if="detail.qrCodeUrl"
          :src="detail.qrCodeUrl"
          width="160"
          height="160"
          fit="contain"
        />
        <template v-else>
          <van-icon name="qr" size="72" color="#1E74FF" />
          <p class="qr-hint">扫描二维码查看排水户信息</p>
        </template>
      </div>
      <span
        class="type-tag"
        :style="{ color: '#1E74FF', background: '#E3F2FD' }"
      >
        {{ detail.drainType }}
      </span>
    </div>

    <!-- Section: 基本信息 -->
    <div class="section">
      <div class="section-header">
        <span class="section-accent"></span>
        <span class="section-title">基本信息</span>
      </div>
      <div class="card">
        <div class="info-grid">
          <div class="info-item">
            <span class="info-label">排水户编号</span>
            <span class="info-value">{{ detail.id }}</span>
          </div>
          <div class="info-item full-width">
            <span class="info-label">排水户名称</span>
            <span class="info-value">{{ detail.name }}</span>
          </div>
          <div class="info-item">
            <span class="info-label">排水户类型</span>
            <span class="info-value">{{ detail.type }}</span>
          </div>
          <div class="info-item full-width">
            <span class="info-label">地址</span>
            <span class="info-value">{{ detail.address }}</span>
          </div>
          <div class="info-item">
            <span class="info-label">联系人</span>
            <span class="info-value">{{ detail.contact }}</span>
          </div>
          <div class="info-item">
            <span class="info-label">联系电话</span>
            <span class="info-value">{{ detail.phone }}</span>
          </div>
          <div class="info-item full-width">
            <span class="info-label">排水许可证</span>
            <span class="info-value">{{ detail.licenseNo }}</span>
          </div>
          <div class="info-item full-width">
            <span class="info-label">排水方式</span>
            <span class="info-value">{{ detail.drainType }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

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

// ── NavBar ──
:deep(.van-nav-bar) {
  background: #1E74FF;
  --van-nav-bar-title-text-color: #fff;
  --van-nav-bar-text-color: #fff;
  --van-nav-bar-icon-color: #fff;
}

// ── QR Card ──
.qr-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: 12px;
  padding: 24px 16px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);

  .qr-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 180px;
    height: 180px;
    border: 2px dashed #1E74FF;
    border-radius: 12px;
    background: #F7FAFF;
  }

  .qr-hint {
    margin: 10px 0 0 0;
    font-size: 12px;
    color: #969799;
  }

  .type-tag {
    padding: 4px 14px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
  }
}

// ── Section ──
.section {
  margin: 0 12px 10px;

  .section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 4px;
  }

  .section-accent {
    width: 3px;
    height: 16px;
    border-radius: 2px;
    background: #1E74FF;
  }

  .section-title {
    font-size: 14px;
    font-weight: 600;
    color: #323233;
  }
}

// ── Card ──
.card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  padding: 12px 16px;
}

// ── Info Grid ──
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.info-item {
  padding: 10px 0;
  border-bottom: 1px solid #F2F3F5;
  display: flex;
  flex-direction: column;
  gap: 4px;

  &:nth-child(odd) {
    padding-right: 12px;
  }

  &.full-width {
    grid-column: 1 / -1;
    padding-right: 0;
  }

  .info-label {
    font-size: 12px;
    color: #969799;
  }

  .info-value {
    font-size: 14px;
    color: #323233;
    word-break: break-all;
  }
}
</style>
