<template>
  <div class="table-box">
    <div class="card table-main">
      <!-- 表格头部 操作按钮 -->
      <div class="table-header">
        <div class="header-button-lf">
          <el-form :model="queryParams" label-width="auto"  :inline="true">
            <el-form-item label="站号:">
              <el-select v-model="queryParams.code"  filterable placeholder="请选择" clearable style="width: 200px">
                <el-option label="RS0001" value="RS0001" />
                <el-option label="RS0002" value="RS0002" />
              </el-select>
            </el-form-item>
            <el-form-item label="告警类型:">
              <el-select v-model="queryParams.type" placeholder="请选择" clearable style="width: 200px">
                <el-option label="能见度" value="1" />
              </el-select>
            </el-form-item>
            <el-form-item label="告警时间:">
              <el-date-picker
                v-model="queryParams.time"
                type="datetimerange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="handleQuery"> 查询 </el-button>
              <el-button style="margin-left: 10px" @click="resetQuery"> 重置 </el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <!-- 表格主体 -->
      <el-table stripe ref="tableRef" :border="true" :data="processTableData"  size="small">
        <el-table-column align="left" label="序号" width="80px" :show-overflow-tooltip="true">
          <template #default="scope">
            {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
          </template>
        </el-table-column>
        <template v-for="item in columns" :key="item">
          <el-table-column v-bind="item" :align="item.align ?? 'left'" :reserve-selection="item.type == 'selection'" :show-overflow-tooltip="true">
          </el-table-column>
        </template>
        <!-- 无数据 -->
        <template #empty>
          <div class="table-empty">
            <slot name="empty">
              <img src="@/assets/images/notData.png" alt="notData" />
              <div>暂无数据</div>
            </slot>
          </div>
        </template>
      </el-table>
      <!-- 分页组件 -->
      <Pagination :pageable="pageable" :handle-size-change="handleSizeChange" :handle-current-change="handleCurrentChange" />
    </div>
  </div>
</template>

<script setup lang="ts" name="useProTable">
import Pagination from "@/components/ProTable/components/Pagination.vue";
import { ref, reactive } from "vue";
import { ColumnProps } from "@/components/ProTable/interface";
const pageable = ref<any>({
  pageNum: 1,
  pageSize: 20,
  total: 1
});

const queryParams = ref({
  code: '',
  type:'',
  time:'',
  pageNum: 1,
  pageSize: 20,
  total: 2
});

// 查询功能
const handleQuery = () => {
  queryParams.value.pageNum = 1;
};

//搜索功能
const resetQuery = () => {
  queryParams.value.pageNum = 1;
};

/**
 * @description 每页条数改变
 * @param {Number} val 当前条数
 * @return void
 * */
const handleSizeChange = (val: number) => {
  console.log(val);
};

/**
 * @description 当前页改变
 * @param {Number} val 当前页
 * @return void
 * */
const handleCurrentChange = (val: number) => {
  console.log(val);
};

const processTableData = ref([
  {
    id: "681913747276782417",
    b: "RS001",
    a: "测试本地",
    c: "日常策略",
    d: "告警中",
    e: "能见度",
    f: "143m",
    g: "2023-06-12 15:00:00",
    h: "2023-06-12 15:00:00",
    i: "字幕通知",
    j: "能见度告警 阈值(1分钟平均能见度 ≤ 500m)观测值(143m)"
  },
  {
    id: "681913747276782417",
    b: "M1987",
    a: "固定站2",
    c: "123",
    d: "已消警",
    e: "能见度",
    f: "143m",
    g: "2023-06-12 15:00:00",
    h: "2023-06-12 15:00:00",
    i: "字幕通知",
    j: "能见度告警 阈值(1分钟平均能见度 ≤ 500m)观测值(143m)"
  }
]);

// 表格配置项
const columns = reactive<ColumnProps[]>([
  { prop: "b", label: "站号" },
  { prop: "a", label: "站名" },
  { prop: "c", label: "策略名称" },
  { prop: "d", label: "策略状态" },
  { prop: "e", label: "告警类型" },
  { prop: "f", label: "观测值" },
  { prop: "g", label: "告警时间",width:150 },
  { prop: "h", label: "消警时间",width:150},
  { prop: "i", label: "通知方式" },
  { prop: "j", label: "告警说明",width:400 }
]);
</script>
