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

import { getPrescriptionListApi } from '../api';

interface RowType {
  id: number;
  prescription_no: string;
  created_at: string;
  auto_expire_time: number;
  is_online: number;
  status: number;
  prescription_type: number;
}

/**
 * 审方列表列：多列拆分，避免单列堆叠
 * query 由页面注入 searchValues，此处仅作默认；index 会覆盖 proxy
 */
export const gridOptions: VxeGridProps<RowType> = {
  checkboxConfig: {
    highlight: true,
    labelField: '',
  },
  columns: [
    {
      field: 'prescription_no',
      align: 'left',
      title: '处方单号',
      minWidth: 160,
      slots: { default: 'prescription_no' },
    },
    {
      field: 'store.name',
      align: 'left',
      title: '诊所',
      minWidth: 120,
      slots: { default: 'store' },
    },
    {
      field: 'doctor_info',
      align: 'left',
      title: '开方医生',
      minWidth: 140,
      slots: { default: 'doctor' },
    },
    {
      field: 'user_patient',
      align: 'left',
      title: '就诊人',
      minWidth: 200,
      slots: { default: 'patient' },
    },
    {
      field: 'is_online',
      align: 'left',
      title: '处方来源',
      width: 110,
      slots: { default: 'is_online' },
    },
    {
      field: 'created_at',
      align: 'left',
      title: '时间',
      minWidth: 180,
      slots: { default: 'time' },
    },
    {
      field: 'status',
      title: '状态',
      width: 100,
      slots: { default: 'status' },
    },
    {
      title: '操作',
      align: 'right',
      slots: { default: 'action' },
      width: 280,
      fixed: 'right',
    },
  ],
  keepSource: true,
  pagerConfig: {},
  columnConfig: {
    useKey: true,
  },
  rowConfig: {
    useKey: true,
    isHover: true,
  },
  proxyConfig: {
    ajax: {
      query: async ({ page }, formValues) => {
        return await getPrescriptionListApi({
          page: page.currentPage,
          pageSize: page.pageSize,
          ...formValues,
        });
      },
    },
  },
  height: 'auto',
  border: 'inner',
  toolbarConfig: {
    // @ts-ignore
    search: false,
    refresh: true,
    print: false,
    export: false,
    zoom: true,
    slots: {
      buttons: 'toolbar-actions',
    },
  },
  showOverflow: false,
};
