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

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

interface RowType {
  id: number;
  image?: string;
  drug_name: string;
  type_txt?: string;
  audit_status: number;
  audit_status_txt?: string;
  status: number;
  status_txt?: string;
  status_color?: string;
  uploader_name?: string;
  created_at: string;
}

/**
 * 仓侧「我的商品」表格列与远程分页
 */
export const gridOptions: VxeGridProps<RowType> = {
  checkboxConfig: {
    highlight: true,
    labelField: '',
  },
  columnConfig: {
    useKey: true,
  },
  rowConfig: {
    useKey: true,
  },
  columns: [
    { field: 'id', align: 'left', title: 'ID', width: 80 },
    {
      field: 'image',
      title: '图片',
      width: 80,
      slots: { default: 'image' },
    },
    { field: 'drug_name', title: '药品名称', minWidth: 160 },
    { field: 'type_txt', title: '类型', width: 110 },
    {
      field: 'audit_status_txt',
      title: '审核状态',
      width: 110,
      slots: { default: 'audit_status' },
    },
    {
      field: 'status_txt',
      title: '商品状态',
      width: 100,
      slots: { default: 'status' },
    },
    { field: 'uploader_name', title: '上传人', width: 120 },
    { field: 'created_at', title: '创建时间', width: 170 },
    {
      type: 'html',
      title: '操作',
      fixed: 'right',
      width: 120,
      slots: { default: 'action' },
    },
  ],
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      query: async ({ page }, formValues) => {
        return await getDeliveryWarehouseProductList({
          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,
};
