AreaTable.tsx 2.99 KB
import {Table} from 'antd';
import React, {useState} from 'react';
import { useStore } from '@/pages/pms/partPlan/AmountPlan';
import {PartVO} from "@/pages/pms/partPlan/MinRatioPlan/api";
import useInitial from "@/hooks/useInitail";
import {getList, ListVO} from "@/pages/pms/partPlan/AmountPlan/api";
import DetailModal from './DetailModal';

const { Column } = Table;
interface Props {
  showAnalyse?: boolean
  // eslint-disable-next-line react/no-unused-prop-types
  type?: number, // 类型1区域库2库房3车系4车型5配件
  // eslint-disable-next-line react/no-unused-prop-types
  detailType?: number, // 类型1区域库2库房3车系4车型5配件
  // eslint-disable-next-line react/no-unused-prop-types
  id?: number, // 上一个列表ID
}
export default function Index(props: Props = {}) {
  const {showAnalyse=true} = props;
  const { dfParams } = useStore();
  const { data: parts } = useInitial(getList, [], {...dfParams, ...props});
  const [visible, setVisible] = useState(false);
  // 类型1区域库2库房3车系4车型5配件
  const [detailType, setDetailType] = useState<number>();
  const [id, setId] = useState<number>();

  return (
    <div>
      <Table rowKey={(v: PartVO) => `${v.partId}`} scroll={{y: 500, x: 1000}} dataSource={parts || []} pagination={false}>
        <Column title="区域库" dataIndex="name" fixed="left" />
        <Column title="本次计划金额(元)" dataIndex="thisTimeAmount" />
        <Column title="动态库销比" dataIndex="ratio" render={t => (t || 0).toFixed(2)} />
        <Column title="库存金额" dataIndex="stockAmount" render={t => (t || 0).toFixed(2)} />
        <Column title="滚动90天月均出库金额" dataIndex="outAmount" render={t => (t || 0).toFixed(2)} />
        {showAnalyse && (
          <>
            <Column
              title="库房分析"
              render={(t, _: ListVO) => (
                <a onClick={() => {
                  setVisible(true);
                  setId(_.id);
                  setDetailType(2);
                }}
                >
                  查看
                </a>
              )}
            />
            <Column
              title="车系分析"
              render={(t, _: ListVO) => (
                <a onClick={() => {
                  setVisible(true);
                  setId(_.id);
                  setDetailType(3);
                }}
                >
                  查看
                </a>
              )}
            />
            <Column
              title="配件分析"
              render={(t, _: ListVO) => (
                <a onClick={() => {
                  setVisible(true);
                  setId(_.id);
                  setDetailType(5);
                }}
                >
                  查看
                </a>
              )}
            />
          </>
        )}
      </Table>
      <DetailModal
        visible={visible}
        onCancel={() => setVisible(false)}
        id={id}
        detailType={detailType}
        type={1}
      />
    </div>
  );
}