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

import { getPlatformQualificationsList } from '../api/qualifications';

interface RowType {
  id: string;
  drug_license_image: string;
  business_license_image: string;
  medical_device_license_image: string;
  food_license_image: string;
  pharmacist_certificate_image: string;
  internet_drug_license_image: string;
  store_id: number | null;
  sort_order: number;
  status: number;
  status_txt: string;
  created_at: string;
  updated_at: 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_license_image',
      align: 'left',
      title: '药品经营许可证',
      slots: { default: 'drug_license_image' },
      width: 150,
    },
    {
      field: 'business_license_image',
      align: 'left',
      title: '营业执照',
      slots: { default: 'business_license_image' },
      width: 150,
    },
    {
      field: 'medical_device_license_image',
      align: 'left',
      title: '医疗器械经营许可证',
      slots: { default: 'medical_device_license_image' },
      width: 180,
    },
    {
      field: 'food_license_image',
      align: 'left',
      title: '食品经营许可证',
      slots: { default: 'food_license_image' },
      width: 150,
    },
    {
      field: 'pharmacist_certificate_image',
      align: 'left',
      title: '药师资格证',
      slots: { default: 'pharmacist_certificate_image' },
      width: 150,
    },
    {
      field: 'internet_drug_license_image',
      align: 'left',
      title: '互联网药品经营许可证',
      slots: { default: 'internet_drug_license_image' },
      width: 180,
    },
    {
      field: 'store_name',
      align: 'left',
      title: '绑定店铺',
      width: 150,
      slots: { default: 'store_name' },
    },
    { field: 'sort_order', align: 'left', title: '排序', width: 100 },
    {
      field: 'status_txt',
      align: 'left',
      title: '状态',
      width: 100,
    },
    { field: 'created_at', title: '创建时间', width: 180 },
    { type: 'html', title: '操作', slots: { default: 'action' }, width: 150 },
  ],
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      // 请求后端接口方法
      query: async ({ page }, formValues) => {
        return await getPlatformQualificationsList({
          page: page.currentPage,
          pageSize: page.pageSize,
          ...formValues,
        });
      },
    },
  },
  border: false,
  toolbarConfig: {
    // 是否显示搜索表单控制按钮
    // @ts-ignore 正式环境时有完整的类型声明
    search: true,
    refresh: true, // 刷新
    print: false, // 打印
    export: false, // 导出
    // custom: true, // 自定义列
    zoom: true, // 最大化最小化
    slots: {
      buttons: 'toolbar-actions',
    },
    custom: {
      // 自定义列-图标
      icon: 'vxe-icon-menu',
    },
  },
  showOverflow: false,
};
