<template>
  <div class="div-container">
    <div class="top">
      <span style="margin: 0 0 0 12px">所属单位：</span>
      <a-input v-model:value="value" placeholder="" style="margin: 0 20px 0 0" />
      <span>学历：</span>
      <a-input v-model:value="value" placeholder="" style="margin: 0 20px 0 0" />
      <span>学位：</span>
      <a-input v-model:value="value" placeholder="" style="margin: 0 20px 0 0" />
      <span>专家姓名：</span>
      <a-input v-model:value="value" placeholder="" style="margin: 0 20px 0 0" />
      <span>所属领域：</span>
      <a-input v-model:value="value" placeholder="" style="margin: 0 20px 0 0" />
      <span>所属行业：</span>
      <a-input v-model:value="value" placeholder="" style="margin: 0 20px 0 0" />
      <a-button style="margin: 0 20px 0 0">重置</a-button>
      <a-button type="primary" style="margin: 0 12px 0 0">查询</a-button>
    </div>
    <div class="top-button">
      <a-button type="primary" style="margin: 0 12px 0 20px" @click="addInfo" size="large"
        >新增</a-button
      >
      <a-button type="primary" style="margin: 0 20px 0 0" @click="addInfo" size="large"
        >编辑</a-button
      >
      <a-button type="primary" danger size="large" style="margin: 0 20px 0 0">删除</a-button>
      <a-button type="primary" style="margin: 0 20px 0 0" @click="addInfo" size="large"
        >批量导入</a-button
      >
      <a-button type="primary" style="margin: 0 20px 0 0" @click="addInfo" size="large"
        >批量导出</a-button
      >
    </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" />
  </div>
</template>
<script setup lang="ts">
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { tableColums } from './tableColumns';
  import { ref, onMounted } from 'vue';
  import dialogForm from './dialogForm.vue';
  import { getTableList } from '/@/views/lifeline/api/riskLinkageSystemApi/baseManage/index';
  onMounted(() => {
    getTableList().then((res) => {
      console.log(res);
    });
  });
  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,
    });
  }

  /**
   * 点击详情
   */
  function handleItem() {
    dialog.value.show();
  }
  /**
   * 点击编辑
   */
  function handleEdit() {
    dialog.value.show();
  }
  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',
    },
  });
  //
  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: #f0f0f0;
    padding: 10px;
    margin-right: 0;
    overflow: hidden;

    .top {
      width: 100%;
      height: 50px;
      background: #fff;
      line-height: 50px;
      margin-bottom: 20px;
    }

    .top-button {
      margin-bottom: 20px;

      .ant-btn {
        width: 100px;
        border-radius: 5px;
      }
    }

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

    .table-body {
      height: 100%;
      padding: 10px;
      background: #fff;
    }
  }
</style>
