import { listDictModel } from '/@/api/common';
import { DescItem } from '/@/components/Description';
import { BasicColumn, FormSchema } from '/@/components/Table';
import { validateStr } from '/@/utils/validate';

export const columns: BasicColumn[] = [
  {
    title: '岗位名称',
    dataIndex: 'posName',
  },
  {
    title: '岗位编码',
    dataIndex: 'posCode',
  },
  {
    title: '排序码',
    dataIndex: 'sort',
  },
  {
    title: '状态',
    dataIndex: 'disable',
  },
];

// 表单列定义
export const searchFormSchema: FormSchema[] = [
  {
    label: '岗位名称',
    field: 'posName',
    component: 'Input',
    componentProps: {
      placeholder: '请输入岗位名称',
    },
  },
  {
    label: '状态',
    field: 'disable',
    component: 'ApiSelect',
    componentProps: {
      api: listDictModel,
      params: {
        dictCode: 'sys_disable_type',
      },
    },
  },
];
// 表单新增编辑
export const dataFormSchema: FormSchema[] = [
  {
    label: '岗位名称',
    field: 'posName',
    required: true,
    component: 'Input',
    componentProps: {
      placeholder: '请输入岗位名称',
    },
  },
  {
    label: '岗位编码',
    field: 'posCode',
    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();
          },
        },
      ];
    },
  },
  {
    label: '排序码',
    field: 'sort',
    required: true,
    component: 'Input',
    componentProps: {
      placeholder: '请输入排序码',
    },
  },
  {
    label: '状态',
    field: 'disable',
    required: true,
    component: 'ApiRadioGroup',
    componentProps: {
      api: listDictModel,
      params: {
        dictCode: 'sys_disable_type',
      },
    },
    defaultValue: '0',
  },
  {
    label: '备注',
    field: 'remark',
    component: 'Input',
    componentProps: {
      placeholder: '请输入备注',
    },
  },
];
// 表单详情查看
export const viewSchema: DescItem[] = [
  {
    label: '岗位名称',
    field: 'posName',
  },
  {
    label: '岗位编码',
    field: 'posCode',
  },
  {
    label: '排序码',
    field: 'sort',
  },
  {
    label: '备注',
    field: 'remark',
  },
  {
    label: '状态',
    field: 'disable',
  },
  {
    label: '创建时间',
    field: 'createTime',
  },
  {
    label: '更新时间',
    field: 'updateTime',
  },
];
