import { ref } from 'vue';
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { dict, decryptData } from '/@/api/common/api'


// 获取专业方向字典
const speciality = ref<any>([])
const lxdh = ref('1')
export const useSpeciality = () => {
  // 获取行业分类
  const getspeciality = async () => {
    speciality.value = await dict({ key: 'zjgl-zyfx' });
  };
  getspeciality();
  return { data: speciality };
};
// getspeciality()
export const columns: BasicColumn[] = [
  {
    title: '姓名',
    resizable: true,
    width: 100,
    dataIndex: 'zjxm'
  },
  {
    title: '姓别',
    resizable: true,
    width: 80,
    dataIndex: 'sex'
  },
  {
    title: '单位',
    resizable: true,
    width: 130,
    dataIndex: 'unit'
  },
  {
    title: '职称',
    dataIndex: 'zc',
    resizable: true,
    width: 180,
  },
  {
    title: '专家方向',
    resizable: true,
    width: 240,
    dataIndex: 'zyfxName'
  },
  // {
  //   title: '联系方式',
  //   resizable: true,
  //   width: 120,
  //   dataIndex: 'phone',
  //   customRender: ({ record }: any) => {
  //     const rule = /^[0-9]+$/.test(record.phone);
  //     if (!rule && record.phone) {
  //       const regex = /[*]/.test(record.phone);

  //       if (!regex) {
  //         decryptData({ str: record.phone }).then(res => {
  //           phone.value = res.replace(res.substring(3, 7), '****')
  //           return phone.value
  //         })
  //       }

  //     }

  //     return phone.value
  //   },
  // },
  {
    title: '登录账号',
    resizable: true,
    width: 180,
    dataIndex: 'zjzh'
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 90,
    resizable: true,
    // customRender: ({ record }: any) => {
    //   if (record.status == 1) {
    //     return true
    //   } else if (record.status == 2) {
    //     return false
    //   }

    // },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '姓名',
    field: 'zjxm',
    colProps: { span: 6 },
    component: 'Input'
  },
  {
    label: '状态',
    field: 'status',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        { label: '启用', value: '1', },
        { label: '停用', value: '2' },
      ],
    },
  },
  {
    label: '专业方向',
    field: 'zyfxCodes',
    component: 'CheckboxGroup',
    colProps: { span: 20 },
    slot: 'zyfx'
  },


];

export const formSchema: FormSchema[] = [
  // TODO 主键隐藏字段，目前写死为ID
  { label: '', field: 'id', component: 'Input', show: false },
  { label: '', field: 'showFooter', component: 'Input', show: false }, //用来查看的时候禁用的
  {
    label: '姓名',
    field: 'zjxm',
    required: true,
    component: 'Input',
    dynamicDisabled: ({ values }) => {
      return values.showFooter;
    },
  },
  {
    label: '性别',
    field: 'sex',
    component: 'RadioGroup',
    defaultValue: '1',
    dynamicDisabled: ({ values }) => {
      return values.showFooter;
    },
    componentProps: {
      options: [
        { label: '男', value: '1' },
        { label: '女', value: '0' },
      ],
    },
  },
  {
    label: '单位',
    field: 'unit',
    required: true,
    dynamicDisabled: ({ values }) => {
      return values.showFooter;
    },
    component: 'Input',
  },
  {
    label: '职称',
    field: 'zc',
    required: true,
    dynamicDisabled: ({ values }) => {
      return values.showFooter;
    },
    component: 'Input',
  },
  {
    label: '身份证号',
    field: 'sfzh',
    dynamicDisabled: ({ values }) => {
      return values.showFooter;
    },
    required: true,
    component: 'Input',
    dynamicRules: ({ values }) => {

      return [{ pattern: /^\d{18}|(\d{18}(\d|x|X))$/, message: !values.showFooter ? '' : '身份证格式有误', required: true }];
    },
  },
  {
    label: '联系手机',
    field: 'lxdh',
    dynamicDisabled: ({ values }) => {
      return values.showFooter;
    },
    component: 'Input',
    required: true,
    dynamicRules: ({ values }) => {
      return [{ pattern: /^1[3,4,5,6,7,8,9][0-9]{9}$/, message: !values.showFooter ? '' : '手机格式有误', required: true }];
    },
  },
  // {
  //   label: '开户银行',
  //   field: 'khhmc',
  //   dynamicDisabled: ({ values }) => {
  //     return values.showFooter;
  //   },
  //   component: 'Input',
  // },
  // {
  //   label: '银行账户',
  //   field: 'yhzh',
  //   dynamicDisabled: ({ values }) => {
  //     return values.showFooter;
  //   },
  //   component: 'InputNumber',
  //   dynamicRules: ({ values }) => {
  //     return [{ pattern: /^([1-9]{1})(\d{15}|\d{16}|\d{18})$/, message: !values.showFooter ? '' : '银行账户格式有误', required: false }];
  //   },

  // },
  {
    label: '邮箱',
    field: 'email',
    dynamicDisabled: ({ values }) => {
      return values.showFooter;
    },
    component: 'Input',
    dynamicRules: () => {
      return [{ pattern: /^\w+([-\.]\w+)*@\w+([\.-]\w+)*\.\w{2,4}$/, message: '电子邮箱格式有误', required: false }];
    },
  },
  {
    label: '状态',
    field: 'status',
    dynamicDisabled: ({ values }) => {
      return values.showFooter;
    },
    component: 'RadioGroup',
    defaultValue: '1',
    componentProps: {
      options: [
        { label: '启用', value: '1' },
        { label: '停用', value: '2' },
      ],
    },
  },
  {
    label: '专业方向',
    field: 'zyfxCode',
    dynamicDisabled: ({ values }) => {
      return values.showFooter;
    },
    component: 'CheckboxGroup',
    required: true,
    componentProps: {
      options: useSpeciality().data
    }

  },
  {
    label: '备注',
    field: 'bz',
    dynamicDisabled: ({ values }) => {
      return values.showFooter;
    },
    component: 'InputTextArea',
    componentProps: {
      autoSize: {
        //最小显示行数
        minRows: 4,

      },
    }

  },



];

// 专家抽取
export const searchcqFormSchema: FormSchema[] = [
  {
    label: '地块编号',
    field: 'wrdkbm',
    colProps: { span: 6 },
    component: 'Input'
  },
  {
    label: '所处阶段',
    field: 'scjdbm',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        { label: '地块调查', value: 'S2' },
        { label: '风险评估', value: 'S3' },
        { label: '风险管控', value: 'S4' },
        { label: '修复', value: 'S5' },
        { label: '风险管控及修复', value: 'S10' },
        { label: '风险管控及修复效果评估', value: 'S6' },
      ],
    },
  },
  {
    label: '专业方向',
    field: 'cqzyfx',
    component: 'CheckboxGroup',
    colProps: { span: 12 },
    slot: 'zyfx'
  },


];
export const Cqcolumns: BasicColumn[] = [
  {
    title: '地块编号',
    resizable: true,
    width: 220,
    dataIndex: 'wrdkbm'
  },
  {
    title: '地块名称',
    resizable: true,
    width: 220,
    dataIndex: 'wrdkmc'
  },
  {
    title: '所处阶段',
    resizable: true,
    width: 120,
    dataIndex: 'scjdbm',
    customRender: ({ record }: any) => {
      let res = ''
      if (record.scjdbm == 'S2') {
        res = '地块调查'
      } else if (record.scjdbm == 'S3') {
        res = '风险评估'
      } else if (record.scjdbm == 'S4') {
        res = '风险管控'
      } else if (record.scjdbm == 'S5') {
        res = '修复'
      } else if (record.scjdbm == 'S6') {
        res = '风险管控及修复效果评估'
      } else if (record.scjdbm == 'S10') {
        res = '风险管控及修复'
      }
      return res
    }
  },
  {
    title: '抽取专业方向',
    dataIndex: 'cqzyfxName',
    width: 220,
  },
  {
    title: '抽取人员',
    resizable: true,
    width: 120,
    dataIndex: 'createBy'
  },
  {
    title: '抽取时间',
    resizable: true,
    width: 220,
    dataIndex: 'createTsamp'
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 80,
    resizable: true,
    customRender: ({ record }: any) => {
      let res = ''
      if (record.status == '1') {
        res = '抽取中'
      } else if (record.status == '2') {
        res = '抽取完成'
      }
      return res
    },
  },
];

// 随机抽取
export const sjcolumns: BasicColumn[] = [
  {
    title: '姓名',
    resizable: true,
    dataIndex: 'zjxm'
  },
  {
    title: '姓别',
    resizable: true,
    dataIndex: 'sex'
  },
  {
    title: '单位',
    resizable: true,
    dataIndex: 'unit'
  },
  {
    title: '职称',
    dataIndex: 'zc',
  },
  {
    title: '专家方向',
    resizable: true,
    width: 220,
    dataIndex: 'zyfxName'
  },
  {
    title: '联系方式',
    resizable: true,
    dataIndex: 'lxdh'
  },
  {
    title: '登录账号',
    resizable: true,
    dataIndex: 'zjzh'
  },
  {
    title: '操作',
    resizable: true,
    dataIndex: 'opera'
  },
];

// 添加随机抽取的搜索
export const searchsjFormSchema: FormSchema[] = [
  // TODO 主键隐藏字段，目前写死为ID
  { label: '', field: 'id', component: 'Input', show: false },
  {
    label: '姓名',
    field: 'zjxm',
    colProps: { span: 6 },
    component: 'Input',
  },

  {
    label: '专业方向',
    field: 'zyfxCode',
    component: 'CheckboxGroup',
    colProps: { span: 24 },
    componentProps: {
      options: useSpeciality().data
    }

  },

];

