<template>
  <div class="div-container">
    <div class="top">
      <div class="top-left">
        <span style="margin: 0 10px 0 10px">关键字</span>
        <a-input v-model:value="value" style="margin: 0 12px 0 0" />
        <span style="margin: 0 10px 0 10px">预警类型</span>
        <a-input v-model:value="value" style="margin: 0 12px 0 0" />
        <span style="margin: 0 10px 0 10px">预警级别</span>
        <a-input v-model:value="value" style="margin: 0 12px 0 0" />
        <span style="margin: 0 10px 0 10px">处置状态</span>
        <a-input v-model:value="value" style="margin: 0 12px 0 0" />
        <span style="margin: 0 10px 0 10px">预警时间</span>
        <a-input v-model:value="value" style="margin: 0 12px 0 0" />
        <a-button type="primary" style="margin: 0 0 0 12px" @click="addInfo">查询</a-button>
      </div>
      <div class="top-right">
        <a-button type="primary" style="margin: 0 0 0 12px" @click="addInfo"
          ><PlusOutlined />新增</a-button
        >
        <a-button type="primary" danger style="margin: 0 0 0 12px"><DeleteOutlined />删除</a-button>
      </div>
    </div>
    <div class="table-body">
      <BasicTable @register="registerTable">
        <template #action="{ record }">
          <TableAction
            :actions="[
              {
                label: '详情',
                onClick: handleItem.bind(null, record),
              },
              {
                label: '编辑',
                onClick: handleEdit.bind(null, record),
              },
            ]"
          />
        </template>
      </BasicTable>
    </div>
    <dialogForm ref="dialog" />
    <dialogFormHandle ref="handleDialog" />
  </div>
</template>
<script setup lang="ts">
  import { PlusOutlined, DeleteOutlined } from '@ant-design/icons-vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { tableColums } from './tableColumns';
  import { ref, onMounted } from 'vue';
  import dialogForm from './dialogForm.vue';
  import dialogFormHandle from './dialogFormHandle.vue';
  interface DataItem {
    key: string;
    name: string;
    age: number;
    address: string;
    ellipsis: boolean;
  }
  const data: DataItem[] = [];
  for (let i = 0; i < 46; i++) {
    data.push({
      key: i.toString(),
      name: `Edward King ${i}`,
      age: 32,
      address: `London, Park ${i}`,
      ellipsis: true,
    });
  }
  // let scrollY = ref();
  // onMounted(() => {
  //   scrollY.value = document.querySelector('.div-container')?.clientHeight ;
  //   console.log(scrollY, 123);
  // });
  const [registerTable] = useTable({
    title: '',
    columns: tableColums,
    useSearchForm: false,
    showTableSetting: false,
    bordered: false,
    showIndexColumn: true,
    canResize: false,
    striped: true,
    pagination: true,
    dataSource: data,
    scroll: { y: 700 },
    actionColumn: {
      width: 100,
      dataIndex: 'action',
      title: '操作',
      slots: { customRender: 'action' },
      fixed: 'right',
    },
    rowSelection: {
      type: 'checkbox',
    },
  });

  /**
   * 点击详情
   */
  function handleItem() {
    dialog.value.show();
  }
  /**
   * 点击编辑
   */
  function handleEdit() {
    dialog.value.show();
  }

  const dialog = ref();
  const handleDialog = ref();
  const value = ref('');
  onMounted(() => {
    console.log(dialog.value); // Proxy {…}
    console.log(handleDialog.value); // Proxy {…}
  });

  function addInfo() {
    dialog.value.show();
  }
</script>

<style lang="less" scoped>
  .div-container {
    width: 100%;
    height: 100%;
    background: #f0f0f0;
    padding: 10px;
    margin-right: 0;

    .top {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 10px;
      width: 100%;
      height: 55px;
      background: #fff;
      line-height: 55px;
    }

    .gdiv {
      width: 350px;
    }

    .ant-input {
      width: 160px;
      height: 32px;
    }

    .table-body {
      background: #fff;
      padding: 6px;
    }
  }
</style>
