<template>
  <div class="div-container">
    <div class="top">
      <span style="margin: 0 12px 0 0">关键字</span>
      <a-input
        v-model:value="value"
        placeholder="请输入设备类型名称,统计单位"
        style="margin: 0 12px 0 0"
      />
      <a-button type="primary" style="margin: 0 12px 0 0"><SearchOutlined />查询</a-button>
      <a-button type="primary" style="margin: 0 12px 0 0" @click="addInfo"
        ><PlusOutlined />添加</a-button
      >
      <a-button type="primary" danger><DeleteOutlined />删除</a-button>
    </div>
    <div class="table-body">
      <!-- <wtable :tableData="tableData" /> -->
      <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" />
  </div>
</template>
<script setup lang="ts">
  import { SearchOutlined, 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';
  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,
    });
  }
  const [registerTable] = useTable({
    title: '',
    columns: tableColums,
    useSearchForm: false,
    showTableSetting: false,
    bordered: false,
    showIndexColumn: true,
    canResize: false,
    striped: true,
    pagination: true,
    dataSource: data,
    actionColumn: {
      width: 100,
      dataIndex: 'action',
      title: '操作',
      slots: { customRender: 'action' },
      fixed: 'right',
    },
    rowSelection: {
      type: 'checkbox',
    },
  });

  // let tableData = reactive({
  //   columns: [
  //     {
  //       title: '序号',
  //       width: '100px',
  //       dataIndex: 'index',
  //       key: 'index',
  //       customRender: (text) => {
  //         return text.index + 1;
  //       },
  //     },
  //     {
  //       title: '设备分组',
  //       dataIndex: 'name',
  //     },
  //     {
  //       title: '类型名称',
  //       dataIndex: 'age',
  //     },
  //     {
  //       title: '数量统计单位',
  //       dataIndex: 'address',
  //     },
  //     {
  //       title: '修改人',
  //       dataIndex: 'address',
  //     },
  //     {
  //       title: '备注',
  //       dataIndex: 'address',
  //     },
  //     {
  //       title: '修改时间',
  //       dataIndex: 'address',
  //     },
  //     {
  //       title: '操作',
  //       dataIndex: 'address',
  //     },
  //   ],
  // });
  /**
   * 点击详情
   */
  function handleItem() {}
  /**
   * 点击编辑
   */
  function handleEdit() {}

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

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

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

    .top {
      width: 100%;
      height: 40px;
      background: #fff;
      line-height: 40px;
    }

    .ant-input {
      width: 240px;
      height: 30px;
    }

    .table-body {
      height: 100%;
    }
  }
</style>
