<template>
  <div class="deviceStatistics card">
    <div class="card-head">
      <div class="title">告警列表</div>
      <div class="condition">
        <el-input style="width: 240px" v-model="search" placeholder="搜索设备IMEI号" :suffix-icon="Search" @input="handleInput" />
      </div>
    </div>
    <TableCustom :columns="columns" :tableData="tableData" :paging="page" :changePage="changePage">
      <template #location="{ rows }">
        <el-button type="success" link :icon="View" v-if="rows.warnType == 0 || rows.warnType == 1" @click="toIncidentDispose(rows.id)"> 查看 </el-button>
      </template>
      <template #status="{ rows }">
        <el-tag :type="rows.status == 1 ? 'success' : 'danger'">
          {{ statusEnum[rows.status] }}
        </el-tag>
      </template>
    </TableCustom>
  </div>
</template>
<script setup lang="ts">
import { PropType, ref } from "vue";
import { Search, View } from "@element-plus/icons-vue";
import TableCustom from "@/components/table-custom.vue";
import { debounce } from "@/utils";
import { useRouter } from "vue-router";
import { TWarnRecord } from "@/api/index.d";

interface TPaging {
  page: number;
  size: number;
  total: number;
  deviceId?: number;
}

const router = useRouter();
enum statusEnum {
  "待处理",
  "已处理",
}
const search = ref("");

const { tableData, page, getData, changePage } = defineProps({
  tableData: {
    type: Array,
    default: () => [],
  },
  page: {
    type: Object as PropType<TPaging>,
    default: () => ({
      page: 1,
      size: 10,
      total: 0,
    }),
  },
  getData: {
    type: Function,
    default: () => {},
  },
  changePage: {
    type: Function,
    default: () => {},
  },
});
// 表格相关
let columns = [
  { type: "index", label: "序号", width: 55, align: "center" },
  { prop: "deviceId", label: "IMEI号" },
  { prop: "createTime", label: "时间" },
  { prop: "location", label: "地理位置" },
  { prop: "status", label: "处理状态" },
];
const handleInput = debounce((e) => {
  page.deviceId = e;
  getData();
}, 500);

const toIncidentDispose = (id: string) => {
  router.push({
    path: "/incidentDispose",
    query: { id },
  });
};
</script>
<style scoped lang="less">
.card {
  height: 100%;
  background: #ffffff;
  padding: 16px 10px;
  box-sizing: border-box;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
  box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.12);
  margin-bottom: 20px;
  .card-head {
    color: #061451;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transform: translateX(-10px);
    .title {
      &::before {
        display: inline-block;
        margin-right: 10px;
        content: "";
        width: 2px;
        height: 14px;
        border-radius: 20px;
        background: #061451;
      }
    }
    .condition {
      display: flex;
      align-items: center;
      margin-left: 20px;
      .condition-time {
        border: 1px solid #dcdfe6;
        overflow: hidden;
        margin-left: 20px;
      }
    }
  }
}
</style>
