import React from 'react';
import { connect } from 'dva';
import { DatePicker, Card } from 'antd';
import { DataTable } from '../../../components';
import { CascaderItem } from '../../components';
import { numberUtils } from '@utils';
import moment from 'moment';

const RecpStatistics = ({ dispatch, recpStatistics, loading }) => {
  const { list, total, filterParams } = recpStatistics;
  const { MonthPicker } = DatePicker;

  const domain = 'recpStatistics';
  const domainCN = '华南入库统计';

  const tableProps = {
    rowKey: 'rowKey',
    sortBy: 'itemCode',
    scroll: { x: '200%' },
    domain,
    dispatch,
    loading,
    total,
    showAdd: false,
    enableSelection: false,
    dataSource: list,
    handleDownload: {
      requestUrl: `/srm/api/export/recpstatistics`,
      requestParam:  window.location.search,
    },
    filter: [{
      title: '选择月份',
      dataIndex: 'priceMonth',
      tag: (<MonthPicker placeholder="请选择月份" style={{ width: '100%' }} allowClear={false} />),
      options: {
        rules: [{
          required: true,
          message: '必填',
        }],
        initialValue: filterParams.priceMonth ? moment(filterParams.priceMonth, 'YYYYMM') : moment(),
      },
    }, {
      title: '公司',
      dataIndex: 'ouCodeName',
      options: {
        initialValue: filterParams.ouCodeName,
      },
    }, {
      title: '供应商',
      dataIndex: 'suppCodeName',
      options: {
        initialValue: filterParams.suppCodeName,
      },
    }, {
      title: '物料',
      dataIndex: 'itemCodeName',
      options: {
        initialValue: filterParams.itemCodeName,
      },
    }, {
      title: '物料类别',
      dataIndex: 'cccCode',
      tag: <CascaderItem placeholder="选择大类/中类/小类" changeOnSelect={true} />,
      options: {
        initialValue: filterParams.cccCode,
      },
    }],
    columns: [{
      title: '公司名称',
      dataIndex: 'ouName',
      width: '6%',
    }, {
      title: '供应商编码',
      dataIndex: 'suppCode',
      width: '4%',
    }, {
      title: '供应商名称',
      dataIndex: 'suppName',
      width: '6%',
    }, {
      title: '物料编码',
      dataIndex: 'itemCode',
      width: '4%',
    }, {
      title: '物料名称',
      dataIndex: 'itemName',
      width: '8%',
    }, {
      title: '大类描述',
      dataIndex: 'c1Name',
      width: '4%',
    }, {
      title: '中类描述',
      dataIndex: 'c2Name',
      width: '4%',
    }, {
      title: '小类描述',
      dataIndex: 'c3Name',
      width: '4%',
    }, {
      title: '规格型号',
      dataIndex: 'spec',
      width: '4%',
    }, {
      title: '主单位',
      dataIndex: 'uom',
      width: '3%',
    }, {
      title: '税率',
      dataIndex: 'taxRate',
      width: '3%',
    }, {
      title: '总数量',
      dataIndex: 'qty',
      width: '4%',
    }, {
      title: '未税单价',
      dataIndex: 'netPrice',
      width: '4%',
      render: (value) => numberUtils.round_half_up_format(value, 4),
    }, {
      title: '含税单价',
      dataIndex: 'taxPrice',
      width: '4%',
      render: (value) => numberUtils.round_half_up_format(value, 4),
    }, {
      title: '未税总金额',
      dataIndex: 'netAmt',
      width: '4%',
      render: (value) => numberUtils.round_half_up_format(value, 2),
    }, {
      title: '含税总金额',
      dataIndex: 'amt',
      width: '4%',
      render: (value) => numberUtils.round_half_up_format(value, 2),
    }, {
      title: '含税均价',
      dataIndex: 'avgAmt',
      width: '4%',
      render: (value) => numberUtils.round_half_up_format(value, 2),
    }, {
      title: '含税单价环比',
      dataIndex: 'chainAvgAmtRate',
      width: '4%',
    }, {
      title: '含税单价同比',
      dataIndex: 'yearAvgAmtRate',
      width: '4%',
    }, {
      title: '总数量环比',
      dataIndex: 'chainQtyRate',
      width: '4%',
    }, {
      title: '总数量同比',
      dataIndex: 'yearQtyRate',
      width: '4%',
    }, {
      title: '含税总金额环比',
      dataIndex: 'chainAmtRate',
      width: '4%',
    }, {
      title: '含税总金额同比',
      dataIndex: 'yearAmtRate',
      width: '4%',
    }
    ],
  };

  return (
    <Card>
      <DataTable {...tableProps} />
    </Card>
  );
};

export default connect(({ recpStatistics, loading }) => ({ recpStatistics, loading }))(RecpStatistics);
