<template>
  <div class="accident-records-container">
    <div class="container-title">
      <span class="line"></span>
      <span class="title">本月交通事故记录</span>
      <span class="more" @click="handleClickMore"
        >查看全部<el-icon><ArrowRight /></el-icon
      ></span>
    </div>
    <div class="table-container">
      <el-table :data="accidentRecords" style="width: 100%; height: 100%">
        <el-table-column prop="accidentLocation" label="事故地点" />
        <el-table-column prop="accidentTime" label="事故时间" width="200px" />
        <el-table-column prop="accidentDescription" label="事故描述" />
        <el-table-column prop="action" label="操作" width="120px" align="left" fixed="right">
          <template #default="scope">
            <div class="view-detail" @click="handleViewDetail(scope.row.id)"> 查看详情 </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { ref, onMounted } from 'vue';
  import router from '@/router';
  import { ElIcon } from 'element-plus';
  import { ArrowRight } from '@element-plus/icons-vue';
  import {
    QueryPageParams,
    QueryTrafficAccidentRecordOverviewPageRes,
    getTrafficAccidentRecordOverview,
  } from '@/api/traffic-overview';

  const queryPageParams = ref<QueryPageParams>({
    pageNumber: 1,
    pageSize: 20,
  });
  const accidentRecords = ref<QueryTrafficAccidentRecordOverviewPageRes[]>([]);

  const handleClickMore = () => {
    router.push({
      path: '/traffic/accident',
    });
  };

  const handleViewDetail = (id: number) => {
    router.push({
      path: '/traffic/accident-item',
      query: { id: id },
    });
  };

  const getTrafficAccidentRecordOverviewData = () => {
    getTrafficAccidentRecordOverview(queryPageParams.value).then((res) => {
      accidentRecords.value = res.records;
    });
  };

  onMounted(() => {
    getTrafficAccidentRecordOverviewData();
  });
</script>

<style scoped lang="scss">
  .container-title {
    height: 24px;
    display: flex;
    align-items: center;
    font-weight: 500;
    font-size: 16px;
    color: #000000;

    .line {
      width: 3px;
      height: 16px;
      background: #1777ff;
      margin-right: 10px;
    }

    .title {
      margin-right: 12px;
    }

    .more {
      margin-left: auto;
      margin-right: 17px;
      font-weight: 400;
      font-size: 16px;
      color: #1777ff;
      display: flex;
      align-items: center;
      cursor: pointer;
    }

    .more:hover {
      color: #94c1ff;
    }
  }

  .accident-records-container {
    width: 100%;
    height: 100%;
    padding: 14px 0;

    .table-container {
      width: 100%;
      height: calc(100% - 24px - 18px);
      margin-top: 18px;
      padding: 0 16px;
      overflow: auto;

      .view-detail {
        font-size: 14px;
        color: #1777ff;
        cursor: pointer;
      }

      .view-detail:hover {
        color: #94c1ff;
      }
    }
  }
</style>
