import React from 'react';
import { connect } from 'dva';
import { DatePicker, Input } from 'antd';
import { dataUtils, numberUtils } from '../../../utils';
import { DataTable } from '../../components';
import { CascaderItem } from "../components";
import { stringUtils } from "../../utils";

const PlanMgmt = ({ dispatch, plan, ouBanks, loading }) => {
  const { list, total, currentItem, modalVisible, mode } = plan;
  const { RangePicker } = DatePicker;

  const domain = 'plan';
  const domainCN = '需求计划';

  const cccCode = stringUtils.queryURL('cccCode') ? stringUtils.queryURL('cccCode').split('%2C') : [];

  const tableProps = {
    rowKey: 'id',
    // sortBy: 'start',
    limit: stringUtils.queryURL('limit'),
    offset: stringUtils.queryURL('offset'),
    scroll: {
      x: 5000,
      y: 500
    },
    domain,
    dispatch,
    loading,
    total,
    showAdd: false,
    enableSelection: false,
    dataSource: list,
    filter: [{
      title: '公司',
      dataIndex: 'ouCodeName',
      options: {
        initialValue: '',
      },
      tag: <Input placeholder="请输入名称/编号" />,
    }, {
      title: '物料',
      dataIndex: 'itemCodeName',
      options: {
        initialValue: '',
      },
      tag: <Input placeholder="请输入名称/编号" />,
    }, {
      title: '仓库',
      dataIndex: 'mcuCodeName',
      options: {
        initialValue: '',
      },
      tag: <Input placeholder="请输入名称/编号" />,
    }, {
      title: '物料类别',
      dataIndex: 'cccCode',
      tag: <CascaderItem placeholder="选择大类/中类/小类" changeOnSelect={true} />,
      options: {
        initialValue: cccCode,
      },
    }],
    columns: [{
      title: '公司名称',
      dataIndex: 'ouName',
      width: 200,
    }, {
      title: '世纪',
      dataIndex: 'century',
      width: 50,
    }, {
      title: '年份',
      dataIndex: 'year',
      width: 50,
    }, {
      title: '月份',
      dataIndex: 'month',
      width: 50,
    }, {
      title: '仓库',
      dataIndex: 'mcuName',
      width: 100,
    }, {
      title: '物料短项目号',
      dataIndex: 'itemShortCode',
      width: 100,
    }, {
      title: '请购日期',
      dataIndex: 'requireDate',
      width: 150,
    }, {
      title: '类别',
      dataIndex: 'category',
      width: 150,
    }, {
      title: '第三项目号',
      dataIndex: 'itemThirdCode',
      width: 100,
    }, {
      title: '搜索文本',
      dataIndex: 'searchText',
      width: 200,
    }, {
      title: '存储类型',
      dataIndex: 'storageType',
      width: 100,
    }, {
      title: '物料编码',
      dataIndex: 'itemCode',
      width: 150,
    }, {
      title: '物料名称',
      dataIndex: 'itemDesc',
      width: 200,
    }, {
      title: '物料规格',
      dataIndex: 'itemSpec',
      width: 150,
    }, {
      title: '主计量单位',
      dataIndex: 'uomName',
      width: 100,
    }, {
      title: '单价',
      dataIndex: 'price',
      className: 'alignRight',
      width: 100,
    }, {
      title: '上月出库数量',
      dataIndex: 'exNumLastMonth',
      className: 'alignRight',
      width: 100,
    }, {
      title: '上月日均用量',
      dataIndex: 'avgNumLastMonth',
      className: 'alignRight',
      width: 100,
    }, {
      title: '上月万元用量(门店)',
      dataIndex: 'orgWanLastMonth',
      className: 'alignRight',
      width: 100,
    }, {
      title: '上月万元用量(出库)',
      dataIndex: 'exWanLastMonth',
      className: 'alignRight',
      width: 100,
    }, {
      title: '半月出库量(本月)',
      dataIndex: 'exNumHalfMonth',
      className: 'alignRight',
      width: 100,
    }, {
      title: '半月日均发货量(本月)',
      dataIndex: 'avgExNumHalfMonth',
      className: 'alignRight',
      width: 100,
    }, {
      title: '半月万元用量(本月)',
      dataIndex: 'wanHalfMonth',
      className: 'alignRight',
      width: 100,
    }, {
      title: '下月预估用量',
      dataIndex: 'estNumNextMonth',
      className: 'alignRight',
      width: 100,
    }, {
      title: '下月预估日均用量',
      dataIndex: 'estAvgNumNextMonth',
      className: 'alignRight',
      width: 100,
    }, {
      title: '下月月度天数',
      dataIndex: 'nextMonthDays',
      width: 100,
    }, {
      title: '当前库存量',
      dataIndex: 'inventory',
      className: 'alignRight',
      width: 100,
    }, {
      title: '在途数量',
      dataIndex: 'numOnRoad',
      className: 'alignRight',
      width: 100,
    }, {
      title: '在途与结存可供发货天数',
      dataIndex: 'supportDays',
      className: 'alignRight',
      width: 100,
    }, {
      title: '预估日至本月天数',
      dataIndex: 'intervalDays',
      width: 100,
    }, {
      title: '安全库存天数',
      dataIndex: 'secureDays',
      width: 100,
    }, {
      title: '预估量',
      dataIndex: 'estimateNum',
      className: 'alignRight',
      width: 100,
    }, {
      title: '发货浮动百分比(%)',
      dataIndex: 'floatPercent',
      className: 'alignRight',
      width: 100,
    }, {
      title: '预估量确认',
      dataIndex: 'estimateConfirm',
      className: 'alignRight',
      width: 100,
    }, {
      title: '预估金额',
      dataIndex: 'estimateAmt',
      className: 'alignRight',
      width: 100,
    }, {
      title: '实购数量',
      dataIndex: 'actualPurchaseNum',
      className: 'alignRight',
      width: 100,
    }, {
      title: '上月销售金额(整月)',
      dataIndex: 'salesAmtLastMonth',
      className: 'alignRight',
      width: 100,
    }, {
      title: '本月销售金额(半月)',
      dataIndex: 'salesAmtHalfMonth',
      className: 'alignRight',
      width: 100,
    }, {
      title: '下月份预估销售金额',
      dataIndex: 'estSalesAmtNextMonth',
      className: 'alignRight',
      width: 100,
    }, {
      title: '用户号',
      dataIndex: 'userCode',
      width: 100,
    }, {
      title: '程序号',
      dataIndex: 'processNum',
      width: 100,
    }, {
      title: '工作站号',
      dataIndex: 'workNum',
      width: 100,
    }, {
      title: '更新日期',
      dataIndex: 'updateDate',
      width: 150,
    }],
  };

  return (
    <div className="content-inner">
      <DataTable {...tableProps} />
    </div>
  );
};

export default connect(({ plan, ouBanks, loading }) => ({ plan, ouBanks, loading }))(PlanMgmt);
