import { validateStr } from '/@/utils/validate';
import { listDictModel } from '/@/api/common';
import { BasicColumn, FormSchema } from '/@/components/Table';
export const columns: BasicColumn[] = [
  {
    title: '角色名称',
    dataIndex: 'name',
  },
  {
    title: '角色编码',
    dataIndex: 'code',
  },
  {
    title: '角色类型',
    dataIndex: 'type',
  },
  {
    title: '状态',
    dataIndex: 'disable',
  },
  {
    title: '排序',
    dataIndex: 'sort',
    width: 90,
  },
  {
    title: '备注',
    dataIndex: 'remark',
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 160,
  },
  {
    title: '更新时间',
    dataIndex: 'updateTime',
    width: 160,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '角色名称',
    component: 'Input',
    componentProps: {
      placeholder: '请输入角色名称',
    },
  },
  {
    field: 'code',
    label: '角色编码',
    component: 'Input',
    componentProps: {
      placeholder: '请输入角色编码',
    },
  },
];

export const dataFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '角色名称',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入角色名称',
    },
  },
  {
    field: 'code',
    label: '角色编码',
    component: 'Input',
    componentProps: {
      placeholder: '请输入角色编码',
    },
    dynamicRules: () => {
      return [
        {
          required: true,
          validator: async (_, value) => {
            if (!value) {
              return Promise.reject('角色编码不能为空');
            }
            if (validateStr(value)) {
              return Promise.reject('角色编码为字母或数字组成');
            }
            return Promise.resolve();
          },
        },
      ];
    },
  },
  {
    field: 'orgIds',
    label: '数据权限',
    slot: 'orgIds',
    component: 'Input',
    ifShow: ({ values }) => values.dataScope === '2',
  },
  {
    field: 'sort',
    label: '排序',
    component: 'InputNumber',
    required: true,
    defaultValue: 99,
    componentProps: {
      placeholder: '请输入排序',
      min: 1,
    },
  },
  {
    field: 'disable',
    label: '状态',
    component: 'ApiRadioGroup',
    required: true,
    componentProps: {
      api: listDictModel,
      params: {
        dictCode: 'sys_disable_type',
      },
    },
    defaultValue: '0',
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    componentProps: {
      placeholder: '请输入备注',
    },
  },
];
