<template>
  <PageWrapper dense>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button type="primary" @click="handleAdd">新增</a-button>
        <a-button type="primary" @click="handleAdd">配置人员</a-button>
        <a-button type="primary" @click="handleAdd">配置服务目录</a-button>
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column && record && column.key === 'action'">
          <a-button type="link" @click="handleEdit(record.id)">编辑</a-button>
          <a-button type="link" @click="handleDelete(record.id)">删除</a-button>
          <a-button type="link" @click="handleDetail(record.id)">详情</a-button>
        </template>
      </template>
    </BasicTable>
    <detailDrawer ref="detailDrawerRef" />
    <addModal ref="addModalRef" />
  </PageWrapper>
</template>

<script setup lang="ts">
  import { PageWrapper } from '@/components/Page';
  import { BasicTable, useTable } from '@/components/Table';
  import { list, removeByIds } from './api';
  import { formSchemas, columns } from './data';
  import detailDrawer from './detailDrawer.vue';
  import { ref } from 'vue';
  import addModal from './addModal.vue';

  defineOptions({ name: 'ProjectManage' });

  const [registerTable, { reload }] = useTable({
    rowSelection: {
      type: 'checkbox',
    },
    title: '项目管理',
    api: list,
    showIndexColumn: true,
    rowKey: 'id',
    useSearchForm: true,
    formConfig: {
      schemas: formSchemas,
      name: 'projectManage',
      baseColProps: {
        xs: 24,
        sm: 24,
        md: 24,
        lg: 6,
      },
    },
    columns: columns,
    actionColumn: {
      width: 200,
      title: '操作',
      key: 'action',
      fixed: 'right',
    },
  });

  //抽屉
  const detailDrawerRef = ref();
  const handleDetail = (id: any) => {
    detailDrawerRef.value.showDrawer(id);
  };
  const handleDelete = async (id: any) => {
    await removeByIds([id]);
    reload();
  };
  //新增编辑弹窗
  const addModalRef = ref();
  const handleAdd = () => {
    addModalRef.value.showModal(1);
  };
  const handleEdit = (id: any) => {
    addModalRef.value.showModal(2, id);
  };
</script>

<style scoped></style>
