import type { VbenFormProps } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { QueryApi } from '#/api';

export const searchFormOptions: VbenFormProps = {
  showCollapseButton: false,
  schema: [
    {
      component: 'Input',
      fieldName: 'code',
      label: '查询编号',
    },
    {
      component: 'Input',
      fieldName: 'name',
      label: '查询名称',
    },
  ],
};

export const gridOptions: VxeGridProps<QueryApi.RecordItem> = {
  toolbarConfig: {
    refresh: true,
    print: false,
    export: false,
    zoom: true,
    custom: true,
  },
  columns: [
    { title: '序号', type: 'seq', width: 50 },
    {
      align: 'left',
      field: 'code',
      title: '查询编号',
      width: 120,
    },
    { align: 'left', field: 'name', title: '查询名称', width: 200 },
    { field: 'sort', title: '排序', width: 50 },
    { align: 'left', field: 'remark', title: '备注' },
    {
      field: 'action',
      fixed: 'right',
      slots: { default: 'action' },
      title: '操作',
      width: 140,
    },
  ],
  height: 'auto',
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      query: async ({ page }, formValues) => {
        return await QueryApi.getPage({
          pageIndex: page.currentPage,
          pageSize: page.pageSize,
          ...formValues,
        });
      },
    },
  },
};
