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

import { getWesternMedicineList } 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: 'id', align: 'left', title: 'ID', width: 100 },
    { field: 'drug_name', align: 'left', title: '药品名称', width: 120 },
    { field: 'pinyin_simple', title: '拼音', width: 120 },
    {
      field: 'zone_name',
      title: '分区',
      width: 100,
      slots: { default: 'zone' },
    },
    {
      field: 'category_name',
      title: '分类',
      width: 120,
      slots: { default: 'category' },
    },
    { field: 'supplier.name', title: '供应商', slots: { default: 'supplier' },width: 130 },
    {
      field: 'image',
      align: 'left',
      title: '产品图片',
      slots: { default: 'image' },
      width: 130,
    },
    {
      field: 'instruction',
      align: 'left',
      title: '说明书',
      slots: { default: 'instruction' },
      width: 130,
    },
    { field: 'function', title: '主要功能', width: 240 },
    { field: 'specification', title: '规格', width: 130 },
    {
      field: 'is_otc',
      title: '处方药',
      width: 100,
      slots: { default: 'is_otc' },
    },
    { field: 'status', title: '状态', slots: { default: 'status' } },
    { field: 'created_at', title: '发布时间', width: 240 },
    {
      field: 'min_adjust_price',
      title: '最低调整金额',
      width: 130,
      slots: { default: 'min_adjust_price' },
    },
    { type: 'html', title: '操作', fixed: 'right', width: 280, slots: { default: 'action' } },
  ],
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      // 请求后端接口方法
      query: async ({ page }, formValues) => {
        return await getWesternMedicineList({
          page: page.currentPage,
          pageSize: page.pageSize,
          ...formValues,
        });
      },
    },
  },
  // exportConfig: {
  //   api: passApplicationApi,
  // },
  height: 'auto',
  border: false,
  toolbarConfig: {
    // 是否显示搜索表单控制按钮
    // @ts-ignore 正式环境时有完整的类型声明
    search: true,
    refresh: true, // 刷新
    print: false, // 打印
    export: false, // 导出
    // custom: true, // 自定义列
    zoom: true, // 最大化最小化
    slots: {
      buttons: 'toolbar-buttons',
    },
    custom: {
      // 自定义列-图标
      icon: 'vxe-icon-menu',
    },
  },
  showOverflow: false,
};
