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

import { getWarehouseDrugChangeLogList } from '../api';
import { normalizeChangeLogFilters } from './search';

export const gridOptions: VxeGridProps<any> = {
  checkboxConfig: {
    highlight: true,
    labelField: '',
  },
  columns: [
    { field: 'id', title: 'ID', width: 80 },
    { field: 'operator_name', title: '操作人', minWidth: 100 },
    {
      field: 'user_type_txt',
      title: '用户类型',
      width: 90,
      slots: { default: 'user_type' },
    },
    {
      field: 'change_type_txt',
      title: '变更类型',
      width: 110,
      slots: { default: 'change_type' },
    },
    { field: 'drug_name', title: '药品名称', minWidth: 120 },
    { field: 'drug_number', title: '药品编码', minWidth: 110 },
    { field: 'store_id', title: '门店ID', width: 90 },
    { field: 'batch_no', title: '批次号', minWidth: 140 },
    { field: 'remark', title: '备注', minWidth: 140 },
    { field: 'created_at', title: '操作时间', width: 170 },
    {
      title: '操作',
      width: 90,
      fixed: 'right',
      slots: { default: 'action' },
    },
  ],
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      query: async ({ page }, formValues) => {
        return await getWarehouseDrugChangeLogList({
          page: page.currentPage,
          pageSize: page.pageSize,
          ...normalizeChangeLogFilters(formValues || {}),
        });
      },
    },
  },
  height: 'auto',
  toolbarConfig: {
    search: true,
    refresh: true,
    zoom: true,
    slots: {
      buttons: 'toolbar-actions',
    },
  },
};
