import React from 'react';
import { connect } from 'dva';
import { Card, Checkbox, DatePicker, Input, InputNumber, message } from 'antd';
import { EditableDataTable, FormEL, UdcSelect, UploadEL,SuggestSelect } from '../../../components';
import { dataUtils, formUtils } from '../../../utils';
import { Toolbar } from '../../components';
import styles from './index.less';
import moment from 'moment';

const localCfg = (record, mode, dispatch, loading, supplierDetail, ) => {
  const { TextArea } = Input;
  const domain = 'supplierDetail';
  const CheckboxGroup = Checkbox.Group;
  const viewFlag = true;
  const readOnly = false;

  const disabledDate = (current) => current && current > moment().endOf('day');

  const handleChange = (key, index, newValue) => {
    dispatch({ type: `${domain}/updateCell`, payload: { key, index, value: newValue } });
  };

  const handleAddrChange = (key, index, newValue) => {
    dispatch({ type: `${domain}/updateAddrCell`, payload: { key, index, value: newValue } });
  };

  const suppInfo = [{
    title: '供应商编号',
    dataIndex: 'suppCode',
    options: {
    },
    tag: <Input disabled={true} />,
  }, {
    title: '供应商名称',
    dataIndex: 'suppName',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
        {
          max: 200,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input />,
  }, {
    title: '供应商简称',
    dataIndex: 'suppAbbr',
    options: {
      rules: [
        {
          max: 100,
          message: '请输入不超过100个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly} />,
  }, {
    title: '供货区域',
    dataIndex: 'region',
    options: {

      rules: [
        {
          required: true,
          message: '必填',
        }
      ]
    },
    tag: <SuggestSelect apiName="regions" mode="multiple" />,
  }, {
    title: '供应商状态',
    dataIndex: 'suppStatus',
    options: {

    },
    tag: <UdcSelect domain="SUPP" code="SUPP_STATUS" disabled={true} />,
  }, {
    title: '注册地(城市)',
    dataIndex: 'registerCity',
    tag: <UdcSelect domain="EDP" code="CITY" disabled={readOnly}/>,
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
      ],
    },
  }, {
    title: '注册地址',
    dataIndex: 'registerAddress',
    options: {
      rules: [
        {
          max: 100,
          message: '请输入不超过100个字符',
        },
        {
          required: true,
          message: '必填',
        },
      ],
    },
    tag: <Input disabled={readOnly} />,
  }, {
    title: '创立日期',
    dataIndex: 'registerDate',
    tag: <DatePicker disabled={readOnly}
      disabledDate={disabledDate}
      style={{ width: '100%' }} />,
  }, {
    title: '公司电话',
    dataIndex: 'suppTel',
    options: {

      rules: [
        {
          required: true,
          message: '必填',
        },
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ]
    },
    tag: <Input disabled={readOnly} />,
  }, {
    title: '电子邮箱',
    dataIndex: 'email',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
        {
          type: 'email',
          message: '请输入邮箱',
        },
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly} />,
  }, {
    title: '传真号码',
    dataIndex: 'suppFax',
    tag: <Input disabled={readOnly} />,
    options: {
      rules: [
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
  }, {
    title: '联系地址',
    dataIndex: 'contactAddr',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
        {
          max: 100,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly} />,
  }, {
    title: '官方网站',
    dataIndex: 'webaddress',
    options: {
      rules: [
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],

    },
    tag: <Input disabled={readOnly} />,
  }, {
    title: '法人代表',
    dataIndex: 'repr',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],

    },
    tag: <Input disabled={readOnly} />,
  }, {
    title: '法人电话',
    dataIndex: 'reprTel',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly} />,
  }, {
    title: '法人邮箱',
    dataIndex: 'reprMail',
    options: {
      rules: [
        {
          type: 'email',
          message: '请输入邮箱',
        },
        {
          required: true,
          message: '必填',
        },
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly} />,
  }, {
    title: '业务负责人',
    dataIndex: 'bussPic',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly} />,
  }, {
    title: '负责人电话',
    dataIndex: 'bussPicTel',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly} />,
  }, {
    title: '负责人邮箱',
    dataIndex: 'bussPicMail',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
        {
          type: 'email',
          message: '请输入邮箱',
        },
      ],
    },
    tag: <Input disabled={readOnly} />,
  },{
    title: '负责人职位',
    dataIndex: 'bussPicPosition',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
      ],
    },
    tag: <UdcSelect domain="SRM" code="POSITION" disabled={readOnly}/>,
  }, {
    title: '审批状态',
    dataIndex: 'approveStatus',
    options: {
    },
    tag: <UdcSelect domain="SUPP" code="SUPP_APPR_STATUS" disabled={true} mode="multiple" />,
  }, {
    title: '供应商性质',
    dataIndex: 'gysxz',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
      ],
    },
    tag: <UdcSelect domain="SUPP" code="GYSXZ" disabled={readOnly} mode="multiple" />,
  }, {
    title: '企业性质',
    dataIndex: 'gysxz1',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
      ],
    },
    tag: <UdcSelect domain="SUPP" code="GYSXZ1" disabled={readOnly} mode="multiple" />,
  }, {
    title: '纳税性质',
    dataIndex: 'gysxz2',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
      ],
    },
    tag: <UdcSelect domain="SUPP" code="GYSXZ2" disabled={readOnly} mode="multiple" />,
  }, {
    title: '注册资金',
    dataIndex: 'registerFund',
    options: {
      rules: [
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly} addonAfter="万元" />,
  }, {
    title: '公司总人数',
    dataIndex: 'compScale',
    options: {
      rules: [
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly} />,
  }, {
    title: '开户银行',
    dataIndex: 'suppBank',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
      ],
    },
    tag: <SuggestSelect apiName="bank" disabled={readOnly}/>,
  }, {
    title: '银行账户',
    dataIndex: 'bankAccount',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly} />,
  }, {
    title: '币种',
    dataIndex: 'currId',
    options: {
    },
    tag: <SuggestSelect apiName="currs" />,
  }, {
    title: '付款方式',
    dataIndex: 'payMethod',
    options: {
      rules: [
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <UdcSelect domain="SRM" code="PAY_METHOD" disabled={readOnly} />,
  }, {
    title: '付款条款',
    dataIndex: 'paymentTerm',
    options: {
      rules: [
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <UdcSelect domain="SRM" code="PAYMENT_TERM" disabled={readOnly} />,
  }, {
    title: '营业执照号',
    dataIndex: 'icRegisterNo',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly} />,
  // }, {
  //   title: '税务登记号',
  //   dataIndex: 'invTaxno',
  //   options: {
  //     rules: [
  //       {
  //         required: true,
  //         message: '必填',
  //       },
  //       {
  //         max: 40,
  //         message: '请输入不超过40个字符',
  //       },
  //     ],
  //   },
  //   tag: <Input disabled={readOnly} />,
  }, {
    title: '发票类型',
    dataIndex: 'invType',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
      ],
    },
    tag: <UdcSelect domain="SRM" code="INV_TYPE" disabled={readOnly} />,
  }, {
    title: '默认税率',
    dataIndex: 'taxRate',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
      ],
    },
    tag: <SuggestSelect apiName="tax"/>,
  }, {
    title: '供应渠道',
    dataIndex: 'gyqd',
    options: {},
    tag: <UdcSelect domain="SUPP" code="GYQD" mode="multiple" />,
  // }, {
  //   title: '引入原因',
  //   dataIndex: 'enroleDesc',
  //   options: {
  //     rules: [
  //       {
  //         max: 200,
  //         message: '请输入不超过200个字符',
  //       },
  //     ],
  //   },
  //   tag: <TextArea disabled={readOnly} autosize={{ minRows: 2, maxRows: 6 }} style={{ width: '100%' }} />,
  }];

  const introductionInfo = [{
    dataIndex: 'remark',
    options: {

    },
    colProps: {
      xs: 24,
      sm: 24,
      md: 24,
      xl: 24,
      lg: 24,
      style: {},
    },
    formItemLayout: {
      labelCol: {
        span: 0,
      },
      wrapperCol: {
        span: 24,
      },
    },
    tag: <TextArea rows={10} />,
  }];

  const contactInfo = [{
    title: '主要联系人',
    dataIndex: 'bussContact',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly}/>,
  }, {
    title: '用户手机',
    dataIndex: 'bussContactTel',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly}/>,
  }, {
    title: '用户邮箱',
    dataIndex: 'bussContactMail',
    options: {
      rules: [
        {
          required: true,
          message: '必填',
        },
        {
          type: 'email',
          message: '请输入邮箱',
        },
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly}/>,
  },];

  const addrTableProps = [{
    title: '联系人',
    dataIndex: 'contPerson',
    width: '15%',
    required: true,
    render: (value, row, index) => {
      return (<Input
        value={value}
        size="small"

        style={{ textAlign: 'left' }}
        onChange={(e) => {
          handleAddrChange('contPerson', index, e.target.value);
        }}
      />);

    },
  }, {
    title: '联系电话',
    dataIndex: 'tel',
    width: '15%',
    required: true,
    render: (value, row, index) => {
      return (<Input
        value={value}
        size="small"

        style={{ textAlign: 'left' }}
        onChange={(e) => {
          handleAddrChange('tel', index, e.target.value);
        }}
      />);
    },
  }, {
    title: '电子邮箱',
    dataIndex: 'email',
    width: '15%',
    render: (value, row, index) => {
      return (<Input
        value={value}

        size="small"
        style={{ textAlign: 'left' }}
        onChange={(e) => {
          handleAddrChange('email', index, e.target.value);
        }}
      />);
    },
  }, {
    title: '详细地址',
    dataIndex: 'detailaddr',
    width: '40%',
    render: (value, row, index) => {
      return (<Input
        value={value}

        size="small"
        style={{ textAlign: 'left' }}
        onChange={(e) => {
          handleAddrChange('detailaddr', index, e.target.value);
        }}
      />);
    },
  },]

  const produceInfo = [{
    title: '厂房总面积',
    dataIndex: 'cfzmj',
    options: {
      rules: [
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly} addonAfter="㎡" />,
  }, {
    title: '生产面积',
    dataIndex: 'scmj',
    tag: <Input disabled={readOnly} addonAfter="㎡" />,
    options: {
      rules: [
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
  }, {
    title: '生产线',
    dataIndex: 'scx',
    options: {
      rules: [
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly} />,
  }, {
    title: '原料仓储面积',
    dataIndex: 'ylccmj',
    options: {
      rules: [
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly} addonAfter="㎡" />,
  }, {
    title: '冷冻冷藏库面积',
    dataIndex: 'ldlckmj',
    tag: <Input disabled={readOnly} addonAfter="㎡" />,
    options: {
      rules: [
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
  }, {
    title: '成品库面积',
    dataIndex: 'cpkmj',
    options: {
      rules: [
        {
          max: 40,
          message: '请输入不超过40个字符',
        },
      ],
    },
    tag: <Input disabled={readOnly} addonAfter="㎡" />,
  }, {
    title: '工厂员工人数',
    dataIndex: 'gcygrs',
    tag: <InputNumber disabled={readOnly} style={{ width: '100%' }} min={0} />,
  }, {
    title: '开发技术人数',
    dataIndex: 'kfjsrs',
    options: {
    },
    tag: <InputNumber disabled={readOnly} style={{ width: '100%' }} min={0} />,
  }, {
    title: '品质检验人数',
    dataIndex: 'pzjyrs',
    options: {
    },
    tag: <InputNumber disabled={readOnly} style={{ width: '100%' }} min={0} />,
  }, {
    title: '主要生产设备',
    dataIndex: 'zyscsb',
    options: {

    },
    tag: <TextArea disabled={readOnly} autosize={{ minRows: 2, maxRows: 6 }} />,
  }, {
    title: '供应商来源',
    dataIndex: 'gysly',
    options: {

    },
    tag: <TextArea disabled={readOnly} autosize={{ minRows: 2, maxRows: 6 }} />,
  }];

  const produceSelectInfo = [{
    title: '质量检验',
    dataIndex: 'zljy',
    tag: <UdcSelect domain="SUPP" code="ZLJY" mode="multiple" />,
  }, {
    title: '检验范围',
    dataIndex: 'jyfw',
    options: {
      initialValue: [],
    },
    tag: <UdcSelect domain="SUPP" code="JYFW" mode="multiple" />,
  }, {
    title: '质量控制点报表',
    dataIndex: 'zlkzdbb',
    options: {
      initialValue: [],
    },
    tag: <UdcSelect domain="SUPP" code="ZLKZDBB" mode="multiple" />,
  }, {
    title: '供货质量记录',
    dataIndex: 'ghzljl',
    options: {
      initialValue: [],
    },
    tag: <UdcSelect domain="SUPP" code="GHZLJL" mode="multiple" />,
  }, {
    title: '产品执行标准',
    dataIndex: 'cpzxbz',
    options: {
      initialValue: [],
    },
    tag: <UdcSelect domain="SUPP" code="CPZXBZ" mode="multiple" />,
  }, {
    title: '认证体系',
    dataIndex: 'rztx',
    options: {
      initialValue: [],
    },
    tag: <UdcSelect domain="SUPP" code="RZTX" mode="multiple" />,
  }];

  const qualifyTableProps = [{
    title: '证件编号',
    required: true,
    dataIndex: 'qualifyNo',
    width: '15%',
    render: (value, row, index) => {
      return (<Input
        value={value}
        size="small"
        disabled={readOnly}
        onChange={(e) => {
          handleChange('qualifyNo', index, e.target.value);
        }}
      />);
    },
  }, {
    title: '证件名称',
    required: true,
    dataIndex: 'qualifyName',
    width: '20%',
    render: (value, row, index) => {
      return (<Input
        value={value}
        size="small"
        disabled={readOnly}
        style={{ textAlign: 'left' }}
        onChange={(e) => {
          handleChange('qualifyName', index, e.target.value);
        }}
      />);
    },
  }, {
    title: '证件类型',
    required: true,
    dataIndex: 'qualifyType',
    width: '14%',
    render: (value, row, index) => {
      return (<UdcSelect domain="SUPP"
        code="GYSZZ_TYPE"
        size="small"
        value={value}
        disabled={readOnly}
        onChange={(e) => {
          handleChange('qualifyType', index, e);
        }}
      />);
    },
  }, {
    title: '生效日期',
    dataIndex: 'validFrom',
    width: '13%',
    required: true,
    render: (value, row, index) => {
      return (<DatePicker style={{ width: '100%' }} size="small" disabled={readOnly} value={value ? moment(value) : value}
        onChange={(e, data) => {
          handleChange('validFrom', index, data);
        }}
      />);
    },
  }, {
    title: '失效日期',
    dataIndex: 'validTo',
    width: '13%',
    required: true,
    render: (value, row, index) => {
      return (<DatePicker style={{ width: '100%' }} size="small" disabled={readOnly} value={value ? moment(value) : value}
        onChange={(e, data) => {
          handleChange('validTo', index, data);
        }}
      />);
    },
  }, {
    title: '附件',
    dataIndex: 'attachRepo',
    width: '25%',
    required: true,
    render: (value, row, index) =>{
      let clsPath = row.attachRepo ? row.attachRepo : Math.abs(row.id);
      let dataKey = row.id > 0 ? row.id : '';
      return(<UploadEL size={'small'} api={`/api/supp/sfs/token?clsPath=${clsPath}&dataKey=${dataKey}`} dataKey={`${dataKey}`} listTypes={['text', 'picture', 'picture-card']}
        disabled={false} />
      );
    }
  },]


  const suppItem = [
    {
      title: '物料信息',
      dataIndex: 'gysylsx',
      options: {
        initialValue: [],
      },
      tag: <CheckboxGroup options={suppItem} className={styles.checkbox} />,
    },
  ]

  return {
    suppInfo,
    contactInfo,
    produceInfo,
    produceSelectInfo,
    introductionInfo,
    addrTableProps,
    qualifyTableProps,
  };
};

export default localCfg;
