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

import { getDeliveryWarehouseDrugList } from '#/views/system/delivery-warehouse-drug/api';

interface RowType {
  id: string;
  warehouse_id: number;
  drug_id: number;
  quote: string;
  promo_fee: string;
  platform_fee: string;
  stock: number;
  frozen_number: number;
  status: number;
  created_at: string;
  drug?: { drug_name: string };
  warehouse?: { name: string };
}

export const gridOptions: VxeGridProps<RowType> = {
  checkboxConfig: {
    highlight: true,
    labelField: '',
  },
  columnConfig: {
    useKey: true,
  },
  rowConfig: {
    useKey: true,
  },
  columns: [
    { type: 'checkbox', width: 60 },
    { field: 'id', align: 'left', title: 'ID', width: 100 },
    {
      field: 'warehouse_id',
      title: '配送仓库',
      slots: { default: 'warehouse_id' },
    },
    { field: 'drug_id', title: '药品ID', width: 100 },
    {
      field: 'drug_name',
      title: '药品名称',
      slots: { default: 'drug_name' },
    },
    { field: 'quote', title: '报价' },
    { field: 'promo_fee', title: '推广费' },
    { field: 'platform_fee', title: '平台费' },
    { field: 'stock', title: '库存' },
    { field: 'frozen_number', title: '冻结数量' },
    {
      field: 'status',
      title: '状态',
      slots: { default: 'status' },
      width: 100,
    },
    { field: 'created_at', title: '创建时间' },
    { type: 'html', title: '操作', slots: { default: 'action' } },
  ],
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      query: async ({ page }, formValues) => {
        return await getDeliveryWarehouseDrugList({
          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,
};
