import React from 'react';
import { Input, DatePicker } from 'antd';
import { UdcSelect, SuggestSelect, } from '@components';
import { OrgPicker } from '@bizComponents';

const localCfg = (record, mode, dispatch, loading, ) => {
  const { TextArea } = Input;
  const domain = 'edDetail';

  const handleChange = (key, index, newValue) => {
    if (newValue) {
      dispatch({ type: `${domain}/updateEmp`, payload: { index, id: newValue } });
    } else {
      dispatch({ type: `${domain}/updateNullCell`, payload: { index } });
    }
  };

  const basicInfo = [
    {
      title: '报告单号',
      dataIndex: 'reportCode',
      tag: <Input disabled={true} />,
    },
    {
      title: '报告单状态',
      dataIndex: 'reportStatus',
      tag: <UdcSelect domain="SRM" code="8D_STATUS" disabled={true} />,
    },
    {
      title: '审批状态',
      dataIndex: 'approveStatus',
      tag: <UdcSelect domain="SRM" code="APPROVE_STATUS" disabled={true} />,
    },
    {
      title: '责任区分',
      dataIndex: 'dutyType',
      tag: <UdcSelect domain="SRM" code="DUTY_TYPE" />,
      options: {
        rules: [
          {
            required: true,
            message: '必填',
          },
        ],
      },
    }, {
      title: '责任部门(内部)',
      dataIndex: 'org',
      tag: <OrgPicker />,
    }, {
      title: '责任单位(内部)',
      dataIndex: 'ouName',
      tag: <Input disabled={true} />,
    }, {
      title: '责任角色(内部)',
      dataIndex: 'dutyOuRole',
      tag: <SuggestSelect apiName="fieldBpmRoles" params={{ field: 'EO' }} />,
    }, {
      title: '责任单位(外部)',
      dataIndex: 'suppId',
      tag: <SuggestSelect apiName="supps" />,
    }, {
      title: '责任角色(外部)',
      dataIndex: 'dutySuppRole',
      tag: <SuggestSelect apiName="fieldBpmRoles" params={{ field: 'EP' }} />,
    }, {
      title: '报告日期',
      dataIndex: 'reportDate',
      tag: <DatePicker style={{ width: '100%' }} />,
    }, {
      title: '是否已生成索赔单',
      dataIndex: 'docNo',
      tag: <Input disabled={true} />,
    }, {
      title: '备注',
      dataIndex: 'remark',
      tag: <TextArea autosize={{ minRows: 2, maxRows: 6 }} />,
      options: {
        rules: [
          {
            max: 200,
            message: '请输入不超过200个字符',
          },
        ],
      },
    },
  ]

  const empInfo = [{
    title: '员工名称',
    dataIndex: 'empName',
    width: '20%',
    required: true,
    render: (value, row, index) => {
      return (
        <SuggestSelect apiName="emps"
          size="small"
          value={value}
          showCode={true}
          disabled={mode === 'view' || mode === 'approval' ? true : false}
          onChange={(e) => {
            handleChange('empId', index, e);
          }}
        />);
    },
  }, {
    title: '员工编号',
    dataIndex: 'empCode',
    width: '20%',
    render: (value, row, index) => {
      return (<Input disabled={true} size="small" value={value} />);
    },
  }, {
    title: '所属组织',
    dataIndex: 'orgName',
    width: '20%',
    render: (value, row, index) => {
      return (<Input disabled={true} size="small" value={value} />);
    },
  }, {
    title: '职位',
    dataIndex: 'position',
    width: '20%',
    render: (value, row, index) => {
      return (<Input disabled={true} size="small" value={value} />);
    },
  }, {
    title: '手机号码',
    dataIndex: 'mobile',
    width: '20%',
    render: (value, row, index) => {
      return (<Input disabled={true} size="small" value={value} />);
    },
  },]

  const flowInfo = [
    {
      title: '选择长期措施',
      dataIndex: 'rootPolicy',
      tag: <TextArea autosize={{ minRows: 2, maxRows: 6 }} />,
      options: {
        rules: [
          {
            max: 500,
            message: '请输入不超过500个字符',
          },
        ],
      },
    }, {
      title: '执行长期措施',
      dataIndex: 'rootPolicyResult',
      tag: <TextArea autosize={{ minRows: 2, maxRows: 6 }} />,
      options: {
        rules: [
          {
            max: 500,
            message: '请输入不超过500个字符',
          },
        ],
      },
    }, {
      title: '预防问题重复出现措施',
      dataIndex: 'preventionMeasure',
      tag: <TextArea autosize={{ minRows: 2, maxRows: 6 }} />,
      options: {
        rules: [
          {
            max: 500,
            message: '请输入不超过500个字符',
          },
        ],
      },
    },
  ];

  const problemDesc = [{
    title: '问题描述',
    dataIndex: 'problemDesc',
    tag: <TextArea autosize={{ minRows: 2, maxRows: 6 }} />,
    options: {
      rules: [
        {
          max: 500,
          message: '请输入不超过500个字符',
        },
        {
          required: true,
          whitespace: true,
          message: '必填',
        },
      ],
    },
  }];

  const tempPolicy = [{
    title: '短期临时措施',
    dataIndex: 'tempPolicy',
    tag: <TextArea autosize={{ minRows: 2, maxRows: 6 }} />,
    options: {
      rules: [
        {
          max: 500,
          message: '请输入不超过500个字符',
        },
      ],
    },
  }];

  const rootCause = [{
    title: '定义和核实原因',
    dataIndex: 'rootCause',
    tag: <TextArea autosize={{ minRows: 2, maxRows: 6 }} />,
    options: {
      rules: [
        {
          max: 500,
          message: '请输入不超过500个字符',
        },
      ],
    },
  }];

  const problemDescUpload = [{
    title: '附件上传',
    dataIndex: 'upload',
  }];

  const tempPolicyUpload = [{
    title: '附件上传',
    dataIndex: 'upload',
  }];

  const rootCauseUpload = [{
    title: '附件上传',
    dataIndex: 'upload',
  }];

  return {
    basicInfo,
    empInfo,
    flowInfo,
    problemDesc,
    tempPolicy,
    rootCause,
    problemDescUpload,
    tempPolicyUpload,
    rootCauseUpload,
  };
};

export default localCfg;
