import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { dict } from '/@/api/common/api'
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';

export const columns: BasicColumn[] = [
  {
    title: '姓名',
    resizable: true,
    dataIndex: 'zjxm'
  },
  {
    title: '工作单位所在区域',
    resizable: true,
    dataIndex: 'gzdwszqyName'
  },
  {
    title: '工作单位',
    resizable: true,
    dataIndex: 'gzdw'
  },
  {
    title: '技术职称',
    dataIndex: 'jszc',
    customRender: ({ record }: any) => {
      console.log(record, 'record')
      let res = ''
      if (record.status == 1) {
        res = '副研究员'
      } else if (record.status == 2) {
        res = '助理研究员'
      } else if (record.status == 3) {
        res = '研究员'
      } else if (record.status == 4) {
        res = '教授'
      } else if (record.status == 5) {
        res = '高级工程师'
      } else if (record.status == 6) {
        res = '教授级高工'
      } else if (record.status == 7) {
        res = '工程师'
      } else if (record.status == 8) {
        res = '农艺师'
      } else if (record.status == 9) {
        res = '"千人计划"特聘专家'
      } else if (record.status == 10) {
        res = '副教授'
      } else if (record.status == 11) {
        res = '助理工程师'
      } else if (record.status == 12) {
        res = '高级农艺师'
      } else if (record.status == 13) {
        res = '环评工程师'
      }
      return res
    },
  },
  {
    title: '专家类别',
    resizable: true,
    dataIndex: 'zjlbName'
  },
  {
    title: '创建人',
    resizable: true,
    dataIndex: 'createByName'
  },
  {
    title: '登录账号',
    resizable: true,
    dataIndex: 'lxfsSj'
  },
  {
    title: '状态',
    dataIndex: 'status',
    resizable: true,
    customRender: ({ record }: any) => {
      console.log(record, 'record')
      let res = ''
      if (record.status == 10) {
        res = '启用'
      } else if (record.status == -10) {
        res = '停用'
      }
      return res
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '姓名',
    field: 'zjxm',
    component: 'Input'
  },
  {
    label: '工作单位',
    field: 'gzdw',
    component: 'Input'
  },
  {
    label: '专家类别',
    field: 'zjlbName',
    component: 'Input'
  },
  {
    label: '创建人',
    field: 'createByName',
    component: 'Input'
  },
  {
    label: '工作单位所在区域',
    field: 'createByName',
    component: 'Select',

  },
];

export const formSchema: FormSchema[] = [
  // TODO 主键隐藏字段，目前写死为ID
  { label: '', field: 'id', component: 'Input', show: false },
  {
    label: '姓名',
    field: 'zjxm',
    required: true,
    component: 'Input',
  },
  {
    label: '身份证号',
    field: 'sfzh',
    component: 'Input',
    dynamicRules: () => {
      return [{ pattern: /^\d{15}|(\d{17}(\d|x|X))$/, message: '身份证格式有误', required: false }];
    },
  },
  {
    label: '出生年月',
    field: 'csny',
    component: 'DatePicker',
    required: true,
    componentProps: {
      //日期格式化，页面上显示的值
      format: 'YYYY-MM-DD',
      //返回值格式化（绑定值的格式）
      valueFormat: 'YYYY-MM-DD',
    }
  },
  {
    label: '性别',
    field: 'sex',
    component: 'RadioGroup',
    defaultValue: '1',
    componentProps: {
      options: [
        { label: '男', value: '1' },
        { label: '女', value: '0' },
      ],
    },
  },
  {
    label: '民族',
    field: 'mz',
    component: 'Input',
  },
  {
    label: '照片',
    field: 'photo',
    component: 'Input',
  },
  {
    label: '工作单位所在区域',
    field: 'gzdwszqyName',
    component: 'Input',
  },
  {
    label: '健康状况',
    field: 'jkzk',
    component: 'Input',
  },
  {
    label: '学历',
    field: 'xl',
    component: 'ApiSelect',
    componentProps: {
      api: dict,
      params: { key: 'zjgl-xl' }, // 行政区划编码
      labelField: 'text',
      valueField: 'value',
    }

  },
  {
    label: '技术职称',
    field: 'jszc',
    component: 'ApiSelect',
    componentProps: {
      api: dict,
      params: { key: 'zjgl-jszc' }, // 行政区划编码
      labelField: 'text',
      valueField: 'value',
    }

  },
  {
    label: '评聘时间',
    field: 'ppsj',
    component: 'DatePicker',
    componentProps: {
      //日期格式化，页面上显示的值
      format: 'YYYY-MM-DD',
      //返回值格式化（绑定值的格式）
      valueFormat: 'YYYY-MM-DD',
    }
  },
  {
    label: '创建人',
    field: 'createByName',
    component: 'Input',
  },

  {
    label: '单位地址',
    field: 'dwdz',
    component: 'Input',
  },
  {
    label: '单位电话',
    field: 'dwdh',
    component: 'Input',
    dynamicRules: () => {
      return [{ pattern: /^0\d{2,3}-?\d{7,8}$/, message: '电话格式有误', required: true }];
    },
  },
  {
    label: '联系手机',
    field: 'lxfsSj',
    component: 'Input',
    dynamicRules: () => {
      return [{ pattern: /^1[3,4,5,6,7,8,9][0-9]{9}$/, message: '手机格式有误', required: true }];
    },
  },
  {
    label: '电子邮箱',
    field: 'lxfsEmail',
    component: 'Input',
    required: true,
    dynamicRules: () => {
      return [{ pattern: /^\w+([-\.]\w+)*@\w+([\.-]\w+)*\.\w{2,4}$/, message: '电子邮箱格式有误', required: false }];
    },
  },
  {
    label: '职业资格证书名称',
    field: 'zyzgzsmc',
    component: 'Input',
  },
  {
    label: '职业资格证书编号',
    field: 'zyzgzsbh',
    component: 'Input',
  },
  {
    label: '专业类别',
    field: 'zylb',
    component: 'Input',
  },
  {
    label: '状态',
    field: 'status',
    component: 'RadioGroup',
    defaultValue: '10',
    componentProps: {
      options: [
        { label: '启用', value: '10' },
        { label: '停用', value: '-10' },
      ],
    },
  },
  {
    label: '行业领域编码',
    field: 'hylyCode',
    component: 'Input',
  },
  {
    label: '行业领域名称',
    field: 'hylyName',
    component: 'Input',
  },
  {
    label: '行业领域其它',
    field: 'hylyQt',
    component: 'Input',
  },
  {
    label: '专业领域编码',
    field: 'zylyCode',
    component: 'Input',
  },
  {
    label: '专业领域名称',
    field: 'zylyName',
    component: 'Input',
  },
  {
    label: '专业领域其它',
    field: 'zylyQt',
    component: 'Input',
  },
  {
    label: '专家类别编码',
    field: 'zjlbCode',
    component: 'Input',
  },
  {
    label: '专家类别名称',
    field: 'zjlbName',
    component: 'Input',
  },
  {
    label: '专家类别其它',
    field: 'zjlbQt',
    component: 'Input',
  },
  {
    label: '个人简历',
    field: 'grjl',
    component: 'Input',
  },

  {
    label: '附件名称',
    field: 'fileName',
    component: 'Input',
  },
  {
    label: '附件地址',
    field: 'filePath',
    component: 'Input',
  },
  {
    label: '专家级别',
    field: 'level',
    component: 'ApiSelect',
    componentProps: {
      api: dict,
      params: { key: 'zjgl-zjjb' }, // 行政区划编码
      labelField: 'text',
      valueField: 'value',
    }
  },
  {
    label: '备注',
    field: 'bz',
    component: 'Input',
  },
];
