import React from 'react';
import { Input, InputNumber } from 'antd';
import { UdcSelect, UploadEL } from '@components';
import { enums } from '@utils';
const { viewMode } = enums;

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

  // 绩效评分：每行的最大分数规则。索引与行号一一对应。
  const rules = [30, 10, 10, 15, 10, 5, 5, 5, 5, 5, 2, 2, 2, 2, 2];

  const handleScoreChange = (value, part, index, column) => {
    dispatch({
      type: `${domain}/updateCell`,
      payload: { value, part, index, column },
    });
  };

  const renderInputColumns = (record, text, part, index, column) => {
    return (
      <InputNumber
        value={text}
        min={0}
        max={rules[record.lineNo - 1]}
        onChange={(value) => handleScoreChange(value, part, index, column)}
      />
    );
  };

  const renderTextAreaColumns = (text, part, index, column) => {
    return (
      <TextArea
        rows={1}
        value={text}
        onChange={(e) => handleScoreChange(e.target.value, part, index, column)}
      />
    );
  };

  const renderUploadColumns = (record, part, index, column) => {
    return <UploadEL
      size={'small'}
      api={'/performance/sfs-client/sfs/token'}
      dataKey={`${record.performanceId}-${record.lineNo}`}
      listType={'text'} disabled={mode !== viewMode.CREATE} />;
  };

  const basicInfo = [{
    title: '供应商编号',
    dataIndex: 'suppCode',
  },  {
    title: '评估月份',
    dataIndex: 'yearMonth',
  }, {
    title: '当前绩差',
    dataIndex: 'lqsName',
  },{
    title: '供应商名称',
    dataIndex: 'suppName',
  }, {
    title: '评分状态',
    dataIndex: 'statusName',
  }, {
    title: '上月评级',
    dataIndex: 'pre1Name',
  }, {
    title: '供应商性质',
    dataIndex: 'gysxz',
    tag: <UdcSelect domain="SUPP" code="GYSXZ" mode="multiple" />,
  }, {
    title: '供应品类',
    dataIndex: 'gysylsx',
    tag: <UdcSelect domain="SUPP" code="GYSYLSX" mode="multiple" />,
  },{
    title: '上上月评级',
    dataIndex: 'pre2Name',
  },];

  const rectifyInfo = [{
    title: '整改要求',
    dataIndex: 'rectificationMemo',
    tag: <TextArea rows={4} placeholder="连续两次评级为D 要求填写整改意见" />,
    options: {
      rules: [{
        min: 0,
        max: 600,
        message: '至多输入600个字符',
      },
      ],
    },
  }, {
    title: '供应商反馈',
    dataIndex: 'ouAnswer',
    tag: <TextArea rows={4} placeholder="供应商填写整改措施" />, options: {
      rules: [{
        min: 0,
        max: 300,
        message: '至多输入300个字符',
      },
      ],
    },
    formItemLayout: {
      colon: false,
      labelCol: {
        span: 6,
      },
      wrapperCol: {
        span: 14,
      },
      style: {},
    },
  }];

  const qualityInfo = [{
    title: `品质表现(共50分)`,
    dataIndex: 'scoreItem',
    width: '18%',
  }, {
    title: `得分数${record.total}(分)`,
    dataIndex: 'score',
    width: '12%',
    render: (text, record, index) => renderInputColumns(record, text, 'scoreQuality', index, 'score'),
  }, {
    title: '备注',
    dataIndex: 'memo',
    className: 'alignLeft',
    width: '35%',
    render: (text, record, index) => renderTextAreaColumns(text, 'scoreQuality', index, 'memo'),
    options: {
      rules: [{
        max: 500,
        message: '至多输入500个字符',
      },
      ],
    },
  }, {
    title: '附件',
    dataIndex: 'file',
    width: '35%',
    className: 'alignLeft',
    render: (text, record, index) => renderUploadColumns(record, 'scoreQuality', index, 'file'),
  }];
  const deliveryInfo = [{
    title: `交付保证(共30分)`,
    dataIndex: 'scoreItem',
    width: '18%',
  }, {
    title: `得分数${record.total}(分)`,
    dataIndex: 'score',
    width: '12%',
    render: (text, record, index) => renderInputColumns(record, text, 'scoreDelivery', index, 'score'),
  }, {
    title: '备注',
    dataIndex: 'memo',
    className: 'alignLeft',
    width: '35%',
    render: (text, record, index) => renderTextAreaColumns(text, 'scoreDelivery', index, 'memo'),
    options: {
      rules: [{
        max: 500,
        message: '至多输入500个字符',
      },
      ],
    },
  }, {
    title: '附件',
    dataIndex: 'file',
    width: '35%',
    className: 'alignLeft',
    render: (text, record, index) => renderUploadColumns(record, 'scoreDelivery', index, 'file'),
  }];
  const serviceInfo = [{
    title: `服务承诺(共20分)`,
    dataIndex: 'scoreItem',
    width: '18%',
  }, {
    title: `得分数${record.total}(分)`,
    dataIndex: 'score',
    width: '12%',
    render: (text, record, index) => renderInputColumns(record, text, 'scoreService', index, 'score'),
  }, {
    title: '备注',
    dataIndex: 'memo',
    className: 'alignLeft',
    width: '35%',
    render: (text, record, index) => renderTextAreaColumns(text, 'scoreService', index, 'memo'),
    options: {
      rules: [{
        max: 500,
        message: '至多输入500个字符',
      },
      ],
    },
  }, {
    title: '附件',
    dataIndex: 'file',
    width: '35%',
    className: 'alignLeft',
    render: (text, record, index) => renderUploadColumns(record, 'scoreService', index, 'file'),
  }];
  const additionInfo = [{
    title: `附加分(共10分)`,
    dataIndex: 'scoreItem',
    width: '18%',
  }, {
    title: `得分数${record.total}(分)`,
    dataIndex: 'score',
    width: '12%',
    render: (text, record, index) => renderInputColumns(record, text, 'scoreAddition', index, 'score'),
  }, {
    title: '备注',
    dataIndex: 'memo',
    className: 'alignLeft',
    width: '35%',
    render: (text, record, index) => renderTextAreaColumns(text, 'scoreAddition', index, 'memo'),
    options: {
      rules: [{
        max: 500,
        message: '至多输入500个字符',
      },
      ],
    },
  }, {
    title: '附件',
    dataIndex: 'file',
    width: '35%',
    className: 'alignLeft',
    render: (text, record, index) => renderUploadColumns(record, 'scoreAddition', index, 'file'),
  }];

  const adjust = [{
    title: '调整得分',
    dataIndex: 'finalScore',
    tag: <InputNumber min={0} max={110} />,
    formItemLayout: {
      colon: false,
      labelCol: {
        span: 3,
      },
      wrapperCol: {
        span: 2,
      },
      style: {},
    },
  }, {
    title: '调整理由',
    dataIndex: 'opinion1',
    tag: <TextArea rows={2} />,
    options: {
      rules: [{
        min: 0,
        max: 40,
        message: '至多输入40个字符',
      },
      ],
    },
    formItemLayout: {
      colon: false,
      labelCol: {
        span: 3,
      },
      wrapperCol: {
        span: 20,
      },
      style: {},
    },
  }];

  const attachmentInfo = [{
    title: '绩效评分附件',
    dataIndex: 'files',
  }];

  return {
    basicInfo,
    rectifyInfo,
    qualityInfo,
    deliveryInfo,
    serviceInfo,
    additionInfo,
    adjust,
    attachmentInfo,
  };
};

export default localCfg;
