<template>
  <base-dialog
    v-model:visible="props.visible"
    title="涉灾隐患点情况"
    :table-data="tableData"
    :table-columns="tableColumns"
    :table-height="450"
    :total="total"
    :current-page="currentPage"
    :page-size="pageSize"
    :z-index="2000"
    :max-width="900"
    :show-filter="false"
    :table-show="false"
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
    @close="handleClose"
  >
    <!-- 自定义内容区域 -->
    <template #header>
      <div class="hazard-info-panel">
        <!-- 基本信息 -->
        <div class="info-section">
          <div class="info-row">
            <div class="info-item">
              <span class="info-label">区县名称</span>
              <span class="info-value">{{ hazardData.district }}</span>
            </div>
            <div class="info-item">
              <span class="info-label">风险等级</span>
              <span class="info-value">{{ hazardData.riskLevel }}</span>
            </div>
          </div>
          <div class="info-row">
            <div class="info-item">
              <span class="info-label">公路编号</span>
              <span class="info-value">{{ hazardData.roadCode }}</span>
            </div>
            <div class="info-item">
              <span class="info-label">位置</span>
              <span class="info-value">{{ hazardData.location }}</span>
            </div>
          </div>
        </div>

        <!-- 风险描述 -->
        <div class="info-block">
          <div class="block-title">风险描述</div>
          <div class="block-content">{{ hazardData.riskDescription }}</div>
        </div>

        <!-- 采取措施 -->
        <div class="info-block">
          <div class="block-title">采取措施</div>
          <div class="block-content">{{ hazardData.measures }}</div>
        </div>

        <!-- 三级包保责任人 -->
        <div class="info-block">
          <div class="block-title">三级包保责任人</div>
          <div class="responsibility-list">
            <div class="responsibility-item">
              <span class="responsibility-label">交通主管部门责任人：</span>
              <span class="responsibility-name">{{ hazardData.trafficDept.name }}</span>
              <span class="responsibility-phone">{{ hazardData.trafficDept.phone }}</span>
              <span class="responsibility-frequency">{{ hazardData.trafficDept.frequency }}</span>
            </div>
            <div class="responsibility-item">
              <span class="responsibility-label">公路机构责任人：</span>
              <span class="responsibility-name">{{ hazardData.roadOrg.name }}</span>
              <span class="responsibility-phone">{{ hazardData.roadOrg.phone }}</span>
              <span class="responsibility-frequency">{{ hazardData.roadOrg.frequency }}</span>
            </div>
            <div class="responsibility-item">
              <span class="responsibility-label">养护站责任人：</span>
              <span class="responsibility-name">{{ hazardData.maintenance.name }}</span>
              <span class="responsibility-phone">{{ hazardData.maintenance.phone }}</span>
              <span class="responsibility-frequency">{{ hazardData.maintenance.frequency }}</span>
            </div>
          </div>
        </div>

        <!-- 护路员 -->
        <div class="info-row simple-row">
          <span class="row-label">护路员</span>
          <span class="row-value name">{{ hazardData.roadKeeper.name }}</span>
          <span class="row-value phone">{{ hazardData.roadKeeper.phone }}</span>
          <span class="row-value frequency">{{ hazardData.roadKeeper.frequency }}</span>
        </div>

        <!-- 预警预报关 -->
        <div class="info-row simple-row">
          <span class="row-label">预警预报关</span>
          <span class="row-value">{{ hazardData.earlyWarning }}</span>
        </div>

        <!-- 线下巡查关 -->
        <div class="info-row simple-row">
          <span class="row-label">线下巡查关</span>
          <span class="row-value">{{ hazardData.offlinePatrol }}</span>
        </div>

        <!-- 交通管控关 -->
        <div class="info-row simple-row">
          <span class="row-label">交通管控关</span>
          <span class="row-value">{{ hazardData.trafficControl }}</span>
        </div>

        <!-- 力量预置关 -->
        <div class="info-row simple-row">
          <span class="row-label">力量预置关</span>
          <span class="row-value">{{ hazardData.forcePreposition }}</span>
          <el-icon class="location-icon"><Location /></el-icon>
        </div>

        <!-- 告警阻拦关 -->
        <div class="info-row simple-row">
          <span class="row-label">告警阻拦关</span>
          <span class="row-value">{{ hazardData.alarmBlocking }}</span>
        </div>
      </div>
    </template>
  </base-dialog>
</template>

<script setup>
import { ref, watch } from 'vue';
import { Location } from '@element-plus/icons-vue';
import baseDialog from '../component/baseDialog.vue';

const props = defineProps({
  visible: {
    type: Boolean,
    default: false,
  },
  data: {
    type: Object,
    default: () => ({}),
  },
});

const emit = defineEmits(['update:visible', 'close']);

// 表格列配置（为空，因为使用自定义内容）
const tableColumns = ref([]);
const tableData = ref([]);
const total = ref(0);
const currentPage = ref(1);
const pageSize = ref(10);

// 隐患点数据
const hazardData = ref({
  district: '南川区',
  riskLevel: '较大隐患',
  roadCode: 'S523',
  location: '开县-凭祥(K292+301至K292+386)',
  riskDescription:
    '崩塌形成于路线右侧上边坡陡峭位置，影响长度85m，掉块、滑塌可能性极大。【类型：路内风险点-边坡】',
  measures: '已纳入灾害防治工程计划，拟采用坡面整理及挂网喷射植被混凝土整治。',
  trafficDept: {
    name: '何思毅',
    phone: '13896702005',
    frequency: '半年巡查一次',
  },
  roadOrg: {
    name: '杨洪',
    phone: '15025697135',
    frequency: '每月巡查一次',
  },
  maintenance: {
    name: '陈李彪',
    phone: '13896713399',
    frequency: '每周巡查一次',
  },
  roadKeeper: {
    name: '陈李彪',
    phone: '13896713399',
    frequency: '一周巡查两次',
  },
  earlyWarning: '当前无预警',
  offlinePatrol: '常态化巡查',
  trafficControl: '观察通行 半幅通行 禁止通行 无',
  forcePreposition: '安宁养护站',
  alarmBlocking: '设置警示标识 向社会发布信息 采取硬隔离措施 无',
});

// 关闭弹窗
const handleClose = () => {
  emit('update:visible', false);
  emit('close');
};

// 分页操作
const handleSizeChange = val => {
  pageSize.value = val;
};

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

// 监听visible变化
watch(
  () => props.visible,
  newVal => {
    if (newVal && props.data) {
      // 如果有传入数据，更新显示
      Object.assign(hazardData.value, props.data);
    }
  }
);
</script>

<style lang="scss" scoped>
.hazard-info-panel {
  height: 500px;
  color: rgba(255, 255, 255, 0.9);
  overflow-y: auto;
  // 自定义滚动条样式
  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-track {
    background: rgba(20, 46, 73, 0.3);
    border-radius: 3px;
  }

  &::-webkit-scrollbar-thumb {
    background: #142e49;
    border-radius: 3px;

    &:hover {
      background: #1a3a5c;
    }
  }

  // Firefox 滚动条样式
  scrollbar-width: thin;
  scrollbar-color: #142e49 rgba(20, 46, 73, 0.3);

  .info-section {
    margin-bottom: 16px;
  }

  .info-row {
    display: flex;
    margin-bottom: 12px;

    &.simple-row {
      align-items: center;
      padding: 8px 0;
      border-bottom: 1px solid rgba(64, 169, 255, 0.1);

      .row-label {
        width: 100px;
        color: rgba(255, 255, 255, 0.6);
        font-size: 14px;
      }

      .row-value {
        flex: 1;
        color: rgba(255, 255, 255, 0.9);
        font-size: 14px;

        &.name {
          color: #40a9ff;
          width: auto;
          flex: none;
          margin-right: 8px;
        }

        &.phone {
          color: #40a9ff;
          width: auto;
          flex: none;
          margin-right: 16px;
        }

        &.frequency {
          color: rgba(255, 255, 255, 0.6);
          width: auto;
          flex: none;
        }
      }

      .location-icon {
        color: #40a9ff;
        font-size: 16px;
        cursor: pointer;
        margin-left: 8px;
      }
    }
  }

  .info-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;

    .info-label {
      color: rgba(255, 255, 255, 0.6);
      font-size: 13px;
    }

    .info-value {
      color: rgba(255, 255, 255, 0.9);
      font-size: 14px;
      font-weight: 500;
    }
  }

  .info-block {
    margin-bottom: 16px;
    padding: 12px;
    background: rgba(64, 169, 255, 0.05);
    border-radius: 4px;

    .block-title {
      color: rgba(255, 255, 255, 0.6);
      font-size: 13px;
      margin-bottom: 8px;
    }

    .block-content {
      color: rgba(255, 255, 255, 0.9);
      font-size: 14px;
      line-height: 1.6;
    }
  }

  .responsibility-list {
    display: flex;
    flex-direction: column;
    gap: 8px;

    .responsibility-item {
      display: flex;
      align-items: center;
      gap: 8px;

      .responsibility-label {
        width: 140px;
        color: rgba(255, 255, 255, 0.6);
        font-size: 13px;
      }

      .responsibility-name {
        color: #40a9ff;
        font-size: 14px;
        width: 60px;
      }

      .responsibility-phone {
        color: #40a9ff;
        font-size: 14px;
        width: 120px;
      }

      .responsibility-frequency {
        color: rgba(255, 255, 255, 0.6);
        font-size: 13px;
        flex: 1;
      }
    }
  }
}
</style>
