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

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

interface RowType {
  id: number;
  title: string;
  type: string;
  icon: string;
  description: string;
  sort_order: number;
  status: number;
  status_txt: string;
  store_id: number | null;
  drug_type: number | null;
  drug_type_txt: string;
  created_at: string;
  updated_at: string;
}

export const gridOptions: VxeGridProps<RowType> = {
  checkboxConfig: {
    highlight: true,
    labelField: '',
  },
  columnConfig: {
    useKey: true,
  },
  rowConfig: {
    useKey: true,
    isHover: true,
    isCurrent: true,
  },
  columns: [
    { type: 'checkbox', width: 60 },
    { field: 'id', align: 'left', title: 'ID', width: 80 },
    { field: 'title', align: 'left', title: '标题', minWidth: 160 },
    {
      field: 'type',
      align: 'left',
      title: '类型',
      width: 140,
      formatter: ({ cellValue }) => {
        const map: Record<string, string> = {
          otc: 'OTC专区',
          prescription: '处方药专区',
          health_food: '保健食品专区',
          service_package: '产品服务包专区',
          non_drug: '非药品专区',
          medical_device: '医疗器械专区',
        };
        return map[cellValue] || cellValue || '-';
      },
    },
    {
      field: 'drug_type_txt',
      align: 'left',
      title: '药品类型',
      width: 120,
    },
    {
      field: 'icon',
      align: 'left',
      title: '图标',
      width: 160,
      slots: { default: 'icon' },
    },
    {
      field: 'description',
      align: 'left',
      title: '描述',
      minWidth: 200,
      showOverflow: 'tooltip',
    },
    { 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: 160 },
  ],
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      // 请求后端接口方法
      query: async ({ page }, formValues) => {
        return await getHomeZonesList({
          page: page.currentPage,
          pageSize: page.pageSize,
          ...formValues,
        });
      },
    },
  },
  border: false,
  toolbarConfig: {
    search: true,
    refresh: true,
    print: false,
    export: false,
    zoom: true,
    slots: {
      buttons: 'toolbar-buttons',
    },
    custom: {
      icon: 'vxe-icon-menu',
    },
  },
  showOverflow: false,
};

