// 导入VxeGrid配置类型
import type { VxeGridProps } from '#/adapter/vxe-table';

// 导入保健食品列表查询API
import { getHealthFoodList } from '../api';

/**
 * 表格行数据类型定义
 */
interface RowType {
  id: string;
  name: string;
  logo: string;
  introduce: string;
  created_at: string;
  zone_id: number;
  zone_name: string;
  category_id: number;
  category_name: string;
}

/**
 * 保健食品管理表格配置
 * 列结构对齐西药：商品信息/分类仓储/总仓售价合并列 + 页内特有列
 */
export const gridOptions: VxeGridProps<RowType> = {
  checkboxConfig: {
    highlight: true,
    labelField: '',
  },
  columnConfig: {
    useKey: true,
  },
  rowConfig: {
    useKey: true,
  },
  columns: [
    { type: 'checkbox', width: 60 },
    {
      field: 'drug_name',
      align: 'left',
      title: '商品信息',
      minWidth: 260,
      slots: { default: 'product_info' },
    },
    {
      field: 'zone_name',
      title: '分类仓储',
      minWidth: 200,
      slots: { default: 'category_warehouse' },
    },
    {
      field: 'central_price',
      title: '总仓售价',
      width: 110,
      slots: { default: 'central_price' },
    },
    { field: 'supplier.name', title: '供应商', slots: { default: 'supplier' }, width: 130 },
    { field: 'specification', title: '规格', width: 120 },
    {
      field: 'is_free_shipping',
      title: '单品包邮',
      width: 100,
      slots: { default: 'is_free_shipping' },
    },
    { field: 'status', title: '状态', width: 90, slots: { default: 'status' } },
    { type: 'html', title: '操作', fixed: 'right', width: 320, slots: { default: 'action' } },
  ],
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      query: async ({ page }, formValues) => {
        return await getHealthFoodList({
          page: page.currentPage,
          pageSize: page.pageSize,
          ...formValues,
        });
      },
    },
  },
  height: 'auto',
  border: false,
  toolbarConfig: {
    // @ts-ignore 正式环境时有完整的类型声明
    search: true,
    refresh: true,
    print: false,
    export: false,
    zoom: true,
    slots: {
      buttons: 'toolbar-actions',
    },
    custom: {
      icon: 'vxe-icon-menu',
    },
  },
  showOverflow: false,
};
