import { dataUtils, enums, stringUtils } from '@utils';
import { Card, DatePicker, Table,Input } from 'antd';
import React from 'react';
import { connect } from 'dva';
import { DataTable, EditableDataTable, FormEL, MonthPicker, SuggestSelect, UdcSelect, UploadEL } from '@components';
import { Toolbar } from '@bizComponents';
import styles from './expandedRow.less';
import { numberUtils } from '@utils';
const TextArea = Input.TextArea;
const { bidStatus } = enums;

const TenderResult = ({ dispatch, tenderResult, loading }) => {
  const { formData, list, total, modalVisible, currentItem, sData, sList } = tenderResult;

  const domain = 'tenderResult';
  const domainCN = '评标结果';

  let readOnly = false;

  const tableProps = {
    rowKey: 'id',
    scroll: {
      x: 2800,
      y: 500,
    },
    domain,
    dispatch,
    loading,
    total,
    showAdd: false,
    dataSource: list,
    enableSelection: false,
    readOnly: false,
    filter: [],
    columns: [{
      title: '物料',
      dataIndex: 'item',
      key: 'item',
      width: 200,
    }, {
      title: '供应商',
      dataIndex: 'supp',
      width: 200,
    }, {
      title: '排名(评分)',
      dataIndex: 'rank',
      className: 'noWrap',
      width: 100,
    }, {
      title: '规格',
      dataIndex: 'itemSpec',
      key: 'itemSpec',
      width: 200,
    }, {
      title: '单位',
      dataIndex: 'itemUomName',
      key: 'itemUomName',
      className: 'noWrap',
      width: 100,
    }, {
      title: '招标数量',
      dataIndex: 'tenderQty',
      key: 'tenderQty',
      className: 'noWrap',
      width: 100,
    }, {
    //   title: '当前价格',
    //   dataIndex: 'price',
    //   key: 'price',
    //   className: 'alignRight',
    //   width: 100
    // }, {
      title: '最大供货量',
      dataIndex: 'maxProvideNum',
      key: 'maxProvideNum',
      className: 'noWrap',
      width: 100,
    }, {
      title: '未税单价',
      dataIndex: 'netPrice',
      key: 'netPrice',
      className: 'noWrap',
      width: 100,
      render: (value, row, index) => {
        return (
          numberUtils.round_half_up_format(value,4)
        )
      }
    }, {
      title: '含税单价',
      dataIndex: 'taxPrice',
      key: 'taxPrice',
      className: 'noWrap',
      width: 100,
      render: (value, row, index) => {
        return (
          numberUtils.round_half_up_format(value,4)
        )
      }
    }, {
      title: '税率(%)',
      dataIndex: 'taxRate',
      key: 'taxRate',
      className: 'noWrap',
      width: 100,
    }, {
      title: '税额',
      dataIndex: 'taxAmt',
      key: 'taxAmt',
      className: 'noWrap',
      width: 100,
      render: (value, row, index) => {
        return (
          numberUtils.round_half_up_format(value,2)
        )
      }
    }, {
      title: '未税总价',
      dataIndex: 'netAmt',
      key: 'netAmt',
      className: 'noWrap',
      width: 120,
      render: (value, row, index) => {
        return (
          numberUtils.round_half_up_format(value,4)
        )
      }
    }, {
      title: '含税总价',
      dataIndex: 'amt',
      key: 'amt',
      className: 'noWrap',
      width: 120,
      render: (value, row, index) => {
        return (
          numberUtils.round_half_up_format(value,4)
        )
      }
    }, {
      title: '中标比例(%)',
      dataIndex: 'bidPercent',
      key: 'bidPercent',
      className: 'noWrap',
      width: 100,
    }, {
      title: '中标数量',
      dataIndex: 'bidQty',
      key: 'bidQty',
      className: 'noWrap',
      width: 100,
    }, {
      title: '中标单价',
      dataIndex: 'bidPrice',
      key: 'bidPrice',
      className: 'noWrap',
      width: 120,
      render: (value, row, index) => {
        return (
          numberUtils.round_half_up_format(value,2)
        )
      }
    }, {
      title: '中标总金额',
      dataIndex: 'bidAmt',
      key: 'bidAmt',
      className: 'noWrap',
      width: 100,
      render: (value, row, index) => {
        return (
          numberUtils.round_half_up_format(value,2)
        )
      }
    }]
  };

  const basic = [{
    title: '招标单编号',
    dataIndex: 'docNo',
  }, {
    title: '招标单名称',
    dataIndex: 'biName',
  }, {
    title: (bidStatus.DROP===formData.docStatus)?'弃标原因':'',
    dataIndex: 'advice',
    tag:  (bidStatus.DROP===formData.docStatus)?<TextArea autosize={{ minRows: 3, maxRows: 3 }} />:<span></span>,
  }]
  const handleFormChange = (field) => {
    // console.log('field=>',field)
  };

  const handleCancel = () => {
    // message.info('你选择了返回')
    dispatch({ type: `${domain}/cancel` });
  };


  return (
    <div>
      <Toolbar
        prcId={formData.prcId}
        defId={formData.defId}
        loading={loading}
        record={formData}
        mode='view'
        buttons={}
        handleCancel={handleCancel}
      />

      <Card
        id="basic"
        title='基本信息'
        loading={loading.effects[`${domain}/query`]}
      >
        <FormEL
          items={basic}
          record={formData}
          readOnly={readOnly}
          onFieldsChange={handleFormChange}
        />
      </Card>

      <Card id="result" title='评标结果'>
        <EditableDataTable {...tableProps} />
      </Card>
    </div>
  );

};

export default connect(({ tenderResult, loading }) => ({ tenderResult, loading }))(TenderResult);
