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

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

interface RowType {
  id: number;
  type: number;
  type_txt: string;
  name: string;
  value: string;
  color: string;
  sort: 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,
    isHover: true,
    isCurrent: true,
  },
  columns: [
    { type: 'checkbox', width: 60 },
    { field: 'id', align: 'left', title: 'ID', width: 80 },
    { field: 'type_txt', align: 'left', title: '类型', width: 110 },
    { field: 'name', align: 'left', title: '名称', minWidth: 140 },
    { field: 'value', align: 'left', title: '存储值', minWidth: 140 },
    {
      field: 'color',
      align: 'left',
      title: '颜色',
      width: 120,
      // 用色块+hex 直观预览，避免放函数调用导致渲染异常
      slots: { default: 'color' },
    },
    { field: 'sort', align: 'left', title: '排序', width: 90 },
    { field: 'status_txt', align: 'left', title: '状态', width: 90 },
    { 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 getPatientCallLogDictList({
          page: page.currentPage,
          pageSize: page.pageSize,
          ...formValues,
        });
      },
    },
  },
  border: false,
  toolbarConfig: {
    search: true,
    refresh: true,
    print: false,
    export: false,
    zoom: true,
    slots: {
      buttons: 'toolbar-actions',
    },
    custom: {
      icon: 'vxe-icon-menu',
    },
  },
  showOverflow: false,
};
