import React from 'react';

import { ItemPicker, OuPicker, SupplierPicker } from '@bizComponents';
import {
  DataTable,
  EditableDataTable,
  FormEL,
  Loader,
  MonthPicker,
  SuggestSelect,
  UdcSelect,
  UploadEL
} from '@components';
import { dataUtils, enums, formUtils } from '@utils';
import { numberUtils } from '@utils';
import { DatePicker, Input, InputNumber, Select } from 'antd';

const { bidStatus } = enums;
const config = (formData, mode, dispatch, loading, extraInfo) => {
  const domain = 'tenderReview';

  /**
   * @param key      字段名
   * @param index    行号
   * @param newValue 新值
   */
  const handleChange = (key, index, newValue) => {
    dispatch({ type: `${domain}/updateCell`, payload: { key, index, value: newValue } });
  };
  const viewScoreDetail = (viewId, itemId) => {
    dispatch({
      type: `${domain}/suppScore`,
      payload: {
        viewId,
        itemId
      }
    });
  }
  // 基本信息form
  const reviewBasicForm = [
    {
      title: '招标单编号',
      dataIndex: 'docNo',
    },
    {
      title: '招标单名称',
      dataIndex: 'biName',
    },
  ];
  // 评分结果
  const reviewResultList = [
    {
      title: '物料编号',
      dataIndex: 'itemCode',
      className: 'noWrap',
      fixed: 'left',
      width: 120
    }, {
      title: '物料名称',
      dataIndex: 'itemDesc',
      className: 'alignLeft',
      fixed: 'left',
      width: 200
    }, {
      title: '规格',
      dataIndex: 'itemSpec',
      className: 'alignLeft',
      fixed: 'left',
      width: 100
    }, {
      title: '单位',
      dataIndex: 'itemUomName',
      className: 'noWrap',
      fixed: 'left',
      width: 100
    }, {
      title: '评分详情',
      dataIndex: 'scoreDetail',
      width: 70,
      className: 'noWrap',
      render: (value, row, index) => {
        return (
          <a onClick={() => viewScoreDetail(row.bidInfoId, row.itemId)}>查看</a>
        )
      },
    }, {
      title: '投标文件',
      dataIndex: 'bidFile',
      width: 300,
      className: 'alignLeft',
      render: (value, row, index) => {
        return (
          <UploadEL size={'small'}
                    api={`/api/source-mgmt/bid-mgmt/bids/bids/sfs/token?clsPath=${row.attachRepo}&dataKey=${row.bidInfoId}`}
                    dataKey={row.bidInfoId}
                    listTypes={'text'}
                    disabled={true}/>
        )
      },
    }, {
      title: '供应商编号',
      dataIndex: 'suppCode',
      width: 90,
      className: 'noWrap',
    }, {
      title: '供应商名称',
      dataIndex: 'suppName',
      width: 100,
      className: 'alignLeft',
    }, {
      title: '排名',
      dataIndex: 'ranking',
      width: 50,
      className: 'noWrap',
    }, {
      title: '评分',
      dataIndex: 'score',
      width: 50,
      className: 'noWrap',
    }, {
      title: '招标数量',
      dataIndex: 'tenderQty',
      className: 'alignRight',
      width: 100
    }, {
      title: '当前价格',
      dataIndex: 'price',
      className: 'alignRight',
      width: 100
    }, {
      title: '最大供货量',
      dataIndex: 'maxProvideNum',
      className: 'alignRight',
      width: 100
    }, {
      title: '未税单价',
      dataIndex: 'netPrice',
      className: 'alignRight',
      width: 100,
      render: (value, row, index) => {
        return (
          numberUtils.round_half_up_format(value, 2)
        )
      }
    }, {
      title: '含税单价',
      dataIndex: 'taxPrice',
      className: 'alignRight',
      width: 100,
      render: (value, row, index) => {
        return (
          numberUtils.round_half_up_format(value, 2)
        )
      }
    }, {
      title: '税率（%）',
      dataIndex: 'taxRate',
      className: 'alignRight',
      width: 100
    }, {
      title: '税额',
      dataIndex: 'taxAmt',
      className: 'alignRight',
      width: 100,
      render: (value, row, index) => {
        return (
          numberUtils.round_half_up_format(value, 2)
        )
      }
    }, {
      title: '未税总价',
      dataIndex: 'netAmt',
      className: 'alignRight',
      width: 100,
      render: (value, row, index) => {
        return (
          numberUtils.round_half_up_format(value, 2)
        )
      }
    }, {
      title: '含税总价',
      dataIndex: 'amt',
      className: 'alignRight',
      width: 100,
      render: (value, row, index) => {
        return (
          numberUtils.round_half_up_format(value, 2)
        )
      }
    }, {
      title: '中标比例(%)',
      dataIndex: 'bidPercent',
      width: 150,
      fixed: 'right',
      render: (value, row, index) => {
        return (
          <InputNumber
            min={0}
            max={100}
            precision={1}
            size="small"
            step={1}
            disabled={bidStatus.PENDING_ADJUST !== extraInfo.docStatus}
            value={row.bidPercent}
            onChange={(e) => {
              handleChange('bidPercent', index, e);
            }}
          />
        );
      },
    }, {
      title: '中标数量',
      dataIndex: 'bidQty',
      className: 'alignRight',
      width: 80,
      fixed: 'right',
    }, {
      title: '中标单价',
      dataIndex: 'bidPrice',
      className: 'alignRight',
      width: 80,
      fixed: 'right',
      render: (value, row, index) => {
        return (
          numberUtils.round_half_up_format(row.taxPrice, 2)
        )
      }
    }, {
      title: '中标总金额',
      dataIndex: 'bidAmt',
      className: 'alignRight',
      width: 90,
      fixed: 'right',
      render: (value, row, index) => {
        return (
          numberUtils.round_half_up_format(value, 2)
        )
      }
    }
  ];

  return {
    reviewBasicForm,
    reviewResultList
  };
};

export default config;
