import type { VxeGridProps, VxeColumnPropTypes } from 'vxe-table';
import XEUtils from 'xe-utils';

interface VxeColumn {
  type?: string;
  field?: string;
  title?: string;
  width?: number | string;
  minWidth?: number | string;
  maxWidth?: number | string;
  sortable?: boolean;
  formatter?: (value: any) => string;
  treeNode?: boolean;
  slots?: {};
  visible?: boolean;
  editRender?: {};
  align?: string;
  showOverflow?: boolean | string;
  fixed?: string;
  filters?: [] | {};
  filterMethod?: any;
  filterMethodTp?: string;
  filterRender?: any;
}

const textFilterRender: VxeColumnPropTypes.FilterRender = {
  name: 'VxeInput',
};

function textFilterMethod({ option, row, column }) {
  if (option.data) {
    return `${row[column.field]}`.indexOf(option.data) > -1;
  }
  return true;
}

export const complianceCol: VxeColumn[] = [
  { type: 'checkbox', visible: true, width: '50', showOverflow: false },
  {
    field: 'ind',
    title: '序号',
    sortable: true,
    width: '100',
    showOverflow: false,
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
  },
  {
    field: 'cgrpPath',
    title: '分组',
    sortable: true,
    visible: true,
    width: '10%',
    filters: [],
    filterMethodTp: 'check',
  },
  {
    field: 'item',
    title: '条目',
    width: '18%',
    sortable: true,
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  {
    field: 'content',
    title: '内容',
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  {
    field: 'caName',
    title: '控制项',
    width: '16%',
    type: 'html',
    visible: true,
    slots: { default: 'caName_default' },
    showOverflow: 'ellipsis',
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  { field: 'labelNames', title: '标签', width: '16%', type: 'html', visible: false, slots: { default: 'labels_default' } },
  { field: 'labels', title: '标签编码', visible: false, width: '0' },
  { field: 'id', title: 'id', visible: false },
  { field: 'actIds', title: 'actIds', visible: false },
  { field: 'fileId', title: 'fileId', visible: false },
  { field: 'filePath', title: 'filePath', visible: false, filters: [], filterMethodTp: 'check' },
  { field: 'fileName', title: '参考文件', visible: false, width: '16%', slots: { default: 'fileName_default' }, showOverflow: 'ellipsis' },
  { title: '操作', align: 'center', width: '15%', visible: true, fixed: 'right', slots: { default: 'operate' } },
];

export const innerCtlCol: VxeColumn[] = [
  { type: 'checkbox', visible: true, width: '40', showOverflow: false },
  {
    field: 'name',
    title: '内控要求名称',
    width: '20%',
    type: 'text',
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    
  },
  {
    field: 'createTime',
    title: '创建时间',
    width: '20%',
    visible: true,
    type: 'html',
  },
  { field: 'createUser', title: '创建人', visible: true },
  { title: '操作', width: '15%', visible: true, align: 'center', fixed: 'right', slots: { default: 'operate' } },
];

export const innerCtlOrderCol: VxeColumn[] = [
  { type: 'checkbox', visible: true, width: '50', showOverflow: false },
  {
    field: 'ind',
    title: '序号',
    sortable: true,
    width: '100',
    showOverflow: false,
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
  },
  {
    field: 'cgrpPath',
    title: '分组',
    sortable: true,
    visible: true,
    width: '10%',
    filters: [],
    filterMethodTp: 'check',
  },
  {
    field: 'item',
    title: '条目',
    width: '18%',
    sortable: true,
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  {
    field: 'content',
    title: '内容',
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  {
    field: 'caName',
    title: '控制项',
    width: '16%',
    type: 'html',
    visible: true,
    slots: { default: 'caName_default' },
    showOverflow: 'ellipsis',
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  { field: 'labelNames', title: '标签', width: '16%', type: 'html', visible: false, slots: { default: 'labels_default' } },
  { field: 'labels', title: '标签编码', visible: false, width: '0' },
  { field: 'id', title: 'id', visible: false },
  { field: 'actIds', title: 'actIds', visible: false },
  { field: 'fileId', title: 'fileId', visible: false },
  { field: 'filePath', title: 'filePath', visible: false, filters: [], filterMethodTp: 'check' },
  { field: 'fileName', title: '参考文件', visible: false, width: '16%', slots: { default: 'fileName_default' }, showOverflow: 'ellipsis' },
  { title: '操作', align: 'center', width: '15%', visible: true, fixed: 'right', slots: { default: 'operate' } },
];

export const problemCol: VxeColumn[] = [
  { type: 'checkbox', visible: true, width: '40', showOverflow: false },
  {
    field: 'pbItem',
    title: '问题项',
    width: '18%',
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  {
    field: 'pbExample',
    title: '问题示例',
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  {
    field: 'pbAdvise',
    title: '问题建议',
    visible: false,
    width: '15%',
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
  },
  {
    field: 'caName',
    title: '控制项',
    width: '15%',
    type: 'html',
    slots: { default: 'caName_default' },
    showOverflow: 'ellipsis',
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  { field: 'pbAnalysis', title: '问题分析', visible: false, editRender: { autofocus: '.vxe-input--inner' }, slots: { edit: 'text_edit' } },
  { field: 'pbNature', title: '问题性质', visible: false },
  { field: 'labelNames', title: '标签', type: 'html', width: '15%', visible: false, slots: { default: 'labels_default' } },
  { field: 'labels', title: '标签编码', visible: false },
  { field: 'actIds', title: 'actIds', visible: false },
  { field: 'id', title: 'id', visible: false },
  { field: 'filePath', title: 'filePath', visible: false },
  {
    field: 'fileName',
    title: '参考文件',
    visible: true,
    width: '20%',
    slots: { default: 'fileName_default' },
    showOverflow: 'ellipsis',
    filters: [],
    filterMethodTp: 'check',
  },
  { title: '操作', width: '15%', visible: true, align: 'center', fixed: 'right', slots: { default: 'operate' } },
];

export const checkMethodCol: VxeColumn[] = [
  { type: 'checkbox', visible: true, width: '40', showOverflow: false },
  {
    field: 'cgrpPath',
    title: '分组',
    sortable: true,
    visible: true,
    width: '10%',
  },
  {
    field: 'item',
    title: '合规条目',
    sortable: true,
    visible: true,
    type: 'html',
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  {
    field: 'content',
    title: '检查内容',
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    sortable: true,
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  {
    field: 'viewSystem',
    title: '查看系统',
    visible: false,
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    sortable: true,
  },
  {
    field: 'viewRecord',
    title: '查看记录',
    visible: false,
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    sortable: true,
  },
  {
    field: 'viewRule',
    title: '查看制度',
    visible: false,
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    sortable: true,
  },
  {
    field: 'interUser',
    title: '查看用户',
    visible: false,
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    sortable: true,
  },

  {
    field: 'caName',
    title: '控制项',
    width: '10%',
    visible: true,
    type: 'html',
    slots: { default: 'caName_default' },
    showOverflow: 'ellipsis',
    filters: [],
    filterMethodTp: 'check',
  },
  { field: 'labelNames', title: '标签', width: '10%', type: 'html', visible: false, slots: { default: 'labels_default' } },
  { field: 'labels', title: '标签编码', visible: false },
  { field: 'des', title: '备注', visible: false, editRender: { autofocus: '.vxe-input--inner' }, slots: { edit: 'text_edit' } },
  { field: 'actIds', title: 'actIds', visible: false },
  { field: 'id', title: 'id', visible: false },
  {
    field: 'fileName',
    title: '参考文件',
    visible: true,
    width: '10%',
    showOverflow: 'ellipsis',
    slots: { default: 'fileName_default' },
    filters: [],
    filterMethodTp: 'check',
  },
  { title: '操作', width: '15%', visible: true, align: 'center', fixed: 'right', slots: { default: 'operate' } },
];

export const riskEventCol: VxeColumn[] = [
  { type: 'checkbox', visible: true, width: '40', showOverflow: false },
  {
    field: 'riskEventName',
    title: '风险事件',
    width: '25%',
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  {
    field: 'riskEventDesc',
    title: '风险事件描述',
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  { field: 'scenarioName', title: '风险分类', type: 'html', width: '15%', filters: [], filterMethodTp: 'check' },
  {
    field: 'fileName',
    title: '参考文件',
    visible: true,
    width: '10%',
    showOverflow: 'ellipsis',
    slots: { default: 'fileName_default' },
    filters: [],
    filterMethodTp: 'check',
  },
  { field: 'labelNames', title: '标签', type: 'html', visible: false, width: '15%', slots: { default: 'labels_default' } },
  { field: 'labels', title: '标签编码', visible: false },
  { field: 'id', title: 'id', visible: false },
  { field: 'scid', title: 'scid', visible: false },
  { title: '操作', width: '15%', visible: true, align: 'center', fixed: 'right', slots: { default: 'operate' } },
];

export const practiceCol: VxeColumn[] = [
  { type: 'checkbox', visible: true, width: '40', showOverflow: false },
  {
    field: 'content',
    title: '行业实践',
    width: '30%',
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  {
    field: 'exeRule',
    title: '执行规则',
    type: 'html',
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  { field: 'labelNames', title: '标签', visible: false, width: '20%', slots: { default: 'labels_default' } },
  { field: 'labels', title: '标签编码', visible: false },
  { field: 'id', title: 'id', visible: false },
  { field: 'fileId', title: 'fileId', visible: false },
  { field: 'filePath', title: 'filePath', visible: false },
  { field: 'fileName', title: '参考文件', visible: false, width: '18%', slots: { default: 'fileName_default' }, showOverflow: 'ellipsis' },
  { title: '操作', width: '17%', visible: true, align: 'center', fixed: 'right', slots: { default: 'operate' } },
];

export const riskScenaCol: VxeColumn[] = [
  { type: 'checkbox', visible: true, width: '40', showOverflow: false },
  {
    field: 'scenarioName',
    treeNode: true,
    title: '分类名称',
    width: '40%',
    sortable: true,
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  {
    field: 'scenarioDesc',
    title: '分类描述',
    width: '35%',
    sortable: true,
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  { field: 'id', title: 'id', visible: false },
  { title: '操作', width: '22%', visible: true, align: 'center', fixed: 'right', slots: { default: 'operate' } },
];

export const actCol: VxeColumn[] = [
  { type: 'checkbox', visible: true, width: '40', showOverflow: false },
  {
    field: 'caName',
    title: '控制项名称',
    width: '20%',
    //sortable: true,
    //editRender: { autofocus: '.vxe-input--inner' },
    slots: { default: 'caName_default' },
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  {
    field: 'caDesc',
    title: '说明',
    sortable: false,
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  { field: 'domainName', title: '所属领域', width: '20%', type: 'html', sortable: true },
  { field: 'labelNames', title: '标签', visible: false, width: '20%', type: 'html', slots: { default: 'labels_default' } },
  { field: 'labels', title: '标签编码', visible: false },
  { field: 'id', title: 'id', visible: false },
  { title: '操作', width: '15%', visible: true, align: 'center', fixed: 'right', slots: { default: 'operate' } },
];

export const labelCol: VxeColumn[] = [
  { type: 'checkbox', visible: true, width: '40', showOverflow: false },
  { field: 'lableCode', title: '标签编码', width: '10%' },
  {
    field: 'lableName',
    title: '标签名称',
    width: '20%',
    editRender: { autofocus: '.vxe-input--inner' },
    slots: { edit: 'text_edit' },
    filters: [{ data: '' }],
    filterMethod: textFilterMethod,
    filterRender: textFilterRender,
    filterMethodTp: 'text',
  },
  { field: 'level1', title: '一级分类', width: '15%' },
  { field: 'level2', title: '二级分类', width: '15%' },
  { field: 'lableDesc', title: '说明', editRender: { autofocus: '.vxe-input--inner' }, slots: { edit: 'text_edit' } },
  { field: 'sclassifyCode', title: 'sclassifyCode', visible: false },
  { field: 'pclassifyCode', title: 'pclassifyCode', visible: false },
  { field: 'id', title: 'id', visible: false },
  { title: '操作', width: '17%', visible: true, align: 'center', fixed: 'right', slots: { default: 'operate' } },
];

//查询数据
export const srhCompliane: string[] = ['cgrpPath', 'fileName', 'fileTp', 'item', 'content', 'cgrp'];
export const srhInnerCtl: string[] = ['fileName', 'fileTp', 'labelNames', 'caName', 'strategy', 'claim'];
export const srhInnerOrder: string[] = ['fileName', 'execRule', 'ctrlDesc', 'caName'];
export const srhProblem: string[] = ['fileName', 'fileTp', 'pbItem', 'pbExample', 'pbAdvise', 'caName'];
export const srhCheckMethod: string[] = ['cgrpPath', 'fileName', 'item', 'content', 'caName'];
export const srhRiskEvent: string[] = ['scenarioName', 'riskEventName', 'riskEventDesc'];
export const srhPractice: string[] = ['fileName', 'content', 'exeRule'];
export const srhRiskScena: string[] = ['scenarioName', 'scenarioDesc'];
export const srhAct: string[] = ['domainName', 'caName', 'labelNames', 'caDesc'];
export const srhLabel: string[] = ['lableCode', 'lableName', 'lableDesc', 'level1', 'level2'];

export const srhCond = {
  1: srhCompliane,
  2: srhInnerCtl,
  3: srhInnerOrder,
  4: srhProblem,
  5: srhCheckMethod,
  6: srhRiskEvent,
  7: srhPractice,
  8: srhRiskScena,
  9: srhAct,
  10: srhLabel,
};

export const auditCols = {
  1: complianceCol,
  2: innerCtlCol,
  3: innerCtlOrderCol,
  4: problemCol,
  5: checkMethodCol,
  6: riskEventCol,
  7: practiceCol,
  8: riskScenaCol,
  9: actCol,
  10: labelCol,
};

const checkboxFilterRender: VxeColumnPropTypes.FilterRender = {
  name: 'VxeInput',
};
